Skip to content

Commit a2b35cc

Browse files
committed
chore: boost code coverage to 100%
1 parent 7970a66 commit a2b35cc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/oidc-plugin-request/src/authenticator.spec.ts

+33
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { authenticator, canApplyAuthenticator } from './authenticator';
2929
import { requestLogger } from './requestLogger';
3030
import { requestCorrelator } from './requestCorrelator';
3131
import { makeRequestPlugin } from './makeRequestPlugin';
32+
import { authInterceptor, requestCorrelationInterceptor, requestLoggingInterceptor } from './interceptors';
3233

3334
interface ExtendedCoreOptions extends request.CoreOptions {
3435
simple?: boolean;
@@ -790,6 +791,38 @@ describe('authenticator', () => {
790791
};
791792
await correlationService.withIdAsync(work, 'test-123');
792793
});
794+
795+
test('interceptors', async () => {
796+
// setup
797+
const { session, states, logger} = setup();
798+
799+
const auth = authInterceptor(session);
800+
const logging = requestLoggingInterceptor(logger);
801+
const correlator = requestCorrelationInterceptor(correlationService);
802+
803+
const options: ExtendedCoreOptions = {
804+
resolveWithFullResponse: true,
805+
headers: {
806+
'x-correlation-id': 'custom CID',
807+
},
808+
};
809+
await auth(options);
810+
await logging(options);
811+
await correlator(options);
812+
// act
813+
const res = await httpGet('http://localhost:4000/api/secured', options);
814+
// expect
815+
expect(res.statusCode).toBe(200);
816+
expect(res.request.headers.authorization).toBe('Bearer token1');
817+
expect(res.req.getHeader('x-correlation-id')).toBe('custom CID');
818+
expect(requestCounter).toBe(1);
819+
expect(states).toEqual([
820+
OidcSessionState.acquiringToken,
821+
OidcSessionState.tokenAcquired,
822+
]);
823+
expect(logger.last().logType).toBe('debug');
824+
expect(logger.last().messageObj.url).toBe('http://localhost:4000/api/secured');
825+
});
793826

794827
function setup(options: ISetupOptions = {}) {
795828
setupOptions = options;

0 commit comments

Comments
 (0)