Skip to content

Commit

Permalink
fix(test): update social verification ut
Browse files Browse the repository at this point in the history
update social verification util unit test
  • Loading branch information
simeng-li committed Aug 7, 2024
1 parent ba6b6af commit a41ca37
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ConnectorType, GoogleConnector } from '@logto/connector-kit';
import { createMockUtils } from '@logto/shared/esm';

import { mockConnector } from '#src/__mocks__/connector.js';
import type { WithLogContext } from '#src/middleware/koa-audit-log.js';
import createMockContext from '#src/test-utils/jest-koa-mocks/create-mock-context.js';
import { createMockLogContext } from '#src/test-utils/koa-audit-log.js';
Expand All @@ -10,9 +11,10 @@ const { jest } = import.meta;
const { mockEsm } = createMockUtils(jest);

const getUserInfo = jest.fn().mockResolvedValue({ id: 'foo' });
const getConnector = jest.fn().mockResolvedValue(mockConnector);

const tenant = new MockTenant(undefined, undefined, undefined, {
socials: { getUserInfo },
socials: { getUserInfo, getConnector },
});

mockEsm('#src/libraries/connector.js', () => ({
Expand Down Expand Up @@ -49,12 +51,19 @@ describe('verifySocialIdentity', () => {
// @ts-expect-error test mock context
cookies: { get: jest.fn().mockReturnValue('token') },
};
const connectorId = GoogleConnector.factoryId;

getConnector.mockResolvedValueOnce({
...mockConnector,
metadata: {
...mockConnector.metadata,
id: GoogleConnector.factoryId,
},
});
const connectorData = { credential: 'credential' };

await expect(verifySocialIdentity({ connectorId, connectorData }, ctx, tenant)).rejects.toThrow(
'CSRF token mismatch.'
);
await expect(
verifySocialIdentity({ connectorId: 'google', connectorData }, ctx, tenant)
).rejects.toThrow('CSRF token mismatch.');
});

it('should verify Google One Tap verification', async () => {
Expand Down

0 comments on commit a41ca37

Please sign in to comment.