-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: CXSPA-4611, CXSPA-4612
- Loading branch information
Showing
9 changed files
with
723 additions
and
726 deletions.
There are no files selected for viewing
306 changes: 153 additions & 153 deletions
306
.../base/root/components/opf-payment-verification/opf-payment-verification.component.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,153 +1,153 @@ | ||
// /* | ||
// * SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
// * | ||
// * SPDX-License-Identifier: Apache-2.0 | ||
// */ | ||
|
||
// import { Component } from '@angular/core'; | ||
// import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
// import { ActivatedRoute } from '@angular/router'; | ||
// import { HttpErrorModel } from '@spartacus/core'; | ||
// import { Order } from '@spartacus/order/root'; | ||
// import { of, Subscription, throwError } from 'rxjs'; | ||
// import { OpfResponseMapElement } from '../../model'; | ||
// import { OpfPaymentVerificationComponent } from './opf-payment-verification.component'; | ||
// import { OpfPaymentVerificationService } from './opf-payment-verification.service'; | ||
|
||
// @Component({ | ||
// selector: 'cx-spinner', | ||
// template: '', | ||
// }) | ||
// class MockSpinnerComponent {} | ||
|
||
// describe('OpfPaymentVerificationComponent', () => { | ||
// let component: OpfPaymentVerificationComponent; | ||
// let fixture: ComponentFixture<OpfPaymentVerificationComponent>; | ||
// let routeMock: jasmine.SpyObj<ActivatedRoute>; | ||
// let paymentServiceMock: jasmine.SpyObj<OpfPaymentVerificationService>; | ||
|
||
// beforeEach(() => { | ||
// routeMock = jasmine.createSpyObj('ActivatedRoute', [], { | ||
// snapshot: { queryParamMap: new Map() }, | ||
// }); | ||
// paymentServiceMock = jasmine.createSpyObj('OpfPaymentVerificationService', [ | ||
// 'checkIfProcessingCartIdExist', | ||
// 'verifyResultUrl', | ||
// 'verifyPayment', | ||
// 'placeOrder', | ||
// 'goToPage', | ||
// 'displayError', | ||
// ]); | ||
|
||
// TestBed.configureTestingModule({ | ||
// declarations: [OpfPaymentVerificationComponent, MockSpinnerComponent], | ||
// providers: [ | ||
// { provide: ActivatedRoute, useValue: routeMock }, | ||
// { | ||
// provide: OpfPaymentVerificationService, | ||
// useValue: paymentServiceMock, | ||
// }, | ||
// ], | ||
// }); | ||
|
||
// fixture = TestBed.createComponent(OpfPaymentVerificationComponent); | ||
// component = fixture.componentInstance; | ||
// }); | ||
|
||
// it('should create', () => { | ||
// expect(component).toBeTruthy(); | ||
// }); | ||
|
||
// describe('ngOnInit', () => { | ||
// it('should call checkIfProcessingCartIdExist', () => { | ||
// paymentServiceMock.verifyResultUrl.and.returnValue(of()); | ||
|
||
// component.ngOnInit(); | ||
// expect( | ||
// paymentServiceMock.checkIfProcessingCartIdExist | ||
// ).toHaveBeenCalled(); | ||
// }); | ||
|
||
// it('should handle success scenario', () => { | ||
// const mockPaymentSessionId = 'sessionId'; | ||
// const mockResponseMap: OpfResponseMapElement[] = []; | ||
// const mockVerifyResult: { | ||
// paymentSessionId: string; | ||
// responseMap: OpfResponseMapElement[]; | ||
// } = { | ||
// paymentSessionId: mockPaymentSessionId, | ||
// responseMap: mockResponseMap, | ||
// }; | ||
// const mockPlaceOrderResult: Order = { guid: 'placeOrderResult' }; | ||
|
||
// paymentServiceMock.verifyResultUrl.and.returnValue(of(mockVerifyResult)); | ||
// paymentServiceMock.verifyPayment.and.returnValue(of(true)); | ||
// paymentServiceMock.placeOrder.and.returnValue(of(mockPlaceOrderResult)); | ||
|
||
// component.ngOnInit(); | ||
|
||
// expect(paymentServiceMock.verifyResultUrl).toHaveBeenCalledWith( | ||
// routeMock | ||
// ); | ||
// expect(paymentServiceMock.verifyPayment).toHaveBeenCalledWith( | ||
// mockPaymentSessionId, | ||
// mockResponseMap | ||
// ); | ||
// expect(paymentServiceMock.placeOrder).toHaveBeenCalled(); | ||
// }); | ||
|
||
// it('should handle error scenario', () => { | ||
// const mockError: HttpErrorModel = { status: 500, message: 'Error' }; | ||
|
||
// const mockVerifyResult = { | ||
// paymentSessionId: '1', | ||
// responseMap: [], | ||
// }; | ||
|
||
// paymentServiceMock.verifyResultUrl.and.returnValue(of(mockVerifyResult)); | ||
// paymentServiceMock.verifyPayment.and.returnValue(throwError(mockError)); | ||
|
||
// spyOn(component, 'onError'); | ||
|
||
// component.ngOnInit(); | ||
|
||
// expect(component.onError).toHaveBeenCalledWith(mockError); | ||
// }); | ||
// }); | ||
|
||
// describe('onSuccess', () => { | ||
// it('should call paymentService.goToPage with "orderConfirmation"', () => { | ||
// component.onSuccess(); | ||
// expect(paymentServiceMock.goToPage).toHaveBeenCalledWith( | ||
// 'orderConfirmation' | ||
// ); | ||
// }); | ||
// }); | ||
|
||
// describe('onError', () => { | ||
// it('should call paymentService.displayError with the provided error and paymentService.goToPage with "checkoutReviewOrder"', () => { | ||
// const mockError: HttpErrorModel = { status: 404, message: 'Not Found' }; | ||
|
||
// component.onError(mockError); | ||
|
||
// expect(paymentServiceMock.displayError).toHaveBeenCalledWith(mockError); | ||
// expect(paymentServiceMock.goToPage).toHaveBeenCalledWith( | ||
// 'checkoutReviewOrder' | ||
// ); | ||
// }); | ||
// }); | ||
|
||
// describe('ngOnDestroy', () => { | ||
// it('should unsubscribe from the subscription', () => { | ||
// const subscriptionMock: Subscription = jasmine.createSpyObj( | ||
// 'Subscription', | ||
// ['unsubscribe'] | ||
// ); | ||
// component.subscription = subscriptionMock; | ||
|
||
// component.ngOnDestroy(); | ||
|
||
// expect(subscriptionMock.unsubscribe).toHaveBeenCalled(); | ||
// }); | ||
// }); | ||
// }); | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Component } from '@angular/core'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { HttpErrorModel } from '@spartacus/core'; | ||
import { Order } from '@spartacus/order/root'; | ||
import { Subscription, of, throwError } from 'rxjs'; | ||
import { OpfResponseMapElement } from '../../model'; | ||
import { OpfPaymentVerificationComponent } from './opf-payment-verification.component'; | ||
import { OpfPaymentVerificationService } from './opf-payment-verification.service'; | ||
|
||
@Component({ | ||
selector: 'cx-spinner', | ||
template: '', | ||
}) | ||
class MockSpinnerComponent {} | ||
|
||
describe('OpfPaymentVerificationComponent', () => { | ||
let component: OpfPaymentVerificationComponent; | ||
let fixture: ComponentFixture<OpfPaymentVerificationComponent>; | ||
let routeMock: jasmine.SpyObj<ActivatedRoute>; | ||
let paymentServiceMock: jasmine.SpyObj<OpfPaymentVerificationService>; | ||
|
||
beforeEach(() => { | ||
routeMock = jasmine.createSpyObj('ActivatedRoute', [], { | ||
snapshot: { queryParamMap: new Map() }, | ||
}); | ||
paymentServiceMock = jasmine.createSpyObj('OpfPaymentVerificationService', [ | ||
'checkIfProcessingCartIdExist', | ||
'verifyResultUrl', | ||
'verifyPayment', | ||
'placeOrder', | ||
'goToPage', | ||
'displayError', | ||
]); | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [OpfPaymentVerificationComponent, MockSpinnerComponent], | ||
providers: [ | ||
{ provide: ActivatedRoute, useValue: routeMock }, | ||
{ | ||
provide: OpfPaymentVerificationService, | ||
useValue: paymentServiceMock, | ||
}, | ||
], | ||
}); | ||
|
||
fixture = TestBed.createComponent(OpfPaymentVerificationComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
describe('ngOnInit', () => { | ||
it('should call checkIfProcessingCartIdExist', () => { | ||
paymentServiceMock.verifyResultUrl.and.returnValue(of()); | ||
|
||
component.ngOnInit(); | ||
expect( | ||
paymentServiceMock.checkIfProcessingCartIdExist | ||
).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should handle success scenario', () => { | ||
const mockPaymentSessionId = 'sessionId'; | ||
const mockResponseMap: OpfResponseMapElement[] = []; | ||
const mockVerifyResult: { | ||
paymentSessionId: string; | ||
responseMap: OpfResponseMapElement[]; | ||
} = { | ||
paymentSessionId: mockPaymentSessionId, | ||
responseMap: mockResponseMap, | ||
}; | ||
const mockPlaceOrderResult: Order = { guid: 'placeOrderResult' }; | ||
|
||
paymentServiceMock.verifyResultUrl.and.returnValue(of(mockVerifyResult)); | ||
paymentServiceMock.verifyPayment.and.returnValue(of(true)); | ||
paymentServiceMock.placeOrder.and.returnValue(of(mockPlaceOrderResult)); | ||
|
||
component.ngOnInit(); | ||
|
||
expect(paymentServiceMock.verifyResultUrl).toHaveBeenCalledWith( | ||
routeMock | ||
); | ||
expect(paymentServiceMock.verifyPayment).toHaveBeenCalledWith( | ||
mockPaymentSessionId, | ||
mockResponseMap | ||
); | ||
expect(paymentServiceMock.placeOrder).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should handle error scenario', () => { | ||
const mockError: HttpErrorModel = { status: 500, message: 'Error' }; | ||
|
||
const mockVerifyResult = { | ||
paymentSessionId: '1', | ||
responseMap: [], | ||
}; | ||
|
||
paymentServiceMock.verifyResultUrl.and.returnValue(of(mockVerifyResult)); | ||
paymentServiceMock.verifyPayment.and.returnValue(throwError(mockError)); | ||
|
||
spyOn(component, 'onError'); | ||
|
||
component.ngOnInit(); | ||
|
||
expect(component.onError).toHaveBeenCalledWith(mockError); | ||
}); | ||
}); | ||
|
||
describe('onSuccess', () => { | ||
it('should call paymentService.goToPage with "orderConfirmation"', () => { | ||
component.onSuccess(); | ||
expect(paymentServiceMock.goToPage).toHaveBeenCalledWith( | ||
'orderConfirmation' | ||
); | ||
}); | ||
}); | ||
|
||
describe('onError', () => { | ||
it('should call paymentService.displayError with the provided error and paymentService.goToPage with "checkoutReviewOrder"', () => { | ||
const mockError: HttpErrorModel = { status: 404, message: 'Not Found' }; | ||
|
||
component.onError(mockError); | ||
|
||
expect(paymentServiceMock.displayError).toHaveBeenCalledWith(mockError); | ||
expect(paymentServiceMock.goToPage).toHaveBeenCalledWith( | ||
'checkoutReviewOrder' | ||
); | ||
}); | ||
}); | ||
|
||
describe('ngOnDestroy', () => { | ||
it('should unsubscribe from the subscription', () => { | ||
const subscriptionMock: Subscription = jasmine.createSpyObj( | ||
'Subscription', | ||
['unsubscribe'] | ||
); | ||
component.subscription = subscriptionMock; | ||
|
||
component.ngOnDestroy(); | ||
|
||
expect(subscriptionMock.unsubscribe).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.