-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
3,287 additions
and
3,516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
262 changes: 131 additions & 131 deletions
262
integration-libs/opf/base/core/facade/opf-payment.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,131 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { TestBed } from '@angular/core/testing'; | ||
import { CommandService } from '@spartacus/core'; | ||
import { Observable, of } from 'rxjs'; | ||
import { | ||
OpfPaymentVerificationPayload, | ||
OpfPaymentVerificationResponse, | ||
SubmitInput, | ||
SubmitRequest, | ||
SubmitResponse, | ||
} from '../../root/model'; | ||
import { OpfPaymentConnector } from '../connectors'; | ||
import { OpfPaymentHostedFieldsService } from '../services'; | ||
import { OpfPaymentService } from './opf-payment.service'; | ||
|
||
class MockPaymentConnector { | ||
verifyPayment( | ||
paymentSessionId: string, | ||
payload: OpfPaymentVerificationPayload | ||
): Observable<OpfPaymentVerificationResponse> { | ||
return of({ | ||
paymentSessionId, | ||
payload, | ||
} as unknown) as Observable<OpfPaymentVerificationResponse>; | ||
} | ||
} | ||
|
||
class MockOpfPaymentHostedFieldsService { | ||
submitPayment( | ||
submitRequest: SubmitRequest, | ||
otpKey: string, | ||
paymentSessionId: string | ||
): Observable<SubmitResponse> { | ||
return of( | ||
submitRequest, | ||
otpKey, | ||
paymentSessionId | ||
) as Observable<SubmitResponse>; | ||
} | ||
|
||
submitCompletePayment(): Observable<boolean> { | ||
return of(true); | ||
} | ||
} | ||
|
||
const mockSubmitInput = { | ||
cartId: '123', | ||
} as SubmitInput; | ||
|
||
describe('OpfPaymentService', () => { | ||
let service: OpfPaymentService; | ||
let paymentConnector: MockPaymentConnector; | ||
let opfPaymentHostedFieldsServiceSpy: OpfPaymentHostedFieldsService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
OpfPaymentService, | ||
CommandService, | ||
{ | ||
provide: OpfPaymentConnector, | ||
useClass: MockPaymentConnector, | ||
}, | ||
{ | ||
provide: OpfPaymentHostedFieldsService, | ||
useClass: MockOpfPaymentHostedFieldsService, | ||
}, | ||
], | ||
}); | ||
|
||
service = TestBed.inject(OpfPaymentService); | ||
paymentConnector = TestBed.inject(OpfPaymentConnector); | ||
opfPaymentHostedFieldsServiceSpy = TestBed.inject( | ||
OpfPaymentHostedFieldsService | ||
); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should call verifyPayment from connector with the correct payload', () => { | ||
const paymentSessionId = 'exampleSessionId'; | ||
const paymentVerificationPayload = { | ||
responseMap: [ | ||
{ | ||
key: 'key', | ||
value: 'value', | ||
}, | ||
], | ||
} as OpfPaymentVerificationPayload; | ||
const connectorVerifySpy = spyOn( | ||
paymentConnector, | ||
'verifyPayment' | ||
).and.callThrough(); | ||
|
||
service.verifyPayment(paymentSessionId, paymentVerificationPayload); | ||
|
||
expect(connectorVerifySpy).toHaveBeenCalledWith( | ||
paymentSessionId, | ||
paymentVerificationPayload | ||
); | ||
}); | ||
|
||
it('should call submitPayment from opfPaymentHostedFieldsService with the correct payload', () => { | ||
const submitPaymentSpy = spyOn( | ||
opfPaymentHostedFieldsServiceSpy, | ||
'submitPayment' | ||
).and.callThrough(); | ||
|
||
service.submitPayment(mockSubmitInput); | ||
|
||
expect(submitPaymentSpy).toHaveBeenCalledWith(mockSubmitInput); | ||
}); | ||
|
||
it('should call submitCompletePayment from opfPaymentHostedFieldsService with the correct payload', () => { | ||
const submitCompletePaymentSpy = spyOn( | ||
opfPaymentHostedFieldsServiceSpy, | ||
'submitCompletePayment' | ||
).and.callThrough(); | ||
|
||
service.submitCompletePayment(mockSubmitInput); | ||
|
||
expect(submitCompletePaymentSpy).toHaveBeenCalledWith(mockSubmitInput); | ||
}); | ||
}); | ||
// /* | ||
// * SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
// * | ||
// * SPDX-License-Identifier: Apache-2.0 | ||
// */ | ||
|
||
// import { TestBed } from '@angular/core/testing'; | ||
// import { CommandService } from '@spartacus/core'; | ||
// import { Observable, of } from 'rxjs'; | ||
// import { | ||
// OpfPaymentVerificationPayload, | ||
// OpfPaymentVerificationResponse, | ||
// SubmitInput, | ||
// SubmitRequest, | ||
// SubmitResponse, | ||
// } from '../../root/model'; | ||
// import { OpfPaymentConnector } from '../connectors'; | ||
// import { OpfPaymentHostedFieldsService } from '../services'; | ||
// import { OpfPaymentService } from './opf-payment.service'; | ||
|
||
// class MockPaymentConnector { | ||
// verifyPayment( | ||
// paymentSessionId: string, | ||
// payload: OpfPaymentVerificationPayload | ||
// ): Observable<OpfPaymentVerificationResponse> { | ||
// return of({ | ||
// paymentSessionId, | ||
// payload, | ||
// } as unknown) as Observable<OpfPaymentVerificationResponse>; | ||
// } | ||
// } | ||
|
||
// class MockOpfPaymentHostedFieldsService { | ||
// submitPayment( | ||
// submitRequest: SubmitRequest, | ||
// otpKey: string, | ||
// paymentSessionId: string | ||
// ): Observable<SubmitResponse> { | ||
// return of( | ||
// submitRequest, | ||
// otpKey, | ||
// paymentSessionId | ||
// ) as Observable<SubmitResponse>; | ||
// } | ||
|
||
// submitCompletePayment(): Observable<boolean> { | ||
// return of(true); | ||
// } | ||
// } | ||
|
||
// const mockSubmitInput = { | ||
// cartId: '123', | ||
// } as SubmitInput; | ||
|
||
// describe('OpfPaymentService', () => { | ||
// let service: OpfPaymentService; | ||
// let paymentConnector: MockPaymentConnector; | ||
// let opfPaymentHostedFieldsServiceSpy: OpfPaymentHostedFieldsService; | ||
|
||
// beforeEach(() => { | ||
// TestBed.configureTestingModule({ | ||
// providers: [ | ||
// OpfPaymentService, | ||
// CommandService, | ||
// { | ||
// provide: OpfPaymentConnector, | ||
// useClass: MockPaymentConnector, | ||
// }, | ||
// { | ||
// provide: OpfPaymentHostedFieldsService, | ||
// useClass: MockOpfPaymentHostedFieldsService, | ||
// }, | ||
// ], | ||
// }); | ||
|
||
// service = TestBed.inject(OpfPaymentService); | ||
// paymentConnector = TestBed.inject(OpfPaymentConnector); | ||
// opfPaymentHostedFieldsServiceSpy = TestBed.inject( | ||
// OpfPaymentHostedFieldsService | ||
// ); | ||
// }); | ||
|
||
// it('should be created', () => { | ||
// expect(service).toBeTruthy(); | ||
// }); | ||
|
||
// it('should call verifyPayment from connector with the correct payload', () => { | ||
// const paymentSessionId = 'exampleSessionId'; | ||
// const paymentVerificationPayload = { | ||
// responseMap: [ | ||
// { | ||
// key: 'key', | ||
// value: 'value', | ||
// }, | ||
// ], | ||
// } as OpfPaymentVerificationPayload; | ||
// const connectorVerifySpy = spyOn( | ||
// paymentConnector, | ||
// 'verifyPayment' | ||
// ).and.callThrough(); | ||
|
||
// service.verifyPayment(paymentSessionId, paymentVerificationPayload); | ||
|
||
// expect(connectorVerifySpy).toHaveBeenCalledWith( | ||
// paymentSessionId, | ||
// paymentVerificationPayload | ||
// ); | ||
// }); | ||
|
||
// it('should call submitPayment from opfPaymentHostedFieldsService with the correct payload', () => { | ||
// const submitPaymentSpy = spyOn( | ||
// opfPaymentHostedFieldsServiceSpy, | ||
// 'submitPayment' | ||
// ).and.callThrough(); | ||
|
||
// service.submitPayment(mockSubmitInput); | ||
|
||
// expect(submitPaymentSpy).toHaveBeenCalledWith(mockSubmitInput); | ||
// }); | ||
|
||
// it('should call submitCompletePayment from opfPaymentHostedFieldsService with the correct payload', () => { | ||
// const submitCompletePaymentSpy = spyOn( | ||
// opfPaymentHostedFieldsServiceSpy, | ||
// 'submitCompletePayment' | ||
// ).and.callThrough(); | ||
|
||
// service.submitCompletePayment(mockSubmitInput); | ||
|
||
// expect(submitCompletePaymentSpy).toHaveBeenCalledWith(mockSubmitInput); | ||
// }); | ||
// }); |
Oops, something went wrong.