Skip to content

Commit 3e9c26d

Browse files
committed
add tests to decode for response objects of Admin API
1 parent 507b7f2 commit 3e9c26d

File tree

5 files changed

+223
-0
lines changed

5 files changed

+223
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// APIKeyResponseTests.swift
3+
// AnthropicSwiftSDK
4+
//
5+
// Created by 伊藤史 on 2024/12/06.
6+
//
7+
8+
import XCTest
9+
import AnthropicSwiftSDK
10+
11+
final class APIKeyResponseTests: XCTestCase {
12+
func testDecodeAPIKeyResponse() throws {
13+
let json = """
14+
{
15+
"id": "apikey_01Rj2N8SVvo6BePZj99NhmiT",
16+
"type": "api_key",
17+
"name": "Developer Key",
18+
"workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ",
19+
"created_at": "2024-10-30T23:58:27.427722Z",
20+
"created_by": {
21+
"id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
22+
"type": "user"
23+
},
24+
"partial_key_hint": "sk-ant-api03-R2D...igAA",
25+
"status": "active"
26+
}
27+
"""
28+
29+
let jsonData = json.data(using: .utf8)!
30+
let response = try anthropicJSONDecoder.decode(APIKeyResponse.self, from: jsonData)
31+
32+
XCTAssertEqual(response.id, "apikey_01Rj2N8SVvo6BePZj99NhmiT")
33+
XCTAssertEqual(response.type, .apiKey)
34+
XCTAssertEqual(response.name, "Developer Key")
35+
XCTAssertEqual(response.workspaceId, "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ")
36+
XCTAssertEqual(response.createdAt, "2024-10-30T23:58:27.427722Z")
37+
XCTAssertEqual(response.createdBy.id, "user_01WCz1FkmYMm4gnmykNKUu3Q")
38+
XCTAssertEqual(response.createdBy.type, "user")
39+
XCTAssertEqual(response.partialKeyHint, "sk-ant-api03-R2D...igAA")
40+
XCTAssertEqual(response.status, .active)
41+
}
42+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// OrganizationInviteResponseTests.swift
3+
// AnthropicSwiftSDK
4+
//
5+
// Created by 伊藤史 on 2024/12/06.
6+
//
7+
8+
import XCTest
9+
import AnthropicSwiftSDK
10+
11+
final class OrganizationInviteResponseTests: XCTestCase {
12+
func testDecodeOrganizationInviteResponse() throws {
13+
let json = """
14+
{
15+
"id": "invite_015gWxCN9Hfg2QhZwTK7Mdeu",
16+
"type": "invite",
17+
"email": "user@emaildomain.com",
18+
"role": "user",
19+
"invited_at": "2024-10-30T23:58:27.427722Z",
20+
"expires_at": "2024-11-20T23:58:27.427722Z",
21+
"status": "pending"
22+
}
23+
"""
24+
25+
let jsonData = json.data(using: .utf8)!
26+
let response = try anthropicJSONDecoder.decode(InvitationResponse.self, from: jsonData)
27+
28+
XCTAssertEqual(response.id, "invite_015gWxCN9Hfg2QhZwTK7Mdeu")
29+
XCTAssertEqual(response.type, .invite)
30+
XCTAssertEqual(response.email, "user@emaildomain.com")
31+
XCTAssertEqual(response.role, .user)
32+
XCTAssertEqual(response.invitedAt, "2024-10-30T23:58:27.427722Z")
33+
XCTAssertEqual(response.expiresAt, "2024-11-20T23:58:27.427722Z")
34+
XCTAssertEqual(response.status, .pending)
35+
}
36+
37+
func testDecodeOrganizationInviteRemoveResponse() throws {
38+
let json = """
39+
{
40+
"id": "invite_015gWxCN9Hfg2QhZwTK7Mdeu",
41+
"type": "invite_deleted"
42+
}
43+
"""
44+
45+
let jsonData = json.data(using: .utf8)!
46+
let response = try anthropicJSONDecoder.decode(InvitationRemoveResponse.self, from: jsonData)
47+
48+
XCTAssertEqual(response.id, "invite_015gWxCN9Hfg2QhZwTK7Mdeu")
49+
XCTAssertEqual(response.type, .deleted)
50+
}
51+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// OrganizationMemberResponseTests.swift
3+
// AnthropicSwiftSDK
4+
//
5+
// Created by 伊藤史 on 2024/12/06.
6+
//
7+
8+
import XCTest
9+
import AnthropicSwiftSDK
10+
11+
final class OrganizationMemberResponseTests: XCTestCase {
12+
func testDecodeOrganizationMemberResponse() throws {
13+
let json = """
14+
{
15+
"id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
16+
"type": "user",
17+
"email": "user@emaildomain.com",
18+
"name": "Jane Doe",
19+
"role": "user",
20+
"added_at": "2024-10-30T23:58:27.427722Z"
21+
}
22+
"""
23+
24+
let jsonData = json.data(using: .utf8)!
25+
let response = try anthropicJSONDecoder.decode(OrganizationMemberResponse.self, from: jsonData)
26+
27+
XCTAssertEqual(response.id, "user_01WCz1FkmYMm4gnmykNKUu3Q")
28+
XCTAssertEqual(response.type, .user)
29+
XCTAssertEqual(response.email, "user@emaildomain.com")
30+
XCTAssertEqual(response.name, "Jane Doe")
31+
XCTAssertEqual(response.role, .user)
32+
XCTAssertEqual(response.addedAt, "2024-10-30T23:58:27.427722Z")
33+
}
34+
35+
func testDecodeOrganizationMemberRemoveResponse() throws {
36+
let json = """
37+
{
38+
"id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
39+
"type": "user_deleted"
40+
}
41+
"""
42+
43+
let jsonData = json.data(using: .utf8)!
44+
let response = try anthropicJSONDecoder.decode(OrganizationMemberRemoveResponse.self, from: jsonData)
45+
46+
XCTAssertEqual(response.id, "user_01WCz1FkmYMm4gnmykNKUu3Q")
47+
XCTAssertEqual(response.type, .deleted)
48+
}
49+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// WorkspaceMemberResponseTests.swift
3+
// AnthropicSwiftSDK
4+
//
5+
// Created by 伊藤史 on 2024/12/06.
6+
//
7+
8+
import XCTest
9+
import AnthropicSwiftSDK
10+
11+
final class WorkspaceMemberResponseTests: XCTestCase {
12+
func testDecodeWorkspaceMemberResponse() throws {
13+
let json = """
14+
{
15+
"type": "workspace_member",
16+
"user_id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
17+
"workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ",
18+
"workspace_role": "workspace_user"
19+
}
20+
"""
21+
22+
let jsonData = json.data(using: .utf8)!
23+
let response = try anthropicJSONDecoder.decode(WorkspaceMemberResponse.self, from: jsonData)
24+
25+
XCTAssertEqual(response.type, .workspaceMember)
26+
XCTAssertEqual(response.userId, "user_01WCz1FkmYMm4gnmykNKUu3Q")
27+
XCTAssertEqual(response.workspaceId, "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ")
28+
XCTAssertEqual(response.workspaceRole, .user)
29+
}
30+
31+
func testDecodeWorkspaceMemberRemoveResponse() throws {
32+
let json = """
33+
{
34+
"user_id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
35+
"workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ",
36+
"type": "workspace_member_deleted"
37+
}
38+
"""
39+
40+
let jsonData = json.data(using: .utf8)!
41+
let response = try anthropicJSONDecoder.decode(WorkspaceMemberRemoveResponse.self, from: jsonData)
42+
43+
XCTAssertEqual(response.userId, "user_01WCz1FkmYMm4gnmykNKUu3Q")
44+
XCTAssertEqual(response.workspaceId, "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ")
45+
XCTAssertEqual(response.type, .deleted)
46+
}
47+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// WorkspaceResponseTests.swift
3+
// AnthropicSwiftSDK
4+
//
5+
// Created by 伊藤史 on 2024/12/06.
6+
//
7+
8+
import XCTest
9+
import AnthropicSwiftSDK
10+
11+
final class WorkspaceResponseTests: XCTestCase {
12+
func testDecodeWorkspaceResponse() throws {
13+
let json = """
14+
{
15+
"id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ",
16+
"type": "workspace",
17+
"name": "Workspace Name",
18+
"created_at": "2024-10-30T23:58:27.427722Z",
19+
"archived_at": "2024-11-01T23:59:27.427722Z",
20+
"display_color": "#6C5BB9"
21+
}
22+
"""
23+
24+
let jsonData = json.data(using: .utf8)!
25+
let response = try anthropicJSONDecoder.decode(WorkspaceResponse.self, from: jsonData)
26+
27+
XCTAssertEqual(response.id, "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ")
28+
XCTAssertEqual(response.type, .workspace)
29+
XCTAssertEqual(response.name, "Workspace Name")
30+
XCTAssertEqual(response.createdAt, "2024-10-30T23:58:27.427722Z")
31+
XCTAssertEqual(response.archivedAt, "2024-11-01T23:59:27.427722Z")
32+
XCTAssertEqual(response.displayColor, "#6C5BB9")
33+
}
34+
}

0 commit comments

Comments
 (0)