0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-31 22:51:25 -05:00

refactor(core): split mock.ts into __mocks__/*.ts (#510)

* chore(core,ui): coverage ignore src/__mocks__/

* chore(core): build excludes src/__mocks__/

* refactor(core): split mock.ts into __mocks__/*.ts
This commit is contained in:
IceHe.xyz 2022-04-08 17:47:09 +08:00 committed by GitHub
parent b055362d34
commit 5625b8838c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 506 additions and 504 deletions

View file

@ -12,6 +12,6 @@ module.exports = {
'^@/(.*)$': '<rootDir>/src/$1',
'^jose/(.*)$': '<rootDir>/node_modules/jose/dist/node/cjs/$1',
},
coveragePathIgnorePatterns: ['/node_modules/', '/build/'],
coveragePathIgnorePatterns: ['/node_modules/', '/build/', '/src/__mocks__/'],
coverageReporters: ['text-summary', 'lcov'],
};

View file

@ -0,0 +1,238 @@
import { Connector, ConnectorMetadata, ConnectorType } from '@logto/schemas';
export const mockConnectorList: Connector[] = [
{
id: 'connector_0',
type: ConnectorType.Email,
enabled: true,
config: {},
createdAt: 1_234_567_890_123,
},
{
id: 'connector_1',
type: ConnectorType.SMS,
enabled: true,
config: {},
createdAt: 1_234_567_890_234,
},
{
id: 'connector_2',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_345,
},
{
id: 'connector_3',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_456,
},
{
id: 'connector_4',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
{
id: 'connector_5',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
{
id: 'connector_6',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
];
export const mockConnectorInstanceList: Array<{
connector: Connector;
metadata: ConnectorMetadata;
}> = [
{
connector: {
id: 'connector_0',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_123,
},
metadata: {
id: 'connector_0',
type: ConnectorType.Social,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_1',
type: ConnectorType.SMS,
enabled: true,
config: {},
createdAt: 1_234_567_890_234,
},
metadata: {
id: 'connector_1',
type: ConnectorType.SMS,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_2',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_345,
},
metadata: {
id: 'connector_2',
type: ConnectorType.Social,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_3',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_456,
},
metadata: {
id: 'connector_3',
type: ConnectorType.Social,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_4',
type: ConnectorType.Email,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
metadata: {
id: 'connector_4',
type: ConnectorType.Email,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_5',
type: ConnectorType.SMS,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
metadata: {
id: 'connector_5',
type: ConnectorType.SMS,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_6',
type: ConnectorType.Email,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
metadata: {
id: 'connector_6',
type: ConnectorType.Email,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
];
export const mockAliyunDmConnectorInstance = {
connector: {
id: 'aliyun-dm',
enabled: true,
config: {},
createdAt: 1_646_382_233_333,
},
metadata: {
type: ConnectorType.Email,
},
};
export const mockAliyunSmsConnectorInstance = {
connector: {
id: 'aliyun-sms',
enabled: true,
config: {},
createdAt: 1_646_382_233_333,
},
metadata: {
type: ConnectorType.SMS,
},
};
export const mockFacebookConnectorInstance = {
connector: {
id: 'facebook',
enabled: true,
config: {},
createdAt: 1_646_382_233_333,
},
metadata: {
type: ConnectorType.Social,
},
};
export const mockGithubConnectorInstance = {
connector: {
id: 'github',
enabled: true,
config: {},
createdAt: 1_646_382_233_000,
},
metadata: {
type: ConnectorType.Social,
},
};
export const mockGoogleConnectorInstance = {
connector: {
id: 'google',
enabled: false,
config: {},
createdAt: 1_646_382_233_000,
},
metadata: {
type: ConnectorType.Social,
},
};

View file

@ -0,0 +1,70 @@
import {
Application,
ApplicationType,
Passcode,
PasscodeType,
Resource,
Role,
Setting,
UserLog,
UserLogResult,
UserLogType,
} from '@logto/schemas';
export * from './connector';
export * from './sign-in-experience';
export * from './user';
export const mockApplication: Application = {
id: 'foo',
name: 'foo',
type: ApplicationType.SPA,
description: null,
oidcClientMetadata: {
redirectUris: [],
postLogoutRedirectUris: [],
},
customClientMetadata: {},
createdAt: 1_645_334_775_356,
};
export const mockResource: Resource = {
id: 'logto_api',
name: 'management api',
indicator: 'logto.dev/api',
accessTokenTtl: 3600,
};
export const mockRole: Role = {
name: 'admin',
description: 'admin',
};
export const mockSetting: Setting = {
id: 'foo setting',
customDomain: 'mock-logto.dev',
adminConsole: {
applicationSkipGetStarted: false,
},
};
export const mockPasscode: Passcode = {
id: 'foo',
interactionJti: 'jti',
phone: '888 888 8888',
email: 'foo@logto.io',
type: PasscodeType.SignIn,
code: 'asdfghjkl',
consumed: false,
tryCount: 2,
createdAt: 10,
};
export const mockUserLog: UserLog = {
id: 'foo',
userId: 'foo',
type: UserLogType.RegisterEmail,
result: UserLogResult.Success,
payload: {},
createdAt: 10,
};

View file

@ -0,0 +1,69 @@
import {
Branding,
BrandingStyle,
Language,
LanguageInfo,
SignInExperience,
SignInMethods,
SignInMethodState,
TermsOfUse,
} from '@logto/schemas';
export const mockSignInExperience: SignInExperience = {
id: 'foo',
branding: {
primaryColor: '#000',
backgroundColor: '#fff',
darkMode: true,
darkBackgroundColor: '#000',
darkPrimaryColor: '#fff',
style: BrandingStyle.Logo,
logoUrl: 'http://logto.png',
slogan: 'logto',
},
termsOfUse: {
enabled: false,
},
forgetPasswordEnabled: true,
languageInfo: {
autoDetect: true,
fallbackLanguage: Language.english,
fixedLanguage: Language.chinese,
},
signInMethods: {
username: SignInMethodState.primary,
email: SignInMethodState.disabled,
sms: SignInMethodState.disabled,
social: SignInMethodState.secondary,
},
socialSignInConnectorIds: ['github', 'facebook'],
};
export const mockBranding: Branding = {
primaryColor: '#000',
backgroundColor: '#fff',
darkMode: true,
darkBackgroundColor: '#000',
darkPrimaryColor: '#fff',
style: BrandingStyle.Logo_Slogan,
logoUrl: 'http://silverhand.png',
slogan: 'Silverhand.',
};
export const mockTermsOfUse: TermsOfUse = {
enabled: true,
contentUrl: 'http://silverhand.com/terms',
};
export const mockLanguageInfo: LanguageInfo = {
autoDetect: true,
fallbackLanguage: Language.english,
fixedLanguage: Language.chinese,
};
export const mockSignInMethods: SignInMethods = {
username: SignInMethodState.primary,
email: SignInMethodState.disabled,
sms: SignInMethodState.disabled,
social: SignInMethodState.disabled,
};

View file

@ -0,0 +1,96 @@
import { User, userInfoSelectFields } from '@logto/schemas';
import pick from 'lodash.pick';
export const mockUser: User = {
id: 'foo',
username: 'foo',
primaryEmail: 'foo@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {
connector1: { userId: 'connector1', details: {} },
},
customData: {},
};
export const mockUserResponse = pick(mockUser, ...userInfoSelectFields);
export const mockUserList: User[] = [
{
id: '1',
username: 'foo1',
primaryEmail: 'foo1@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
{
id: '2',
username: 'foo2',
primaryEmail: 'foo2@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
{
id: '3',
username: 'foo3',
primaryEmail: 'foo3@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
{
id: '4',
username: 'bar1',
primaryEmail: 'bar1@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
{
id: '5',
username: 'bar2',
primaryEmail: 'bar2@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
];
export const mockUserListResponse = mockUserList.map((user) => pick(user, ...userInfoSelectFields));

View file

@ -1,5 +1,12 @@
import { BrandingStyle, SignInMethodState, ConnectorType } from '@logto/schemas';
import {
mockAliyunDmConnectorInstance,
mockFacebookConnectorInstance,
mockGithubConnectorInstance,
mockBranding,
mockSignInMethods,
} from '@/__mocks__';
import { ConnectorInstance } from '@/connectors/types';
import RequestError from '@/errors/RequestError';
import {
@ -8,13 +15,6 @@ import {
validateSignInMethods,
validateTermsOfUse,
} from '@/lib/sign-in-experience';
import {
mockAliyunDmConnectorInstance,
mockBranding,
mockFacebookConnectorInstance,
mockGithubConnectorInstance,
mockSignInMethods,
} from '@/utils/mock';
const enabledConnectorInstances = [mockFacebookConnectorInstance, mockGithubConnectorInstance];

View file

@ -1,8 +1,8 @@
import { UserRole } from '@logto/schemas';
import { Context } from 'koa';
import { mockUser } from '@/__mocks__';
import RequestError from '@/errors/RequestError';
import { mockUser } from '@/utils/mock';
import { createContextWithRouteParameters } from '@/utils/test-utils';
import { WithAuthContext } from './koa-auth';

View file

@ -1,6 +1,6 @@
import { mockUser, mockUserResponse } from '@/__mocks__';
import RequestError from '@/errors/RequestError';
import * as userQueries from '@/queries/user';
import { mockUser, mockUserResponse } from '@/utils/mock';
import { createContextWithRouteParameters } from '@/utils/test-utils';
import koaUserInfo from './koa-user-info';

View file

@ -1,6 +1,7 @@
import { Application } from '@logto/schemas';
import snakecaseKeys from 'snakecase-keys';
import { mockApplication } from '@/__mocks__';
import {
consumeInstanceById,
destroyInstanceById,
@ -9,7 +10,6 @@ import {
revokeInstanceByGrantId,
upsertInstance,
} from '@/queries/oidc-model-instance';
import { mockApplication } from '@/utils/mock';
import postgresAdapter from './adapter';
import { getApplicationTypeString } from './utils';

View file

@ -2,13 +2,13 @@ import { Applications } from '@logto/schemas';
import { createMockPool, createMockQueryResult, sql } from 'slonik';
import { snakeCase } from 'snake-case';
import { mockApplication } from '@/__mocks__';
import {
convertToIdentifiers,
convertToPrimitiveOrSql,
excludeAutoSetFields,
} from '@/database/utils';
import { DeletionError } from '@/errors/SlonikError';
import { mockApplication } from '@/utils/mock';
import { expectSqlAssert, QueryType } from '@/utils/test-utils';
import {

View file

@ -2,13 +2,13 @@ import { Passcodes, PasscodeType } from '@logto/schemas';
import { createMockPool, createMockQueryResult, sql } from 'slonik';
import { snakeCase } from 'snake-case';
import { mockPasscode } from '@/__mocks__';
import {
convertToIdentifiers,
convertToPrimitiveOrSql,
excludeAutoSetFields,
} from '@/database/utils';
import { DeletionError } from '@/errors/SlonikError';
import { mockPasscode } from '@/utils/mock';
import { expectSqlAssert, QueryType } from '@/utils/test-utils';
import {

View file

@ -1,9 +1,9 @@
import { Resources } from '@logto/schemas';
import { createMockPool, createMockQueryResult, sql } from 'slonik';
import { mockResource } from '@/__mocks__';
import { convertToIdentifiers, convertToPrimitiveOrSql } from '@/database/utils';
import { DeletionError } from '@/errors/SlonikError';
import { mockResource } from '@/utils/mock';
import { expectSqlAssert, QueryType } from '@/utils/test-utils';
import {

View file

@ -1,8 +1,8 @@
import { Roles } from '@logto/schemas';
import { createMockPool, createMockQueryResult, sql } from 'slonik';
import { mockRole } from '@/__mocks__';
import { convertToIdentifiers } from '@/database/utils';
import { mockRole } from '@/utils/mock';
import { expectSqlAssert, QueryType } from '@/utils/test-utils';
import { findAllRoles, findRolesByRoleNames } from './roles';

View file

@ -1,8 +1,8 @@
import { Settings } from '@logto/schemas';
import { createMockPool, createMockQueryResult, sql } from 'slonik';
import { mockSetting } from '@/__mocks__';
import { convertToIdentifiers } from '@/database/utils';
import { mockSetting } from '@/utils/mock';
import { expectSqlAssert, QueryType } from '@/utils/test-utils';
import { defaultSettingId, getSetting, updateSetting } from './setting';

View file

@ -1,6 +1,6 @@
import { createMockPool, createMockQueryResult } from 'slonik';
import { mockSignInExperience } from '@/utils/mock';
import { mockSignInExperience } from '@/__mocks__';
import { expectSqlAssert, QueryType } from '@/utils/test-utils';
import { findDefaultSignInExperience, updateDefaultSignInExperience } from './sign-in-experience';

View file

@ -2,12 +2,12 @@ import { UserLogs } from '@logto/schemas';
import { createMockPool, createMockQueryResult, sql } from 'slonik';
import { snakeCase } from 'snake-case';
import { mockUserLog } from '@/__mocks__';
import {
convertToIdentifiers,
excludeAutoSetFields,
convertToPrimitiveOrSql,
} from '@/database/utils';
import { mockUserLog } from '@/utils/mock';
import { expectSqlAssert, QueryType } from '@/utils/test-utils';
import { insertUserLog, findLogsByUserId } from './user-log';

View file

@ -1,9 +1,9 @@
import { Users } from '@logto/schemas';
import { createMockPool, createMockQueryResult, sql } from 'slonik';
import { mockUser } from '@/__mocks__';
import { convertToIdentifiers, convertToPrimitiveOrSql } from '@/database/utils';
import { DeletionError } from '@/errors/SlonikError';
import { mockUser } from '@/utils/mock';
import { expectSqlAssert, QueryType } from '@/utils/test-utils';
import {

View file

@ -1,6 +1,7 @@
import { CreateUser, Role, User, userInfoSelectFields } from '@logto/schemas';
import pick from 'lodash.pick';
import { mockUser, mockUserList, mockUserListResponse, mockUserResponse } from '@/__mocks__';
import { encryptUserPassword } from '@/lib/user';
import { findRolesByRoleNames } from '@/queries/roles';
import {
@ -11,7 +12,6 @@ import {
deleteUserById,
clearUserCustomDataById,
} from '@/queries/user';
import { mockUser, mockUserList, mockUserListResponse, mockUserResponse } from '@/utils/mock';
import { createRequester } from '@/utils/test-utils';
import adminUserRoutes from './admin-user';

View file

@ -1,7 +1,7 @@
import { Application, CreateApplication, ApplicationType } from '@logto/schemas';
import { mockApplication } from '@/__mocks__';
import { findApplicationById } from '@/queries/application';
import { mockApplication } from '@/utils/mock';
import { createRequester } from '@/utils/test-utils';
import applicationRoutes from './application';

View file

@ -1,6 +1,7 @@
/* eslint-disable max-lines */
import { Connector, ConnectorType } from '@logto/schemas';
import { mockConnectorInstanceList, mockConnectorList } from '@/__mocks__';
import {
ConnectorError,
ConnectorErrorCodes,
@ -13,7 +14,6 @@ import {
import RequestError from '@/errors/RequestError';
import { updateConnector } from '@/queries/connector';
import assertThat from '@/utils/assert-that';
import { mockConnectorList, mockConnectorInstanceList } from '@/utils/mock';
import { createRequester } from '@/utils/test-utils';
import connectorRoutes from './connector';

View file

@ -1,6 +1,6 @@
import { Resource, CreateResource } from '@logto/schemas';
import { mockResource } from '@/utils/mock';
import { mockResource } from '@/__mocks__';
import { createRequester } from '@/utils/test-utils';
import resourceRoutes from './resource';

View file

@ -1,6 +1,6 @@
import { Role } from '@logto/schemas';
import { mockRole } from '@/utils/mock';
import { mockRole } from '@/__mocks__';
import { createRequester } from '@/utils/test-utils';
import roleRoutes from './role';

View file

@ -1,6 +1,6 @@
import { Setting, CreateSetting } from '@logto/schemas';
import { mockSetting } from '@/utils/mock';
import { mockSetting } from '@/__mocks__';
import { createRequester } from '@/utils/test-utils';
import settingRoutes from './setting';

View file

@ -1,6 +1,6 @@
import { BrandingStyle, CreateSignInExperience, SignInExperience } from '@logto/schemas';
import { mockBranding, mockSignInExperience } from '@/utils/mock';
import { mockBranding, mockSignInExperience } from '@/__mocks__';
import { createRequester } from '@/utils/test-utils';
import signInExperiencesRoutes from './sign-in-experience';

View file

@ -15,7 +15,7 @@ import {
mockSignInExperience,
mockSignInMethods,
mockTermsOfUse,
} from '@/utils/mock';
} from '@/__mocks__';
import { createRequester } from '@/utils/test-utils';
import signInExperiencesRoutes from './sign-in-experience';

View file

@ -5,15 +5,15 @@ import {
SignInMethodState,
} from '@logto/schemas';
import * as signInExpLib from '@/lib/sign-in-experience';
import {
mockBranding,
mockFacebookConnectorInstance,
mockGithubConnectorInstance,
mockGoogleConnectorInstance,
mockBranding,
mockSignInExperience,
mockSignInMethods,
} from '@/utils/mock';
} from '@/__mocks__';
import * as signInExpLib from '@/lib/sign-in-experience';
import { createRequester } from '@/utils/test-utils';
import signInExperiencesRoutes from './sign-in-experience';

View file

@ -1,472 +0,0 @@
/* eslint-disable max-lines */
import {
User,
userInfoSelectFields,
Application,
ApplicationType,
Resource,
Role,
Setting,
SignInExperience,
BrandingStyle,
Language,
Connector,
ConnectorMetadata,
Passcode,
PasscodeType,
UserLog,
UserLogType,
UserLogResult,
ConnectorType,
SignInMethodState,
Branding,
SignInMethods,
TermsOfUse,
LanguageInfo,
} from '@logto/schemas';
import pick from 'lodash.pick';
export const mockUser: User = {
id: 'foo',
username: 'foo',
primaryEmail: 'foo@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {
connector1: { userId: 'connector1', details: {} },
},
customData: {},
};
export const mockUserResponse = pick(mockUser, ...userInfoSelectFields);
export const mockUserList: User[] = [
{
id: '1',
username: 'foo1',
primaryEmail: 'foo1@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
{
id: '2',
username: 'foo2',
primaryEmail: 'foo2@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
{
id: '3',
username: 'foo3',
primaryEmail: 'foo3@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
{
id: '4',
username: 'bar1',
primaryEmail: 'bar1@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
{
id: '5',
username: 'bar2',
primaryEmail: 'bar2@logto.io',
primaryPhone: '111111',
roleNames: ['admin'],
passwordEncrypted: null,
passwordEncryptionMethod: null,
passwordEncryptionSalt: null,
name: null,
avatar: null,
identities: {},
customData: {},
},
];
export const mockUserListResponse = mockUserList.map((user) => pick(user, ...userInfoSelectFields));
export const mockApplication: Application = {
id: 'foo',
name: 'foo',
type: ApplicationType.SPA,
description: null,
oidcClientMetadata: {
redirectUris: [],
postLogoutRedirectUris: [],
},
customClientMetadata: {},
createdAt: 1_645_334_775_356,
};
export const mockResource: Resource = {
id: 'logto_api',
name: 'management api',
indicator: 'logto.dev/api',
accessTokenTtl: 3600,
};
export const mockRole: Role = {
name: 'admin',
description: 'admin',
};
export const mockSetting: Setting = {
id: 'foo setting',
customDomain: 'mock-logto.dev',
adminConsole: {
applicationSkipGetStarted: false,
},
};
export const mockSignInExperience: SignInExperience = {
id: 'foo',
branding: {
primaryColor: '#000',
backgroundColor: '#fff',
darkMode: true,
darkBackgroundColor: '#000',
darkPrimaryColor: '#fff',
style: BrandingStyle.Logo,
logoUrl: 'http://logto.png',
slogan: 'logto',
},
termsOfUse: {
enabled: false,
},
forgetPasswordEnabled: true,
languageInfo: {
autoDetect: true,
fallbackLanguage: Language.english,
fixedLanguage: Language.chinese,
},
signInMethods: {
username: SignInMethodState.primary,
email: SignInMethodState.disabled,
sms: SignInMethodState.disabled,
social: SignInMethodState.secondary,
},
socialSignInConnectorIds: ['github', 'facebook'],
};
export const mockConnectorList: Connector[] = [
{
id: 'connector_0',
type: ConnectorType.Email,
enabled: true,
config: {},
createdAt: 1_234_567_890_123,
},
{
id: 'connector_1',
type: ConnectorType.SMS,
enabled: true,
config: {},
createdAt: 1_234_567_890_234,
},
{
id: 'connector_2',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_345,
},
{
id: 'connector_3',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_456,
},
{
id: 'connector_4',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
{
id: 'connector_5',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
{
id: 'connector_6',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
];
export const mockConnectorInstanceList: Array<{
connector: Connector;
metadata: ConnectorMetadata;
}> = [
{
connector: {
id: 'connector_0',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_123,
},
metadata: {
id: 'connector_0',
type: ConnectorType.Social,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_1',
type: ConnectorType.SMS,
enabled: true,
config: {},
createdAt: 1_234_567_890_234,
},
metadata: {
id: 'connector_1',
type: ConnectorType.SMS,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_2',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_345,
},
metadata: {
id: 'connector_2',
type: ConnectorType.Social,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_3',
type: ConnectorType.Social,
enabled: true,
config: {},
createdAt: 1_234_567_890_456,
},
metadata: {
id: 'connector_3',
type: ConnectorType.Social,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_4',
type: ConnectorType.Email,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
metadata: {
id: 'connector_4',
type: ConnectorType.Email,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_5',
type: ConnectorType.SMS,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
metadata: {
id: 'connector_5',
type: ConnectorType.SMS,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
{
connector: {
id: 'connector_6',
type: ConnectorType.Email,
enabled: true,
config: {},
createdAt: 1_234_567_890_567,
},
metadata: {
id: 'connector_6',
type: ConnectorType.Email,
name: {},
logo: './logo.png',
description: {},
readme: 'README.md',
},
},
];
export const mockPasscode: Passcode = {
id: 'foo',
interactionJti: 'jti',
phone: '888 888 8888',
email: 'foo@logto.io',
type: PasscodeType.SignIn,
code: 'asdfghjkl',
consumed: false,
tryCount: 2,
createdAt: 10,
};
export const mockUserLog: UserLog = {
id: 'foo',
userId: 'foo',
type: UserLogType.RegisterEmail,
result: UserLogResult.Success,
payload: {},
createdAt: 10,
};
export const mockBranding: Branding = {
primaryColor: '#000',
backgroundColor: '#fff',
darkMode: true,
darkBackgroundColor: '#000',
darkPrimaryColor: '#fff',
style: BrandingStyle.Logo_Slogan,
logoUrl: 'http://silverhand.png',
slogan: 'Silverhand.',
};
export const mockTermsOfUse: TermsOfUse = {
enabled: true,
contentUrl: 'http://silverhand.com/terms',
};
export const mockLanguageInfo: LanguageInfo = {
autoDetect: true,
fallbackLanguage: Language.english,
fixedLanguage: Language.chinese,
};
export const mockSignInMethods: SignInMethods = {
username: SignInMethodState.primary,
email: SignInMethodState.disabled,
sms: SignInMethodState.disabled,
social: SignInMethodState.disabled,
};
export const mockAliyunDmConnectorInstance = {
connector: {
id: 'aliyun-dm',
enabled: true,
config: {},
createdAt: 1_646_382_233_333,
},
metadata: {
type: ConnectorType.Email,
},
};
export const mockAliyunSmsConnectorInstance = {
connector: {
id: 'aliyun-sms',
enabled: true,
config: {},
createdAt: 1_646_382_233_333,
},
metadata: {
type: ConnectorType.SMS,
},
};
export const mockFacebookConnectorInstance = {
connector: {
id: 'facebook',
enabled: true,
config: {},
createdAt: 1_646_382_233_333,
},
metadata: {
type: ConnectorType.Social,
},
};
export const mockGithubConnectorInstance = {
connector: {
id: 'github',
enabled: true,
config: {},
createdAt: 1_646_382_233_000,
},
metadata: {
type: ConnectorType.Social,
},
};
export const mockGoogleConnectorInstance = {
connector: {
id: 'google',
enabled: false,
config: {},
createdAt: 1_646_382_233_000,
},
metadata: {
type: ConnectorType.Social,
},
};
/* eslint-enable max-lines */

View file

@ -4,6 +4,7 @@
"src"
],
"exclude": [
"src/**/*.test.ts"
"src/**/*.test.ts",
"src/__mocks__/",
]
}

View file

@ -18,7 +18,7 @@ const config: Config.InitialOptions = {
'\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
},
setupFilesAfterEnv: ['<rootDir>/src/jest.setup.ts'],
coveragePathIgnorePatterns: ['/node_modules/', '/dist/'],
coveragePathIgnorePatterns: ['/node_modules/', '/dist/', '/src/__mocks__/'],
coverageReporters: ['text-summary', 'lcov'],
globals: {
'ts-jest': {