Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace options calls by appropriate get requests #1714

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/core/services/api/api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('Api Service', () => {
});

it('should call the httpClient.options method when apiService.options method is called.', done => {
// eslint-disable-next-line etc/no-deprecated
apiService.options('data').subscribe({
next: data => {
expect(data).toBeTruthy();
Expand All @@ -79,6 +80,7 @@ describe('Api Service', () => {
it('should create Error Action if httpClient.options throws Error.', () => {
const statusText = 'ERROR';

// eslint-disable-next-line etc/no-deprecated
apiService.options('data').subscribe({ next: fail, error: fail });
const req = httpTestingController.expectOne(`${REST_URL}/data`);

Expand Down
3 changes: 2 additions & 1 deletion src/app/core/services/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ export class ApiService {
);
}

// not-dead-code
/**
* http options request
* @deprecated http options request - will be removed with the next major release (6.0)
*/
options<T>(path: string, options?: AvailableOptions): Observable<T> {
return this.execute(
Expand Down
6 changes: 2 additions & 4 deletions src/app/core/services/payment/payment.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,21 @@ describe('Payment Service', () => {
it("should get a user's payment method data when 'getUserPaymentMethods' is called for b2c/b2x applications", done => {
when(apiServiceMock.get(anyString())).thenReturn(of([]));
when(apiServiceMock.resolveLinks()).thenReturn(() => of([]));
when(apiServiceMock.options(anyString())).thenReturn(of([]));
const customer = {
customerNo: '4711',
isBusinessCustomer: false,
} as Customer;

paymentService.getUserPaymentMethods(customer).subscribe(() => {
verify(apiServiceMock.get('customers/4711/payments')).once();
verify(apiServiceMock.options('customers/4711/payments')).once();
verify(apiServiceMock.get('customers/4711/eligible-payment-methods')).once();
done();
});
});

it("should get a user's payment method data when 'getUserPaymentMethods' is called for rest applications", done => {
when(apiServiceMock.get(anyString())).thenReturn(of([]));
when(apiServiceMock.resolveLinks()).thenReturn(() => of([]));
when(apiServiceMock.options(anyString())).thenReturn(of([]));
when(appFacadeMock.customerRestResource$).thenReturn(of('privatecustomers'));
const customer = {
customerNo: '4711',
Expand All @@ -239,7 +237,7 @@ describe('Payment Service', () => {

paymentService.getUserPaymentMethods(customer).subscribe(() => {
verify(apiServiceMock.get('privatecustomers/4711/payments')).once();
verify(apiServiceMock.options('privatecustomers/4711/payments')).once();
verify(apiServiceMock.get('privatecustomers/4711/eligible-payment-methods')).once();
done();
});
});
Expand Down
4 changes: 3 additions & 1 deletion src/app/core/services/payment/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ export class PaymentService {
this.apiService.resolveLinks<PaymentInstrumentData>(),
concatMap(instruments =>
this.apiService
.options(`${restResource}/${this.apiService.encodeResourceId(customer.customerNo)}/payments`)
// replace the get request by an options request if your ICM version is lower than 11.10.0
// .options(`${restResource}/${this.apiService.encodeResourceId(customer.customerNo)}/payments`)
.get(`${restResource}/${this.apiService.encodeResourceId(customer.customerNo)}/eligible-payment-methods`)
.pipe(
unpackEnvelope<PaymentMethodOptionsDataType>('methods'),
map(methods => PaymentMethodMapper.fromOptions({ methods, instruments }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('Punchout Service', () => {
apiServiceMock = mock(ApiService);
cookiesServiceMock = mock(CookiesService);

when(apiServiceMock.options(anything(), anything())).thenReturn(of({}));
when(apiServiceMock.get(anything(), anything())).thenReturn(of({}));
when(apiServiceMock.resolveLinks(anything())).thenReturn(() => of([]));
when(apiServiceMock.post(anything(), anything(), anything())).thenReturn(of({}));
Expand Down Expand Up @@ -106,8 +105,8 @@ describe('Punchout Service', () => {

it("should get oci options when 'getOciConfigurationOptions' is called", done => {
punchoutService.getOciConfigurationOptions().subscribe(() => {
verify(apiServiceMock.options(anything(), anything())).once();
expect(capture(apiServiceMock.options).last()[0]).toMatchInlineSnapshot(`"customers/4711/punchouts/oci5"`);
verify(apiServiceMock.get(anything(), anything())).once();
expect(capture(apiServiceMock.get).last()[0]).toMatchInlineSnapshot(`"customers/4711/punchouts/oci5"`);
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ export class PunchoutService {
return this.currentCustomer$.pipe(
switchMap(customer =>
this.apiService
.options<OciOptionsData>(
// replace the get request by an options request if your ICM version is lower than 12.2.1
.get<OciOptionsData>(
`customers/${this.apiService.encodeResourceId(customer.customerNo)}/punchouts/${this.getResourceType(
'oci'
)}`,
Expand Down
Loading