Skip to content

Commit

Permalink
test: user-agent header can be set (#142)
Browse files Browse the repository at this point in the history
* test: demonstrate that the user-agent header can be set

* chore: linting fixes
  • Loading branch information
ashatch authored Aug 27, 2024
1 parent 7660790 commit 154b8ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ coverage
.nyc_output
*.log
dc-management-sdk-js.iml
*.iml
20 changes: 0 additions & 20 deletions dc-management-sdk-js.iml

This file was deleted.

9 changes: 9 additions & 0 deletions src/lib/DynamicContent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
18 changes: 18 additions & 0 deletions src/lib/http/AxiosHttpClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 154b8ef

Please sign in to comment.