0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

fix(test): update social verification ut

update social verification util unit test
This commit is contained in:
simeng-li 2024-08-06 09:48:27 +08:00
parent 89b78a3a95
commit d74fb15aab
No known key found for this signature in database
GPG key ID: 14EA7BB1541E8075

View file

@ -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';
@ -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', () => ({
@ -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 () => {