Skip to content

Commit

Permalink
test(core): sign webhook payload data
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyijun committed May 22, 2023
1 parent 440f90b commit 608ce0c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/core/src/libraries/hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { got } from 'got';
import type { Interaction } from './hook.js';

const { jest } = import.meta;
const { mockEsmWithActual } = createMockUtils(jest);
const { mockEsmWithActual, mockEsm } = createMockUtils(jest);

const nanoIdMock = 'mockId';
await mockEsmWithActual('@logto/shared', () => ({
Expand All @@ -15,6 +15,11 @@ await mockEsmWithActual('@logto/shared', () => ({
generateStandardId: () => nanoIdMock,
}));

const mockSignature = 'mockSignature';
mockEsm('#src/utils/signature.js', () => ({
generateSignature: () => mockSignature,
}));

const { MockQueries } = await import('#src/test-utils/tenant.js');

const url = 'https://logto.gg';
Expand Down Expand Up @@ -78,7 +83,11 @@ describe('triggerInteractionHooksIfNeeded()', () => {

expect(findAllHooks).toHaveBeenCalled();
expect(post).toHaveBeenCalledWith(url, {
headers: { 'user-agent': 'Logto (https://logto.io)', bar: 'baz' },
headers: {
'user-agent': 'Logto (https://logto.io)',
bar: 'baz',
'x-logto-signature-256': mockSignature,
},
json: {
hookId: 'foo',
event: 'PostSignIn',
Expand Down

0 comments on commit 608ce0c

Please sign in to comment.