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:
parent
89b78a3a95
commit
d74fb15aab
1 changed files with 14 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { ConnectorType, GoogleConnector } from '@logto/connector-kit';
|
import { ConnectorType, GoogleConnector } from '@logto/connector-kit';
|
||||||
import { createMockUtils } from '@logto/shared/esm';
|
import { createMockUtils } from '@logto/shared/esm';
|
||||||
|
|
||||||
|
import { mockConnector } from '#src/__mocks__/connector.js';
|
||||||
import type { WithLogContext } from '#src/middleware/koa-audit-log.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 createMockContext from '#src/test-utils/jest-koa-mocks/create-mock-context.js';
|
||||||
import { createMockLogContext } from '#src/test-utils/koa-audit-log.js';
|
import { createMockLogContext } from '#src/test-utils/koa-audit-log.js';
|
||||||
|
@ -10,9 +11,10 @@ const { jest } = import.meta;
|
||||||
const { mockEsm } = createMockUtils(jest);
|
const { mockEsm } = createMockUtils(jest);
|
||||||
|
|
||||||
const getUserInfo = jest.fn().mockResolvedValue({ id: 'foo' });
|
const getUserInfo = jest.fn().mockResolvedValue({ id: 'foo' });
|
||||||
|
const getConnector = jest.fn().mockResolvedValue(mockConnector);
|
||||||
|
|
||||||
const tenant = new MockTenant(undefined, undefined, undefined, {
|
const tenant = new MockTenant(undefined, undefined, undefined, {
|
||||||
socials: { getUserInfo },
|
socials: { getUserInfo, getConnector },
|
||||||
});
|
});
|
||||||
|
|
||||||
mockEsm('#src/libraries/connector.js', () => ({
|
mockEsm('#src/libraries/connector.js', () => ({
|
||||||
|
@ -49,12 +51,19 @@ describe('verifySocialIdentity', () => {
|
||||||
// @ts-expect-error test mock context
|
// @ts-expect-error test mock context
|
||||||
cookies: { get: jest.fn().mockReturnValue('token') },
|
cookies: { get: jest.fn().mockReturnValue('token') },
|
||||||
};
|
};
|
||||||
const connectorId = GoogleConnector.factoryId;
|
|
||||||
|
getConnector.mockResolvedValueOnce({
|
||||||
|
...mockConnector,
|
||||||
|
metadata: {
|
||||||
|
...mockConnector.metadata,
|
||||||
|
id: GoogleConnector.factoryId,
|
||||||
|
},
|
||||||
|
});
|
||||||
const connectorData = { credential: 'credential' };
|
const connectorData = { credential: 'credential' };
|
||||||
|
|
||||||
await expect(verifySocialIdentity({ connectorId, connectorData }, ctx, tenant)).rejects.toThrow(
|
await expect(
|
||||||
'CSRF token mismatch.'
|
verifySocialIdentity({ connectorId: 'google', connectorData }, ctx, tenant)
|
||||||
);
|
).rejects.toThrow('CSRF token mismatch.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should verify Google One Tap verification', async () => {
|
it('should verify Google One Tap verification', async () => {
|
||||||
|
|
Loading…
Reference in a new issue