-
-
Notifications
You must be signed in to change notification settings - Fork 29
fix(pricing): return every territory from per-territory price lists #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -283,4 +283,46 @@ struct SDKInAppPurchasePriceRepositoryTests { | |
| #expect(byTerritory["JPN"]?.customerPrice == "1500") | ||
| #expect(byTerritory["JPN"]?.territory.currency == "JPY") | ||
| } | ||
|
|
||
| @Test func `price schedule includes every manually priced territory beyond the first page`() async throws { | ||
| func manualPricesPage(_ range: Range<Int>, nextCursor: String?) -> InAppPurchasePricesResponse { | ||
| InAppPurchasePricesResponse( | ||
| data: range.map { i in | ||
| AppStoreConnect_Swift_SDK.InAppPurchasePrice( | ||
| type: .inAppPurchasePrices, id: "price-\(i)", | ||
| relationships: .init( | ||
| inAppPurchasePricePoint: .init(data: .init(type: .inAppPurchasePricePoints, id: "pp-\(i)")), | ||
| territory: .init(data: .init(type: .territories, id: "T\(i)")) | ||
| ) | ||
| ) | ||
| }, | ||
| included: range.flatMap { i -> [InAppPurchasePricesResponse.IncludedItem] in [ | ||
| .territory(Territory(type: .territories, id: "T\(i)", attributes: .init(currency: "USD"))), | ||
| .inAppPurchasePricePoint(InAppPurchasePricePoint( | ||
| type: .inAppPurchasePricePoints, id: "pp-\(i)", | ||
| attributes: .init(customerPrice: "\(i).99", proceeds: "\(i).50") | ||
| )), | ||
| ] }, | ||
| links: .init(this: ""), | ||
| meta: .init(paging: .init(total: 175, limit: 200, nextCursor: nextCursor)) | ||
| ) | ||
| } | ||
| let stub = StubAPIClient() | ||
| stub.willReturn(InAppPurchasePriceScheduleResponse( | ||
| data: AppStoreConnect_Swift_SDK.InAppPurchasePriceSchedule(type: .inAppPurchasePriceSchedules, id: "iap-7"), | ||
| links: .init(this: "") | ||
| )) | ||
| stub.willReturnPages([ | ||
| manualPricesPage(0..<100, nextCursor: "page-2"), | ||
| manualPricesPage(100..<175, nextCursor: nil), | ||
| ]) | ||
|
Comment on lines
+315
to
+318
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,115p' Tests/InfrastructureTests/TestHelpers/StubAPIClient.swift
sed -n '280,340p' Tests/InfrastructureTests/Apps/InAppPurchases/SDKInAppPurchasePriceRepositoryTests.swift
rg -n 'requestAllPages|page-2|recordedRequests|requests|cursor|limit: 200' Tests/InfrastructureTests/Apps/InAppPurchases Tests/InfrastructureTests/Apps/Subscriptions | head -110Repository: tddworks/asc-cli Length of output: 9855 🏁 Script executed: rg -n 'requestAllPages|requests.*query|\\.requests|cursor=|limit.*200|page-2' Sources Tests/InfrastructureTests/Apps/InAppPurchases Tests/InfrastructureTests/Apps/Subscriptions Tests/InfrastructureTests/Apps --glob '*.swift' | head -180
git ls-files | rg 'Pagination|APIClient|InAppPurchasePriceRepository|OfferCodeRepository|WinBackOffer|PromotionalOffer'Repository: tddworks/asc-cli Length of output: 12373 🏁 Script executed: sed -n '1,130p' Sources/Infrastructure/Client/APIClient.swift
sed -n '1,130p' Sources/Infrastructure/Apps/InAppPurchases/SDKInAppPurchasePriceRepository.swift
sed -n '1,115p' Tests/InfrastructureTests/Apps/InAppPurchases/SDKInAppPurchasePriceRepositoryTests.swift
sed -n '285,335p' Tests/InfrastructureTests/Apps/InAppPurchases/SDKInAppPurchasePriceRepositoryTests.swift
rg -n -C 5 'willReturnPages|requests|lastQuery|page-2' Tests/InfrastructureTests/Apps/InAppPurchases/SDKInAppPurchasePriceRepositoryTests.swift Tests/InfrastructureTests/Apps/InAppPurchases/OfferCodes/SDKInAppPurchaseOfferCodeRepositoryTests.swift Tests/InfrastructureTests/Apps/Subscriptions/SDKSubscriptionPriceRepositoryTests.swift Tests/InfrastructureTests/Apps/Subscriptions/OfferCodes/SDKSubscriptionOfferCodeRepositoryTests.swift Tests/InfrastructureTests/Apps/Subscriptions/SDKSubscriptionPromotionalOfferRepositoryTests.swift Tests/InfrastructureTests/Apps/Subscriptions/SDKWinBackOfferRepositoryTests.swiftRepository: tddworks/asc-cli Length of output: 27851 🏁 Script executed: rg -n -C 4 'requestAllPages|willReturnPages|requests.*query|lastQuery|cursor.*page-2|page-2.*cursor' Tests --glob '*.swift'Repository: tddworks/asc-cli Length of output: 16780 Assert the second-page request.
🐛 Suggested fix let result = try await repo.getPriceSchedule(iapId: "iap-7")
+ let manualPriceRequests = stub.requests.filter { $0.path.hasSuffix("/manualPrices") }
+ `#expect`(manualPriceRequests.count == 2)
+ let secondPageQuery = manualPriceRequests.last?.query ?? []
+ `#expect`(secondPageQuery.contains(where: { $0.0 == "cursor" && $0.1 == "page-2" }))
+ `#expect`(secondPageQuery.contains(where: { $0.0 == "limit" && $0.1 == "200" }))
+
let prices = result?.territoryPrices ?? []🤖 Prompt for AI Agents |
||
| stub.willReturn(InAppPurchasePricePointsResponse(data: [], links: .init(this: ""))) | ||
|
|
||
| let repo = SDKInAppPurchasePriceRepository(client: stub) | ||
| let result = try await repo.getPriceSchedule(iapId: "iap-7") | ||
|
|
||
| let prices = result?.territoryPrices ?? [] | ||
| #expect(prices.count == 175) | ||
| #expect(prices.first { $0.territory.id == "T174" }?.customerPrice == "174.99") | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: tddworks/asc-cli
Length of output: 1914
🏁 Script executed:
Repository: tddworks/asc-cli
Length of output: 17119
🤖 get_repo_knowledge executed:
get_repo_knowledge tddworks/asc-cli /tmp/coderabbit-repo-knowledge/tddworks-asc-cli-7ed782afLength of output: 922
🌐 Web query:
Apple App Store Connect API paging nextCursor paging information next page token repeated cursor contract💡 Result:
<source_evidence>
Citations:
🏁 Script executed:
Repository: tddworks/asc-cli
Length of output: 41787
🌐 Web query:
github AvdLee appstoreconnect-swift-sdk 4.2.0 APIProvider request async throws cancellation URLSession implementation💡 Result:
<source_evidence>
Citations:
🏁 Script executed:
Repository: tddworks/asc-cli
Length of output: 4263
🌐 Web query:
site:github.com/AvdLee/appstoreconnect-swift-sdk/tree/4.2.0 "struct Request" OR "class Request" query💡 Result:
<source_evidence>
Citations:
🏁 Script executed:
Repository: tddworks/asc-cli
Length of output: 313
🌐 Web query:
https://github.com/AvdLee/appstoreconnect-swift-sdk/blob/4.2.0/Sources/Endpoint.swift Request query struct💡 Result:
<source_evidence>
Citations:
🌐 Web query:
github AvdLee/appstoreconnect-swift-sdk 4.2.0 Endpoint.swift "public struct Request" "query:"💡 Result:
<source_evidence>
Citations:
Stop pagination when a cursor repeats.
requestAllPagesappends each successful response and continues whilenextCursoris non-nil. If responses keep returning the same cursor successfully, the price-schedule read can keep sending requests and accumulating pages. A request error exits the loop only if one occurs. Track returned cursors and throw when a cursor repeats.🐛 Suggested fix
🤖 Prompt for AI Agents