-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add additional tests to fix code coverage
- Loading branch information
Showing
3 changed files
with
116 additions
and
33 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
integration-libs/opf/base/core/connectors/opf-order.connector.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { of } from 'rxjs'; | ||
import createSpy = jasmine.createSpy; | ||
import { OpfOrderAdapter } from './opf-order.adapter'; | ||
import { OpfOrderConnector } from './opf-order.connector'; | ||
|
||
class MockOpfOrderAdapter implements OpfOrderAdapter { | ||
placeOpfOrder = createSpy('placeOpfOrder').and.callFake((userId, cartId, termsChecked) => | ||
of(`load-${userId}-${cartId}-${termsChecked}`) | ||
); | ||
} | ||
|
||
describe('OpfOrderConnector', () => { | ||
let service: OpfOrderConnector; | ||
let adapter: OpfOrderAdapter; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
OpfOrderConnector, | ||
{ provide: OpfOrderAdapter, useClass: MockOpfOrderAdapter }, | ||
], | ||
}); | ||
|
||
service = TestBed.inject(OpfOrderConnector); | ||
adapter = TestBed.inject(OpfOrderAdapter); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('validate should call adapter', () => { | ||
let result; | ||
service.placeOpfOrder('user1', 'cart1', true).subscribe((res) => (result = res)); | ||
expect(result).toEqual('load-user1-cart1-true'); | ||
expect(adapter.placeOpfOrder).toHaveBeenCalledWith('user1', 'cart1', true); | ||
}); | ||
}); |
71 changes: 38 additions & 33 deletions
71
integration-libs/opf/base/core/connectors/opf-payment.connector.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,40 +1,45 @@ | ||
// TODO: Add unit tests | ||
import { TestBed } from '@angular/core/testing'; | ||
import { of } from 'rxjs'; | ||
import { take } from 'rxjs/operators'; | ||
import createSpy = jasmine.createSpy; | ||
import { OpfPaymentAdapter } from './opf-payment.adapter'; | ||
import { OpfPaymentConnector } from './opf-payment.connector'; | ||
|
||
// import { TestBed } from '@angular/core/testing'; | ||
// import { ActiveConfiguration } from '@spartacus/opf/root'; | ||
// import { EMPTY, Observable } from 'rxjs'; | ||
// import { OpfCheckoutConnector } from './opf-checkout.connector'; | ||
// import { OpfAdapter } from './opf.adapter'; | ||
class MockOpfPaymentAdapter implements OpfPaymentAdapter { | ||
verifyPayment = createSpy().and.returnValue(of({})); | ||
submitPayment = createSpy().and.returnValue(of({})); | ||
} | ||
|
||
// class MockOpfAdapter implements Partial<OpfAdapter> { | ||
// getActiveConfigurations(): Observable<ActiveConfiguration[]> { | ||
// return EMPTY; | ||
// } | ||
// } | ||
describe('OpfPaymentConnector', () => { | ||
let service: OpfPaymentConnector; | ||
let adapter: OpfPaymentAdapter; | ||
|
||
// describe('OpfCheckoutConnector', () => { | ||
// let service: OpfCheckoutConnector; | ||
// let adapter: OpfAdapter; | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
OpfPaymentConnector, | ||
{ | ||
provide: OpfPaymentAdapter, | ||
useClass: MockOpfPaymentAdapter, | ||
}, | ||
], | ||
}); | ||
|
||
// beforeEach(() => { | ||
// TestBed.configureTestingModule({ | ||
// providers: [ | ||
// OpfCheckoutConnector, | ||
// { provide: OpfAdapter, useClass: MockOpfAdapter }, | ||
// ], | ||
// }); | ||
service = TestBed.inject(OpfPaymentConnector); | ||
adapter = TestBed.inject(OpfPaymentAdapter); | ||
}); | ||
|
||
// service = TestBed.inject(OpfCheckoutConnector); | ||
// adapter = TestBed.inject(OpfAdapter); | ||
// }); | ||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
// it('should be created', () => { | ||
// expect(service).toBeTruthy(); | ||
// }); | ||
it('should call adapter', () => { | ||
service.verifyPayment('1', {responseMap: [{key: 'test', value: 'value'}]}).pipe(take(1)).subscribe(); | ||
expect(adapter.verifyPayment).toHaveBeenCalledWith('1', {responseMap: [{key: 'test', value: 'value'}]}); | ||
}); | ||
|
||
// it('getActiveConfigurations should call adapter', () => { | ||
// spyOn(adapter, 'getActiveConfigurations').and.stub(); | ||
// service.getActiveConfigurations(); | ||
// expect(adapter.getActiveConfigurations).toHaveBeenCalled(); | ||
// }); | ||
// }); | ||
it('should call adapter', () => { | ||
service.submitPayment({}, '1', '2').pipe(take(1)).subscribe(); | ||
expect(adapter.submitPayment).toHaveBeenCalledWith({}, '1', '2'); | ||
}); | ||
}); | ||
39 changes: 39 additions & 0 deletions
39
integration-libs/opf/base/core/connectors/otp.connector.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { of } from 'rxjs'; | ||
import { take } from 'rxjs/operators'; | ||
import createSpy = jasmine.createSpy; | ||
import { OtpConnector } from './otp.connector'; | ||
import { OtpAdapter } from './otp.adapter'; | ||
|
||
class MockOtpAdapter implements OtpAdapter { | ||
generateOtpKey = createSpy().and.returnValue(of({})); | ||
} | ||
|
||
describe('OtpConnector', () => { | ||
let service: OtpConnector; | ||
let adapter: OtpAdapter; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
OtpConnector, | ||
{ | ||
provide: OtpAdapter, | ||
useClass: MockOtpAdapter, | ||
}, | ||
], | ||
}); | ||
|
||
service = TestBed.inject(OtpConnector); | ||
adapter = TestBed.inject(OtpAdapter); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should call adapter', () => { | ||
service.generateOtpKey('user1', 'cart1').pipe(take(1)).subscribe(); | ||
expect(adapter.generateOtpKey).toHaveBeenCalledWith('user1', 'cart1'); | ||
}); | ||
}); | ||