22
33import { AccountTenure } from "../../models/AccountTenure" ;
44import { ConsumptionRequest } from "../../models/ConsumptionRequest" ;
5+ import { UpdateAppAccountTokenRequest } from "../../models/UpdateAppAccountTokenRequest" ;
56import { ConsumptionStatus } from "../../models/ConsumptionStatus" ;
67import { DeliveryStatus } from "../../models/DeliveryStatus" ;
78import { Environment } from "../../models/Environment" ;
@@ -556,4 +557,88 @@ describe('The api client ', () => {
556557 expect ( error . message ) . toBe ( "Xcode is not a supported environment for an AppStoreServerAPIClient" )
557558 }
558559 } )
560+
561+ it ( 'calls setAppAccountToken' , async ( ) => {
562+ const client = getAppStoreServerAPIClient ( "" , 200 , ( path : string , parsedQueryParameters : URLSearchParams , method : string , stringBody : string | undefined , headers : { [ key : string ] : string ; } ) => {
563+ expect ( "PUT" ) . toBe ( method )
564+ expect ( "/inApps/v1/transactions/49571273/appAccountToken" ) . toBe ( path )
565+ expect ( parsedQueryParameters . entries . length ) . toBe ( 0 )
566+
567+ expect ( stringBody ) . toBeTruthy ( )
568+ const body = JSON . parse ( stringBody ! )
569+ expect ( "7389a31a-fb6d-4569-a2a6-db7d85d84813" ) . toBe ( body . appAccountToken )
570+ } ) ;
571+
572+ const updateAppAccountTokenRequest : UpdateAppAccountTokenRequest = {
573+ appAccountToken : "7389a31a-fb6d-4569-a2a6-db7d85d84813"
574+ }
575+
576+ client . setAppAccountToken ( "49571273" , updateAppAccountTokenRequest ) ;
577+ } )
578+
579+ it ( 'calls setAppAccountToken but receives an invalid UUID error' , async ( ) => {
580+ const client = getClientWithBody ( "tests/resources/models/invalidAppAccountTokenUUIDError.json" , ( path : string , parsedQueryParameters : URLSearchParams , method : string , stringBody : string | undefined , headers : { [ key : string ] : string ; } ) => {
581+ expect ( "PUT" ) . toBe ( method )
582+ expect ( "/inApps/v1/transactions/49571273/appAccountToken" ) . toBe ( path )
583+ expect ( parsedQueryParameters . entries . length ) . toBe ( 0 )
584+ expect ( stringBody ) . toBeTruthy ( )
585+ } , 400 ) ;
586+
587+ try {
588+ const updateAppAccountTokenRequest : UpdateAppAccountTokenRequest = {
589+ appAccountToken : "abc"
590+ }
591+ await client . setAppAccountToken ( "49571273" , updateAppAccountTokenRequest ) ;
592+ fail ( 'this test call is expected to throw' )
593+ } catch ( e ) {
594+ let error = e as APIException
595+ expect ( error . httpStatusCode ) . toBe ( 400 )
596+ expect ( error . apiError ) . toBe ( 4000183 )
597+ expect ( error . errorMessage ) . toBe ( "Invalid request. The app account token field must be a valid UUID." )
598+ }
599+ } )
600+
601+ it ( 'calls setAppAccountToken but receives family transaction not supported error' , async ( ) => {
602+ const client = getClientWithBody ( "tests/resources/models/familyTransactionNotSupportedError.json" , ( path : string , parsedQueryParameters : URLSearchParams , method : string , stringBody : string | undefined , headers : { [ key : string ] : string ; } ) => {
603+ expect ( "PUT" ) . toBe ( method )
604+ expect ( "/inApps/v1/transactions/1234/appAccountToken" ) . toBe ( path )
605+ expect ( parsedQueryParameters . entries . length ) . toBe ( 0 )
606+ expect ( stringBody ) . toBeTruthy ( )
607+ } , 400 ) ;
608+
609+ try {
610+ const updateAppAccountTokenRequest : UpdateAppAccountTokenRequest = {
611+ appAccountToken : "7389a31a-fb6d-4569-a2a6-db7d85d84813"
612+ }
613+ await client . setAppAccountToken ( "1234" , updateAppAccountTokenRequest ) ;
614+ fail ( 'this test call is expected to throw' )
615+ } catch ( e ) {
616+ let error = e as APIException
617+ expect ( error . httpStatusCode ) . toBe ( 400 )
618+ expect ( error . apiError ) . toBe ( 4000185 )
619+ expect ( error . errorMessage ) . toBe ( "Invalid request. Family Sharing transactions aren't supported by this endpoint." )
620+ }
621+ } )
622+
623+ it ( 'calls setAppAccountToken but transactionId not originalTransactionId error' , async ( ) => {
624+ const client = getClientWithBody ( "tests/resources/models/transactionIdNotOriginalTransactionId.json" , ( path : string , parsedQueryParameters : URLSearchParams , method : string , stringBody : string | undefined , headers : { [ key : string ] : string ; } ) => {
625+ expect ( "PUT" ) . toBe ( method )
626+ expect ( "/inApps/v1/transactions/1234/appAccountToken" ) . toBe ( path )
627+ expect ( parsedQueryParameters . entries . length ) . toBe ( 0 )
628+ expect ( stringBody ) . toBeTruthy ( )
629+ } , 400 ) ;
630+
631+ try {
632+ const updateAppAccountTokenRequest : UpdateAppAccountTokenRequest = {
633+ appAccountToken : "7389a31a-fb6d-4569-a2a6-db7d85d84813"
634+ }
635+ await client . setAppAccountToken ( "1234" , updateAppAccountTokenRequest ) ;
636+ fail ( 'this test call is expected to throw' )
637+ } catch ( e ) {
638+ let error = e as APIException
639+ expect ( error . httpStatusCode ) . toBe ( 400 )
640+ expect ( error . apiError ) . toBe ( 4000187 )
641+ expect ( error . errorMessage ) . toBe ( "Invalid request. The transaction ID provided is not an original transaction ID." )
642+ }
643+ } )
559644} )
0 commit comments