Skip to content

Commit 887dd19

Browse files
committed
test(appinfos): add test for category ID mapping in listAppInfos
- Verify mapping of primary and secondary category IDs from relationships - Ensure repository requests category fields explicitly in API call
1 parent a8efbf4 commit 887dd19

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

Sources/Infrastructure/Apps/AppInfos/SDKAppInfoRepository.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ public struct SDKAppInfoRepository: AppInfoRepository, @unchecked Sendable {
99
}
1010

1111
public func listAppInfos(appId: String) async throws -> [Domain.AppInfo] {
12-
let request = APIEndpoint.v1.apps.id(appId).appInfos.get()
12+
// Explicitly request category relationship fields — ASC omits them by default.
13+
let request = APIEndpoint.v1.apps.id(appId).appInfos.get(
14+
parameters: .init(
15+
fieldsAppInfos: [
16+
.primaryCategory, .primarySubcategoryOne, .primarySubcategoryTwo,
17+
.secondaryCategory, .secondarySubcategoryOne, .secondarySubcategoryTwo,
18+
]
19+
)
20+
)
1321
let response = try await client.request(request)
1422
return response.data.map { mapAppInfo($0, appId: appId) }
1523
}

Tests/InfrastructureTests/Apps/AppInfos/SDKAppInfoRepositoryTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,37 @@ struct SDKAppInfoRepositoryTests {
2525
#expect(result.allSatisfy { $0.appId == "app-99" })
2626
}
2727

28+
@Test func `listAppInfos maps primary and secondary category ids from relationships`() async throws {
29+
let stub = StubAPIClient()
30+
stub.willReturn(AppInfosResponse(
31+
data: [
32+
AppInfo(
33+
type: .appInfos,
34+
id: "info-1",
35+
relationships: .init(
36+
primaryCategory: .init(data: .init(type: .appCategories, id: "6014")),
37+
primarySubcategoryOne: .init(data: .init(type: .appCategories, id: "7001")),
38+
primarySubcategoryTwo: .init(data: .init(type: .appCategories, id: "7002")),
39+
secondaryCategory: .init(data: .init(type: .appCategories, id: "6015")),
40+
secondarySubcategoryOne: .init(data: .init(type: .appCategories, id: "7003")),
41+
secondarySubcategoryTwo: .init(data: .init(type: .appCategories, id: "7004"))
42+
)
43+
),
44+
],
45+
links: .init(this: "")
46+
))
47+
48+
let repo = SDKAppInfoRepository(client: stub)
49+
let result = try await repo.listAppInfos(appId: "app-1")
50+
51+
#expect(result[0].primaryCategoryId == "6014")
52+
#expect(result[0].primarySubcategoryOneId == "7001")
53+
#expect(result[0].primarySubcategoryTwoId == "7002")
54+
#expect(result[0].secondaryCategoryId == "6015")
55+
#expect(result[0].secondarySubcategoryOneId == "7003")
56+
#expect(result[0].secondarySubcategoryTwoId == "7004")
57+
}
58+
2859
@Test func `listAppInfos maps id from SDK response`() async throws {
2960
let stub = StubAPIClient()
3061
stub.willReturn(AppInfosResponse(

0 commit comments

Comments
 (0)