@@ -634,6 +634,63 @@ final class AppStoreServerAPIClientTests: XCTestCase {
634634 XCTAssertEqual ( AppStoreServerAPIClient . ConfigurationError. invalidEnvironment, e as! AppStoreServerAPIClient . ConfigurationError )
635635 }
636636 }
637+
638+ public func testSetAppAccountToken( ) async throws {
639+ let client = try getAppStoreServerAPIClient ( " " ) { request, body in
640+ XCTAssertEqual ( . PUT, request. method)
641+ XCTAssertEqual ( " https://local-testing-base-url/inApps/v1/transactions/49571273/appAccountToken " , request. url)
642+ XCTAssertEqual ( [ " application/json " ] , request. headers [ " Content-Type " ] )
643+ let decodedJson = try ! JSONSerialization . jsonObject ( with: body!) as! [ String : Any ]
644+ XCTAssertEqual ( " 7389A31A-FB6D-4569-A2A6-DB7D85D84813 " , decodedJson [ " appAccountToken " ] as! String )
645+ }
646+
647+ let updateAppAccountTokenRequest = UpdateAppAccountTokenRequest (
648+ appAccountToken: UUID ( uuidString: " 7389a31a-fb6d-4569-a2a6-db7d85d84813 " )
649+ )
650+ TestingUtility . confirmCodableInternallyConsistent ( updateAppAccountTokenRequest)
651+
652+ let response = await client. setAppAccountToken ( originalTransactionId: " 49571273 " , updateAppAccountTokenRequest: updateAppAccountTokenRequest)
653+ guard case . success( _) = response else {
654+ XCTAssertTrue ( false )
655+ return
656+ }
657+ }
658+
659+ public func testFamilySharedTransactionNotSupportedError( ) async throws {
660+ let body = TestingUtility . readFile ( " resources/models/familyTransactionNotSupportedError.json " )
661+ let client = try getAppStoreServerAPIClient ( body, . badRequest, nil )
662+ let updateAppAccountTokenRequest = UpdateAppAccountTokenRequest (
663+ appAccountToken: UUID ( uuidString: " 7389a31a-fb6d-4569-a2a6-db7d85d84813 " )
664+ )
665+ let result = await client. setAppAccountToken ( originalTransactionId: " 1234 " , updateAppAccountTokenRequest: updateAppAccountTokenRequest)
666+ guard case . failure( let statusCode, let rawApiError, let apiError, let errorMessage, let causedBy) = result else {
667+ XCTAssertTrue ( false )
668+ return
669+ }
670+ XCTAssertEqual ( 400 , statusCode)
671+ XCTAssertNil ( apiError)
672+ XCTAssertEqual ( 4000185 , rawApiError)
673+ XCTAssertEqual ( " Invalid request. Family Sharing transactions aren't supported by this endpoint. " , errorMessage)
674+ XCTAssertNil ( causedBy)
675+ }
676+
677+ public func testTransactionIdNotOriginalTransactionIdError( ) async throws {
678+ let body = TestingUtility . readFile ( " resources/models/transactionIdNotOriginalTransactionId.json " )
679+ let client = try getAppStoreServerAPIClient ( body, . badRequest, nil )
680+ let updateAppAccountTokenRequest = UpdateAppAccountTokenRequest (
681+ appAccountToken: UUID ( uuidString: " 7389a31a-fb6d-4569-a2a6-db7d85d84813 " )
682+ )
683+ let result = await client. setAppAccountToken ( originalTransactionId: " 1234 " , updateAppAccountTokenRequest: updateAppAccountTokenRequest)
684+ guard case . failure( let statusCode, let rawApiError, let apiError, let errorMessage, let causedBy) = result else {
685+ XCTAssertTrue ( false )
686+ return
687+ }
688+ XCTAssertEqual ( 400 , statusCode)
689+ XCTAssertNil ( apiError)
690+ XCTAssertEqual ( 4000187 , rawApiError)
691+ XCTAssertEqual ( " Invalid request. The transaction ID provided is not an original transaction ID. " , errorMessage)
692+ XCTAssertNil ( causedBy)
693+ }
637694
638695 public func getClientWithBody( _ path: String , _ requestVerifier: @escaping RequestVerifier ) throws -> AppStoreServerAPIClient {
639696 let body = TestingUtility . readFile ( path)
0 commit comments