From 154b8ef9ec03fb4bec114e1bbb05715cd75ab212 Mon Sep 17 00:00:00 2001 From: Andrew Hatch Date: Tue, 27 Aug 2024 10:42:32 +0100 Subject: [PATCH] test: user-agent header can be set (#142) * test: demonstrate that the user-agent header can be set * chore: linting fixes --- .npmignore | 1 + dc-management-sdk-js.iml | 20 -------------------- src/lib/DynamicContent.spec.ts | 9 +++++++++ src/lib/http/AxiosHttpClient.spec.ts | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 20 deletions(-) delete mode 100644 dc-management-sdk-js.iml diff --git a/.npmignore b/.npmignore index 10ca7505..8b52ad64 100644 --- a/.npmignore +++ b/.npmignore @@ -13,3 +13,4 @@ coverage .nyc_output *.log dc-management-sdk-js.iml +*.iml diff --git a/dc-management-sdk-js.iml b/dc-management-sdk-js.iml deleted file mode 100644 index d1d2d789..00000000 --- a/dc-management-sdk-js.iml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/lib/DynamicContent.spec.ts b/src/lib/DynamicContent.spec.ts index 64f5d9b4..03aad04e 100644 --- a/src/lib/DynamicContent.spec.ts +++ b/src/lib/DynamicContent.spec.ts @@ -16,3 +16,12 @@ test('should be able to get a workflow state', async (t) => { const result = await client.workflowStates.get('5a497a000000000000000000'); t.is(result.label, 'Todo'); }); + +test('should send user-agent header', async (t) => { + const client = new MockDynamicContent(undefined, undefined, { + headers: { 'User-Agent': 'my user agent' }, + }); + const hubs = await client.hubs.list(); + t.is(hubs.getItems().length, 1); + t.is(client.mock.history.get[0].headers['User-Agent'], 'my user agent'); +}); diff --git a/src/lib/http/AxiosHttpClient.spec.ts b/src/lib/http/AxiosHttpClient.spec.ts index 82c0780c..c57a8b23 100644 --- a/src/lib/http/AxiosHttpClient.spec.ts +++ b/src/lib/http/AxiosHttpClient.spec.ts @@ -187,3 +187,21 @@ test('client should fail after max (3) retry attempts when responses return stat t.is(response.status, 500); t.is(mock.history.get.length, 4); }); + +test('client can send a configured user-agent', async (t) => { + const client = new AxiosHttpClient({ + headers: { 'User-Agent': 'test-user-agent' }, + }); + + const mock = new MockAdapter(client.client); + mock.resetHistory(); + + mock.onGet('/ping').reply(200, 'pong'); + + await client.request({ + method: HttpMethod.GET, + url: '/ping', + }); + + t.is(mock.history.get[0].headers['User-Agent'], 'test-user-agent'); +});