Skip to content

Commit

Permalink
wip: 🧪 experiment client
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Nov 18, 2020
1 parent c7a2846 commit e288d69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions libs/angular/src/lib/convoyr.inteceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createRequest, createResponse, Convoyr } from '@convoyr/core';
import { EMPTY, of, throwError } from 'rxjs';

import { ConvoyrInterceptor } from './convoyr.interceptor';
import { ConvoyrService } from './convoyr.service';

function asMock<TReturn, TArgs extends any[]>(
value: (...TArgs) => TReturn
Expand All @@ -20,18 +21,18 @@ function asMock<TReturn, TArgs extends any[]>(
}

describe('ConvoyrInterceptor', () => {
let convoyr: Convoyr;
let convoyrService: ConvoyrService;
let interceptor: ConvoyrInterceptor;
let next: HttpHandler;
let observerSpy: ObserverSpy<HttpResponse<unknown>>;

beforeEach(() => {
interceptor = new ConvoyrInterceptor({ plugins: [] });
convoyrService = new ConvoyrService({ plugins: [] });
interceptor = new ConvoyrInterceptor(convoyrService);
observerSpy = new ObserverSpy({ expectErrors: true });
convoyr = interceptor['_convoyr'];

/* Mock `Convoyr.handle`. */
jest.spyOn(convoyr, 'handle');
/* Mock `ConvoyrService.handle`. */
jest.spyOn(convoyrService, 'handle');

next = {
/* Just to avoid pipe error. */
Expand All @@ -49,8 +50,8 @@ describe('ConvoyrInterceptor', () => {

it('should convert Angular HttpRequest to ConvoyrRequest before handing it to plugins', () => {
/* Check that request is transformed from Angular HttpRequest to ConvoyrRequest and forwarded to `convoyr`. */
expect(convoyr.handle).toHaveBeenCalledTimes(1);
expect(convoyr.handle).toHaveBeenCalledWith(
expect(convoyrService.handle).toHaveBeenCalledTimes(1);
expect(convoyrService.handle).toHaveBeenCalledWith(
expect.objectContaining({
request: createRequest({ url: 'https://test.com', method: 'GET' }),
})
Expand Down Expand Up @@ -86,7 +87,9 @@ describe('ConvoyrInterceptor', () => {
new HttpResponse({ body: { answer: 42 } })
)
);
const { request, httpHandler } = asMock(convoyr.handle).mock.calls[0][0];
const { request, httpHandler } = asMock(
convoyrService.handle
).mock.calls[0][0];

httpHandler.handle({ request }).subscribe(observerSpy);

Expand All @@ -103,7 +106,9 @@ describe('ConvoyrInterceptor', () => {
asMock(next.handle).mockReturnValue(
of(new HttpResponse({ body: { answer: 42 } }))
);
const { request, httpHandler } = asMock(convoyr.handle).mock.calls[0][0];
const { request, httpHandler } = asMock(
convoyrService.handle
).mock.calls[0][0];

httpHandler.handle({ request }).subscribe(observerSpy);

Expand Down Expand Up @@ -134,7 +139,9 @@ describe('ConvoyrInterceptor', () => {
})
)
);
const { request, httpHandler } = asMock(convoyr.handle).mock.calls[0][0];
const { request, httpHandler } = asMock(
convoyrService.handle
).mock.calls[0][0];

httpHandler.handle({ request }).subscribe(observerSpy);

Expand Down
2 changes: 1 addition & 1 deletion libs/angular/src/lib/convoyr.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { TestBed } from '@angular/core/testing';
import { createSpyPlugin, SpyPlugin } from '@convoyr/core/testing';
import { ObserverSpy } from '@hirez_io/observer-spy';
import { _CONVOYR_CONFIG } from './convoyr.interceptor';
import { _CONVOYR_CONFIG } from './convoyr.service';
import { ConvoyrModule } from './convoyr.module';

describe('ConvoyrModule', () => {
Expand Down

0 comments on commit e288d69

Please sign in to comment.