|
1 | 1 | import HttpClient, { mergeHeaders, RequestOpts } from '../../src/oms/core/http' |
2 | 2 | import { Client, cloud } from '../../src/oms' |
3 | 3 |
|
4 | | -import { disableFetchMocks, enableFetchMocks } from 'jest-fetch-mock' |
| 4 | +import fetchMock from 'jest-fetch-mock' |
5 | 5 | import { json } from '../utils/helpers' |
6 | 6 |
|
7 | 7 | test('RequestOpts: nothing', () => { |
@@ -50,31 +50,41 @@ test('Client: header merging', () => { |
50 | 50 |
|
51 | 51 | const simpleBody = '{"token": {"user": {"domain": {"id": ""}}, "catalog": []}}' |
52 | 52 |
|
53 | | -test('Client: required headers', async () => { |
54 | | - const authUrl = 'https://google.com/' |
55 | | - const config = cloud(authUrl).withToken('t').config |
56 | | - const client = new Client(config) |
57 | | - enableFetchMocks() |
58 | | - fetchMock.mockOnce(async r => { |
59 | | - expect(r.headers.get('Accept')).toBeDefined() |
60 | | - expect(r.headers.get('Content-Type')).toBeDefined() |
61 | | - expect(r.headers.get('Host')).toBeDefined() |
62 | | - expect(r.headers.get('User-Agent')).toBeDefined() |
63 | | - return json(simpleBody) |
| 53 | +describe('Test requests', () => { |
| 54 | + beforeAll(() => { |
| 55 | + fetchMock.enableMocks() |
| 56 | + }) |
| 57 | + beforeEach(() => { |
| 58 | + fetchMock.resetMocks() |
| 59 | + }) |
| 60 | + afterAll(() => { |
| 61 | + fetchMock.disableMocks() |
64 | 62 | }) |
65 | | - await client.authenticate() |
66 | | - disableFetchMocks() |
67 | | -}) |
68 | 63 |
|
69 | | -test('Client: complex URL', async () => { |
70 | | - const authUrl = 'https://rtest.outcatcher.com/meta/proxy/https:/iam.eu-de.otc.t-systems.com/v3' |
71 | | - const config = cloud(authUrl).withToken('t').config |
72 | | - const client = new Client(config) |
73 | | - enableFetchMocks() |
74 | | - fetchMock.mockOnce(async r => { |
75 | | - expect(r.url).toBe(authUrl + '/auth/tokens') |
76 | | - return json(simpleBody) |
| 64 | + |
| 65 | + test('Client: required headers', async () => { |
| 66 | + const authUrl = 'https://acme.com/' |
| 67 | + const config = cloud(authUrl).withToken('t').config |
| 68 | + const client = new Client(config) |
| 69 | + fetchMock.mockOnce(async r => { |
| 70 | + expect(r.headers.get('Accept')).toBeDefined() |
| 71 | + expect(r.headers.get('Content-Type')).toBeDefined() |
| 72 | + expect(r.headers.get('Host')).toBeDefined() |
| 73 | + expect(r.headers.get('User-Agent')).toBeDefined() |
| 74 | + return json(simpleBody) |
| 75 | + }) |
| 76 | + await client.authenticate() |
| 77 | + }) |
| 78 | + |
| 79 | + test('Client: complex URL', async () => { |
| 80 | + const authUrl = 'https://rtest.outcatcher.com/meta/proxy/https:/iam.eu-de.otc.t-systems.com/v3' |
| 81 | + const config = cloud(authUrl).withToken('t').config |
| 82 | + const client = new Client(config) |
| 83 | + fetchMock.mockOnce(async r => { |
| 84 | + expect(r.url).toBe(authUrl + '/auth/tokens') |
| 85 | + return json(simpleBody) |
| 86 | + }) |
| 87 | + await client.authenticate() |
77 | 88 | }) |
78 | | - await client.authenticate() |
79 | | - disableFetchMocks() |
80 | 89 | }) |
| 90 | + |
0 commit comments