Skip to content

Commit

Permalink
add additional tests to fix code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhepS committed Jul 27, 2023
1 parent ba9c593 commit ecb7da2
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 33 deletions.
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);
});
});
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');
});
});

Check failure on line 45 in integration-libs/opf/base/core/connectors/opf-payment.connector.spec.ts

View workflow job for this annotation

GitHub Actions / CI - Validations and static code checks

Newline required at end of file but not found
39 changes: 39 additions & 0 deletions integration-libs/opf/base/core/connectors/otp.connector.spec.ts
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');
});
});

Check failure on line 39 in integration-libs/opf/base/core/connectors/otp.connector.spec.ts

View workflow job for this annotation

GitHub Actions / CI - Validations and static code checks

Newline required at end of file but not found

0 comments on commit ecb7da2

Please sign in to comment.