0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

refactor: fix integration tests and import order

This commit is contained in:
Darcy Ye 2022-11-28 18:25:47 +08:00
parent c3a361c437
commit 356aeabb54
No known key found for this signature in database
GPG key ID: B46F4C07EDEFC610
5 changed files with 20 additions and 25 deletions

View file

@ -3,6 +3,17 @@ import { MessageTypes } from '@logto/connector-kit';
import { ConnectorType } from '@logto/schemas';
import { any } from 'zod';
import {
mockMetadata,
mockMetadata0,
mockMetadata1,
mockMetadata2,
mockMetadata3,
mockConnector,
mockConnectorFactory,
mockLogtoConnectorList,
mockLogtoConnector,
} from '#src/__mocks__/index.js';
import { defaultConnectorMethods } from '#src/connectors/consts.js';
import type { ConnectorFactory, LogtoConnector } from '#src/connectors/types.js';
import RequestError from '#src/errors/RequestError/index.js';
@ -18,18 +29,6 @@ import { createRequester } from '#src/utils/test-utils.js';
import connectorRoutes from './connector.js';
import {
mockMetadata,
mockMetadata0,
mockMetadata1,
mockMetadata2,
mockMetadata3,
mockConnector,
mockConnectorFactory,
mockLogtoConnectorList,
mockLogtoConnector,
} from '#src/__mocks__/index.js';
const loadConnectorFactoriesPlaceHolder = jest.fn() as jest.MockedFunction<
() => Promise<ConnectorFactory[]>
>;

View file

@ -7,6 +7,7 @@ import { createRequester } from '#src/utils/test-utils.js';
import interactionRoutes, { verificationPrefix } from './index.js';
import { sendPasscodeToIdentifier } from './utils/passcode-validation.js';
// FIXME @Darcy: no more `enabled` for `connectors` table
const getLogtoConnectorByIdHelper = jest.fn(async (connectorId: string) => {
const database = {
enabled: connectorId === 'social_enabled',
@ -124,15 +125,6 @@ describe('session -> interactionRoutes', () => {
expect(response.statusCode).toEqual(400);
});
it('throw error when connector is disabled', async () => {
const response = await sessionRequest.post(path).send({
connectorId: 'social_disabled',
state: 'state',
redirectUri: 'https://logto.dev',
});
expect(response.statusCode).toEqual(400);
});
it('throw error when no social connector is found', async () => {
const response = await sessionRequest.post(path).send({
connectorId: 'others',

View file

@ -10,9 +10,6 @@ jest.mock('#src/lib/social.js', () => ({
jest.mock('#src/connectors.js', () => ({
getLogtoConnectorById: jest.fn().mockResolvedValue({
dbEntry: {
enabled: true,
},
metadata: {
id: 'social',
},

View file

@ -15,7 +15,6 @@ export const createSocialAuthorizationUrl = async (payload: SocialAuthorizationU
const connector = await getLogtoConnectorById(connectorId);
assertThat(connector.dbEntry.enabled, 'connector.not_enabled');
assertThat(connector.type === ConnectorType.Social, 'connector.unexpected_type');
return connector.getAuthorizationUri({ state, redirectUri });

View file

@ -26,6 +26,14 @@ const connectorIdMap = new Map();
* for testing updating configs and enabling/disabling for now.
*/
test('connector set-up flow', async () => {
const connectors = await listConnectors();
await Promise.all(
connectors.map(async ({ id }) => {
await deleteConnectorById(id);
})
);
connectorIdMap.clear();
/*
* Set up social/SMS/email connectors
*/