@@ -11,7 +11,11 @@ import {
1111 User ,
1212 UserSubscriptionStatus ,
1313} from '../../../src/entity' ;
14- import { createMockNjordTransport , saveFixtures } from '../../helpers' ;
14+ import {
15+ createMockNjordErrorTransport ,
16+ createMockNjordTransport ,
17+ saveFixtures ,
18+ } from '../../helpers' ;
1519import {
1620 NotificationTypeV2 ,
1721 Subtype ,
@@ -24,7 +28,7 @@ import { env } from 'process';
2428import { deleteRedisKey , getRedisHash } from '../../../src/redis' ;
2529import { StorageKey } from '../../../src/config' ;
2630import { createClient } from '@connectrpc/connect' ;
27- import { Credits } from '@dailydotdev/schema' ;
31+ import { Credits , TransferStatus } from '@dailydotdev/schema' ;
2832import * as njordCommon from '../../..//src/common/njord' ;
2933import { getTransactionForProviderId } from '../../../src/common/paddle' ;
3034import { UserTransactionProcessor } from '../../../src/entity/user/UserTransaction' ;
@@ -555,5 +559,63 @@ describe('POST /webhooks/apple/notifications', () => {
555559 } ) ;
556560 expect ( userTransaction ) . toBeNull ( ) ;
557561 } ) ;
562+
563+ it ( 'should error cores purchase on njord error' , async ( ) => {
564+ jest . spyOn ( njordCommon , 'getNjordClient' ) . mockImplementation ( ( ) =>
565+ createClient (
566+ Credits ,
567+ createMockNjordErrorTransport ( {
568+ errorStatus : TransferStatus . INSUFFICIENT_FUNDS ,
569+ errorMessage : 'Insufficient funds' ,
570+ } ) ,
571+ ) ,
572+ ) ;
573+
574+ const purchaseCoresSpy = jest . spyOn ( njordCommon , 'purchaseCores' ) ;
575+
576+ await request ( app . server )
577+ . post ( '/webhooks/apple/notifications' )
578+ . send ( {
579+ signedPayload : signedPayload ( {
580+ notificationType : NotificationTypeV2 . ONE_TIME_CHARGE ,
581+ data : {
582+ signedTransactionInfo : {
583+ productId : 'cores_100' ,
584+ quantity : 1 ,
585+ type : 'Consumable' ,
586+ appAccountToken : '18138f83-b4d3-456a-831f-1f3f7bcbb0bd' ,
587+ transactionId : '220698' ,
588+ } ,
589+ } ,
590+ } ) ,
591+ } )
592+ . expect ( 200 ) ;
593+
594+ expect ( purchaseCoresSpy ) . toHaveBeenCalledTimes ( 1 ) ;
595+
596+ const userTransaction = await getTransactionForProviderId ( {
597+ con,
598+ providerId : '220698' ,
599+ } ) ;
600+
601+ expect ( userTransaction ) . toEqual ( {
602+ id : expect . any ( String ) ,
603+ createdAt : expect . any ( Date ) ,
604+ fee : 0 ,
605+ flags : {
606+ providerId : '220698' ,
607+ error : 'Insufficient Cores balance.' ,
608+ } ,
609+ processor : UserTransactionProcessor . AppleStoreKit ,
610+ productId : null ,
611+ receiverId : 'storekit-user-c-1' ,
612+ request : { } ,
613+ senderId : null ,
614+ status : 1 ,
615+ updatedAt : expect . any ( Date ) ,
616+ value : 100 ,
617+ valueIncFees : 100 ,
618+ } ) ;
619+ } ) ;
558620 } ) ;
559621} ) ;
0 commit comments