Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Sep 15, 2023
1 parent 5f07a6a commit 8fd9b7d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/management/token-provider-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import nock from 'nock';
import { jest } from '@jest/globals';
import { RequestOpts, InitOverrideFunction } from '../../src/lib/index.js';
import { RequestOpts, InitOverrideFunction, FetchAPI } from '../../src/lib/index.js';
import { BaseAPI } from '../../src/lib/runtime.js';
import { TokenProviderMiddleware } from '../../src/management/token-provider-middleware.js';

const domain = 'test-domain.auth0.com';

const customFetch = jest
.fn<FetchAPI>()
.mockImplementation((url: URL | RequestInfo, init?: RequestInit) => fetch(url, init));

const opts = {
baseUrl: `https://${domain}`,
clientId: 'test-client-id',
Expand All @@ -14,6 +18,7 @@ const opts = {
parseError: async (response: Response) => {
return new Error(`${response.status}`);
},
fetch: customFetch,
};

export class TestClient extends BaseAPI {
Expand Down Expand Up @@ -87,4 +92,11 @@ describe('TokenProviderMiddleware', () => {
})
);
});

it('should use custom fetch', async () => {
await expect(
clientSecretClient.testRequest({ path: '/foo', method: 'GET' })
).resolves.toMatchObject({});
expect(customFetch).toHaveBeenCalled();
});
});

0 comments on commit 8fd9b7d

Please sign in to comment.