From f7bc349e03ce60a0aaa970936c78faf889137d33 Mon Sep 17 00:00:00 2001 From: "IceHe.life" Date: Tue, 26 Jul 2022 16:12:34 +0800 Subject: [PATCH] test: add connector-mock-sms and connector-mock-email for integration tests (#1668) --- .github/workflows/integration-test.yml | 9 ++- package.sh | 11 ++- packages/connector-mock-mail/README.md | 3 + .../docs/config-template.json | 25 ++++++ packages/connector-mock-mail/logo.svg | 7 ++ packages/connector-mock-mail/package.json | 47 ++++++++++++ packages/connector-mock-mail/src/constant.ts | 20 +++++ packages/connector-mock-mail/src/index.ts | 76 +++++++++++++++++++ packages/connector-mock-mail/src/types.ts | 22 ++++++ .../connector-mock-mail/tsconfig.base.json | 10 +++ .../connector-mock-mail/tsconfig.build.json | 4 + packages/connector-mock-mail/tsconfig.json | 7 ++ packages/connector-mock-sms/README.md | 3 + .../docs/config-template.json | 19 +++++ packages/connector-mock-sms/logo.svg | 3 + packages/connector-mock-sms/package.json | 47 ++++++++++++ packages/connector-mock-sms/src/constant.ts | 20 +++++ packages/connector-mock-sms/src/index.ts | 76 +++++++++++++++++++ packages/connector-mock-sms/src/types.ts | 15 ++++ .../connector-mock-sms/tsconfig.base.json | 10 +++ .../connector-mock-sms/tsconfig.build.json | 4 + packages/connector-mock-sms/tsconfig.json | 7 ++ .../integration-tests/src/connectors-mock.ts | 48 ++++++++++++ .../tests/connectors.test.ts | 54 ++++++------- pnpm-lock.yaml | 58 ++++++++++++++ 25 files changed, 574 insertions(+), 31 deletions(-) create mode 100644 packages/connector-mock-mail/README.md create mode 100644 packages/connector-mock-mail/docs/config-template.json create mode 100644 packages/connector-mock-mail/logo.svg create mode 100644 packages/connector-mock-mail/package.json create mode 100644 packages/connector-mock-mail/src/constant.ts create mode 100644 packages/connector-mock-mail/src/index.ts create mode 100644 packages/connector-mock-mail/src/types.ts create mode 100644 packages/connector-mock-mail/tsconfig.base.json create mode 100644 packages/connector-mock-mail/tsconfig.build.json create mode 100644 packages/connector-mock-mail/tsconfig.json create mode 100644 packages/connector-mock-sms/README.md create mode 100644 packages/connector-mock-sms/docs/config-template.json create mode 100644 packages/connector-mock-sms/logo.svg create mode 100644 packages/connector-mock-sms/package.json create mode 100644 packages/connector-mock-sms/src/constant.ts create mode 100644 packages/connector-mock-sms/src/index.ts create mode 100644 packages/connector-mock-sms/src/types.ts create mode 100644 packages/connector-mock-sms/tsconfig.base.json create mode 100644 packages/connector-mock-sms/tsconfig.build.json create mode 100644 packages/connector-mock-sms/tsconfig.json diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 601b43778..425a6d224 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -7,7 +7,7 @@ on: - 'push-action/**' pull_request: -concurrency: +concurrency: group: integration-test-${{ github.head_ref || github.run_id }} cancel-in-progress: true @@ -23,20 +23,22 @@ jobs: - name: Package run: ./package.sh + env: + INTEGRATION_TEST: true - uses: actions/upload-artifact@v3 with: name: integration-test-${{ github.sha }} path: /tmp/logto.tar.gz retention-days: 3 - + run-logto: needs: package strategy: matrix: os: [ubuntu-latest, macos-12] - + runs-on: ${{ matrix.os }} steps: @@ -93,6 +95,7 @@ jobs: INTEGRATION_TEST: true NODE_ENV: production DB_URL_DEFAULT: postgres://postgres:postgres@localhost:5432 + ADDITIONAL_CONNECTOR_PACKAGES: '@logto/connector-mock-sms,@logto/connector-mock-email' - name: Sleep for 5 seconds run: sleep 5 diff --git a/package.sh b/package.sh index 05580352e..92d84a88c 100755 --- a/package.sh +++ b/package.sh @@ -7,7 +7,16 @@ echo Prune dependencies rm -rf node_modules packages/*/node_modules echo Install production dependencies -NODE_ENV=production pnpm i +if [[ $INTEGRATION_TEST =~ ^(true|1)$ ]]; then + echo Install the mock connectors for integration tests only + cd packages/core + pnpm link @logto/connector-mock-sms + pnpm link @logto/connector-mock-email + cd - + NODE_ENV=production pnpm i --no-frozen-lockfile +else + NODE_ENV=production pnpm i +fi echo Prune files rm -rf \ diff --git a/packages/connector-mock-mail/README.md b/packages/connector-mock-mail/README.md new file mode 100644 index 000000000..9667a0ba7 --- /dev/null +++ b/packages/connector-mock-mail/README.md @@ -0,0 +1,3 @@ +# Mock mail connector + +For integration tests only. diff --git a/packages/connector-mock-mail/docs/config-template.json b/packages/connector-mock-mail/docs/config-template.json new file mode 100644 index 000000000..143c62002 --- /dev/null +++ b/packages/connector-mock-mail/docs/config-template.json @@ -0,0 +1,25 @@ +{ + "apiKey": "", + "fromEmail": "", + "fromName": "", + "templates": [ + { + "usageType": "SignIn", + "type": "text/plain", + "subject": "Logto SignIn Template", + "content": "This is for sign-in purposes only. Your passcode is {{code}}." + }, + { + "usageType": "Register", + "type": "text/plain", + "subject": "Logto Register Template", + "content": "This is for registering purposes only. Your passcode is {{code}}." + }, + { + "usageType": "Test", + "type": "text/plain", + "subject": "Logto Test Template", + "content": "This is for testing purposes only. Your passcode is {{code}}." + } + ] +} diff --git a/packages/connector-mock-mail/logo.svg b/packages/connector-mock-mail/logo.svg new file mode 100644 index 000000000..7bb95cfe2 --- /dev/null +++ b/packages/connector-mock-mail/logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/packages/connector-mock-mail/package.json b/packages/connector-mock-mail/package.json new file mode 100644 index 000000000..4b6dd7970 --- /dev/null +++ b/packages/connector-mock-mail/package.json @@ -0,0 +1,47 @@ +{ + "name": "@logto/connector-mock-email", + "version": "1.0.0-beta.1", + "description": "Mock Email Service connector implementation for integration tests only.", + "main": "./lib/index.js", + "exports": "./lib/index.js", + "author": "Silverhand Inc. ", + "license": "MPL-2.0", + "private": true, + "files": [ + "lib", + "docs", + "logo.svg", + "README.md" + ], + "scripts": { + "precommit": "lint-staged", + "build": "rm -rf lib/ && tsc -p tsconfig.build.json", + "lint": "eslint --ext .ts src", + "lint:report": "pnpm lint --format json --output-file report.json", + "dev": "rm -rf lib/ && tsc-watch -p tsconfig.build.json --preserveWatchOutput --onSuccess \"node ./lib/index.js\"", + "prepack": "pnpm build" + }, + "dependencies": { + "@logto/connector-types": "^1.0.0-beta.1", + "@logto/shared": "^1.0.0-beta.1", + "@silverhand/essentials": "^1.1.6", + "zod": "^3.14.3" + }, + "devDependencies": { + "@silverhand/eslint-config": "^0.17.0", + "@silverhand/ts-config": "^0.17.0", + "@types/node": "^16.3.1", + "eslint": "^8.19.0", + "lint-staged": "^13.0.0", + "prettier": "^2.3.2", + "tsc-watch": "^5.0.0", + "typescript": "^4.6.2" + }, + "engines": { + "node": "^16.0.0" + }, + "eslintConfig": { + "extends": "@silverhand" + }, + "prettier": "@silverhand/eslint-config/.prettierrc" +} diff --git a/packages/connector-mock-mail/src/constant.ts b/packages/connector-mock-mail/src/constant.ts new file mode 100644 index 000000000..a47877cd8 --- /dev/null +++ b/packages/connector-mock-mail/src/constant.ts @@ -0,0 +1,20 @@ +import { ConnectorType, ConnectorMetadata } from '@logto/connector-types'; + +export const defaultMetadata: ConnectorMetadata = { + id: 'mock-email-service', + target: 'mock-mail', + type: ConnectorType.Email, + platform: null, + name: { + en: 'Mock Mail Service', + 'zh-CN': 'Mock 邮件服务', + }, + logo: './logo.svg', + logoDark: null, + description: { + en: 'The description of Mock SMS Service.', + 'zh-CN': 'Mock 邮件服务的描述。', + }, + readme: './README.md', + configTemplate: './docs/config-template.json', +}; diff --git a/packages/connector-mock-mail/src/index.ts b/packages/connector-mock-mail/src/index.ts new file mode 100644 index 000000000..717507195 --- /dev/null +++ b/packages/connector-mock-mail/src/index.ts @@ -0,0 +1,76 @@ +import { + ConnectorError, + ConnectorErrorCodes, + ConnectorMetadata, + Connector, + EmailSendMessageFunction, + EmailSendTestMessageFunction, + EmailConnectorInstance, + GetConnectorConfig, + EmailMessageTypes, +} from '@logto/connector-types'; +import { assert } from '@silverhand/essentials'; + +import { defaultMetadata } from './constant'; +import { mockMailConfigGuard, MockMailConfig } from './types'; + +export default class MockMailConnector implements EmailConnectorInstance { + public metadata: ConnectorMetadata = defaultMetadata; + private _connector?: Connector; + + public get connector() { + if (!this._connector) { + throw new ConnectorError(ConnectorErrorCodes.General); + } + + return this._connector; + } + + public set connector(input: Connector) { + this._connector = input; + } + + constructor(public readonly getConfig: GetConnectorConfig) {} + + public validateConfig(config: unknown): asserts config is MockMailConfig { + const result = mockMailConfigGuard.safeParse(config); + + if (!result.success) { + throw new ConnectorError(ConnectorErrorCodes.InvalidConfig, result.error); + } + } + + public sendMessage: EmailSendMessageFunction = async (address, type, data) => { + const config = await this.getConfig(this.metadata.id); + + this.validateConfig(config); + + return this.sendMessageBy(config, address, type, data); + }; + + public sendTestMessage: EmailSendTestMessageFunction = async (config, address, type, data) => { + this.validateConfig(config); + + return this.sendMessageBy(config, address, type, data); + }; + + private readonly sendMessageBy = async ( + config: MockMailConfig, + address: string, + type: keyof EmailMessageTypes, + data: EmailMessageTypes[typeof type] + ) => { + const { templates } = config; + const template = templates.find((template) => template.usageType === type); + + assert( + template, + new ConnectorError( + ConnectorErrorCodes.TemplateNotFound, + `Template not found for type: ${type}` + ) + ); + + return { address, data }; + }; +} diff --git a/packages/connector-mock-mail/src/types.ts b/packages/connector-mock-mail/src/types.ts new file mode 100644 index 000000000..c72ac0d4c --- /dev/null +++ b/packages/connector-mock-mail/src/types.ts @@ -0,0 +1,22 @@ +import { z } from 'zod'; + +export enum ContextType { + Text = 'text/plain', + Html = 'text/html', +} + +const templateGuard = z.object({ + usageType: z.string(), + type: z.nativeEnum(ContextType), + subject: z.string(), + content: z.string(), // With variable {{code}}, support HTML +}); + +export const mockMailConfigGuard = z.object({ + apiKey: z.string(), + fromEmail: z.string(), + fromName: z.string().optional(), + templates: z.array(templateGuard), +}); + +export type MockMailConfig = z.infer; diff --git a/packages/connector-mock-mail/tsconfig.base.json b/packages/connector-mock-mail/tsconfig.base.json new file mode 100644 index 000000000..848a915f7 --- /dev/null +++ b/packages/connector-mock-mail/tsconfig.base.json @@ -0,0 +1,10 @@ +{ + "extends": "@silverhand/ts-config/tsconfig.base", + "compilerOptions": { + "outDir": "lib", + "baseUrl": ".", + "paths": { + "@/*": ["src/*"] + } + } +} diff --git a/packages/connector-mock-mail/tsconfig.build.json b/packages/connector-mock-mail/tsconfig.build.json new file mode 100644 index 000000000..a07f6b0e4 --- /dev/null +++ b/packages/connector-mock-mail/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.base", + "include": ["src"] +} diff --git a/packages/connector-mock-mail/tsconfig.json b/packages/connector-mock-mail/tsconfig.json new file mode 100644 index 000000000..93d1196d5 --- /dev/null +++ b/packages/connector-mock-mail/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.base", + "compilerOptions": { + "types": ["node"] + }, + "include": ["src"] +} diff --git a/packages/connector-mock-sms/README.md b/packages/connector-mock-sms/README.md new file mode 100644 index 000000000..01364bec4 --- /dev/null +++ b/packages/connector-mock-sms/README.md @@ -0,0 +1,3 @@ +# Mock short message service connector + +For integration tests only. diff --git a/packages/connector-mock-sms/docs/config-template.json b/packages/connector-mock-sms/docs/config-template.json new file mode 100644 index 000000000..32e9a6236 --- /dev/null +++ b/packages/connector-mock-sms/docs/config-template.json @@ -0,0 +1,19 @@ +{ + "accountSID": "", + "authToken": "", + "fromMessagingServiceSID": "", + "templates": [ + { + "usageType": "SignIn", + "content": "This is for sign-in purposes only. Your passcode is {{code}}." + }, + { + "usageType": "Register", + "content": "This is for registering purposes only. Your passcode is {{code}}." + }, + { + "usageType": "Test", + "content": "This is for testing purposes only. Your passcode is {{code}}." + } + ] +} diff --git a/packages/connector-mock-sms/logo.svg b/packages/connector-mock-sms/logo.svg new file mode 100644 index 000000000..bfb773b11 --- /dev/null +++ b/packages/connector-mock-sms/logo.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/connector-mock-sms/package.json b/packages/connector-mock-sms/package.json new file mode 100644 index 000000000..22c615213 --- /dev/null +++ b/packages/connector-mock-sms/package.json @@ -0,0 +1,47 @@ +{ + "name": "@logto/connector-mock-sms", + "version": "1.0.0-beta.1", + "description": "Mock SMS connector implementation for integration tests only.", + "main": "./lib/index.js", + "exports": "./lib/index.js", + "author": "Silverhand Inc. ", + "license": "MPL-2.0", + "private": true, + "files": [ + "lib", + "docs", + "logo.svg", + "README.md" + ], + "scripts": { + "precommit": "lint-staged", + "build": "rm -rf lib/ && tsc -p tsconfig.build.json", + "lint": "eslint --ext .ts src", + "lint:report": "pnpm lint --format json --output-file report.json", + "dev": "rm -rf lib/ && tsc-watch -p tsconfig.build.json --preserveWatchOutput --onSuccess \"node ./lib/index.js\"", + "prepack": "pnpm build" + }, + "dependencies": { + "@logto/connector-types": "^1.0.0-beta.1", + "@logto/shared": "^1.0.0-beta.1", + "@silverhand/essentials": "^1.1.6", + "zod": "^3.14.3" + }, + "devDependencies": { + "@silverhand/eslint-config": "^0.17.0", + "@silverhand/ts-config": "^0.17.0", + "@types/node": "^16.3.1", + "eslint": "^8.19.0", + "lint-staged": "^13.0.0", + "prettier": "^2.3.2", + "tsc-watch": "^5.0.0", + "typescript": "^4.6.2" + }, + "engines": { + "node": "^16.0.0" + }, + "eslintConfig": { + "extends": "@silverhand" + }, + "prettier": "@silverhand/eslint-config/.prettierrc" +} diff --git a/packages/connector-mock-sms/src/constant.ts b/packages/connector-mock-sms/src/constant.ts new file mode 100644 index 000000000..cab15e187 --- /dev/null +++ b/packages/connector-mock-sms/src/constant.ts @@ -0,0 +1,20 @@ +import { ConnectorType, ConnectorMetadata } from '@logto/connector-types'; + +export const defaultMetadata: ConnectorMetadata = { + id: 'mock-short-message-service', + target: 'mock-sms', + type: ConnectorType.SMS, + platform: null, + name: { + en: 'Mock SMS Service', + 'zh-CN': 'Mock 短信服务', + }, + logo: './logo.svg', + logoDark: null, + description: { + en: 'The description of Mock SMS Service.', + 'zh-CN': 'Mock 短信服务的描述。', + }, + readme: './README.md', + configTemplate: './docs/config-template.json', +}; diff --git a/packages/connector-mock-sms/src/index.ts b/packages/connector-mock-sms/src/index.ts new file mode 100644 index 000000000..74904e57b --- /dev/null +++ b/packages/connector-mock-sms/src/index.ts @@ -0,0 +1,76 @@ +import { + ConnectorError, + ConnectorErrorCodes, + ConnectorMetadata, + Connector, + SmsSendMessageFunction, + SmsSendTestMessageFunction, + SmsConnectorInstance, + GetConnectorConfig, + SmsMessageTypes, +} from '@logto/connector-types'; +import { assert } from '@silverhand/essentials'; + +import { defaultMetadata } from './constant'; +import { mockSmsConfigGuard, MockSmsConfig } from './types'; + +export default class MockSmsConnector implements SmsConnectorInstance { + public metadata: ConnectorMetadata = defaultMetadata; + private _connector?: Connector; + + public get connector() { + if (!this._connector) { + throw new ConnectorError(ConnectorErrorCodes.General); + } + + return this._connector; + } + + public set connector(input: Connector) { + this._connector = input; + } + + constructor(public readonly getConfig: GetConnectorConfig) {} + + public validateConfig(config: unknown): asserts config is MockSmsConfig { + const result = mockSmsConfigGuard.safeParse(config); + + if (!result.success) { + throw new ConnectorError(ConnectorErrorCodes.InvalidConfig, result.error); + } + } + + public sendMessage: SmsSendMessageFunction = async (phone, type, data) => { + const config = await this.getConfig(this.metadata.id); + + this.validateConfig(config); + + return this.sendMessageBy(config, phone, type, data); + }; + + public sendTestMessage: SmsSendTestMessageFunction = async (config, phone, type, data) => { + this.validateConfig(config); + + return this.sendMessageBy(config, phone, type, data); + }; + + private readonly sendMessageBy = async ( + config: MockSmsConfig, + phone: string, + type: keyof SmsMessageTypes, + data: SmsMessageTypes[typeof type] + ) => { + const { templates } = config; + const template = templates.find((template) => template.usageType === type); + + assert( + template, + new ConnectorError( + ConnectorErrorCodes.TemplateNotFound, + `Template not found for type: ${type}` + ) + ); + + return { phone, data }; + }; +} diff --git a/packages/connector-mock-sms/src/types.ts b/packages/connector-mock-sms/src/types.ts new file mode 100644 index 000000000..844e0847e --- /dev/null +++ b/packages/connector-mock-sms/src/types.ts @@ -0,0 +1,15 @@ +import { z } from 'zod'; + +const templateGuard = z.object({ + usageType: z.string(), + content: z.string(), +}); + +export const mockSmsConfigGuard = z.object({ + accountSID: z.string(), + authToken: z.string(), + fromMessagingServiceSID: z.string(), + templates: z.array(templateGuard), +}); + +export type MockSmsConfig = z.infer; diff --git a/packages/connector-mock-sms/tsconfig.base.json b/packages/connector-mock-sms/tsconfig.base.json new file mode 100644 index 000000000..848a915f7 --- /dev/null +++ b/packages/connector-mock-sms/tsconfig.base.json @@ -0,0 +1,10 @@ +{ + "extends": "@silverhand/ts-config/tsconfig.base", + "compilerOptions": { + "outDir": "lib", + "baseUrl": ".", + "paths": { + "@/*": ["src/*"] + } + } +} diff --git a/packages/connector-mock-sms/tsconfig.build.json b/packages/connector-mock-sms/tsconfig.build.json new file mode 100644 index 000000000..a07f6b0e4 --- /dev/null +++ b/packages/connector-mock-sms/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.base", + "include": ["src"] +} diff --git a/packages/connector-mock-sms/tsconfig.json b/packages/connector-mock-sms/tsconfig.json new file mode 100644 index 000000000..93d1196d5 --- /dev/null +++ b/packages/connector-mock-sms/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.base", + "compilerOptions": { + "types": ["node"] + }, + "include": ["src"] +} diff --git a/packages/integration-tests/src/connectors-mock.ts b/packages/integration-tests/src/connectors-mock.ts index 64af8e6b1..995784dde 100644 --- a/packages/integration-tests/src/connectors-mock.ts +++ b/packages/integration-tests/src/connectors-mock.ts @@ -98,3 +98,51 @@ export const sendgridEmailConnectorConfig = { }, ], }; + +export const mockSmsConnectorId = 'mock-short-message-service'; +export const mockSmsConnectorConfig = { + accountSID: 'account-sid-value', + authToken: 'auth-token-value', + fromMessagingServiceSID: 'from-messaging-service-sid-value', + templates: [ + { + content: 'This is for sign-in purposes only. Your passcode is {{code}}.', + usageType: 'SignIn', + }, + { + content: 'This is for registering purposes only. Your passcode is {{code}}.', + usageType: 'Register', + }, + { + content: 'This is for testing purposes only. Your passcode is {{code}}.', + usageType: 'Test', + }, + ], +}; + +export const mockEmailConnectorId = 'mock-email-service'; +export const mockEmailConnectorConfig = { + apiKey: 'api-key-value', + fromEmail: 'noreply@logto.test.io', + fromName: 'from-name-value', + templates: [ + { + usageType: 'SignIn', + type: 'text/plain', + subject: 'Logto SignIn Template', + content: 'This is for sign-in purposes only. Your passcode is {{code}}.', + }, + { + usageType: 'Register', + type: 'text/plain', + subject: 'Logto Register Template', + content: 'This is for registering purposes only. Your passcode is {{code}}.', + }, + { + usageType: 'Test', + type: 'text/plain', + subject: 'Logto Test Template', + content: 'This is for testing purposes only. Your passcode is {{code}}.', + }, + ], +}; diff --git a/packages/integration-tests/tests/connectors.test.ts b/packages/integration-tests/tests/connectors.test.ts index 08456f0a9..893467acd 100644 --- a/packages/integration-tests/tests/connectors.test.ts +++ b/packages/integration-tests/tests/connectors.test.ts @@ -13,12 +13,12 @@ import { facebookConnectorConfig, aliyunSmsConnectorId, aliyunSmsConnectorConfig, - twilioSmsConnectorId, - twilioSmsConnectorConfig, aliyunEmailConnectorId, aliyunEmailConnectorConfig, - sendgridEmailConnectorId, - sendgridEmailConnectorConfig, + mockSmsConnectorId, + mockSmsConnectorConfig, + mockEmailConnectorId, + mockEmailConnectorConfig, } from '@/connectors-mock'; test('connector flow', async () => { @@ -62,13 +62,13 @@ test('connector flow', async () => { /* * Change to another SMS connector */ - const updatedTwilioSmsConnector = await updateConnectorConfig( - twilioSmsConnectorId, - twilioSmsConnectorConfig + const updatedMockSmsConnector = await updateConnectorConfig( + mockSmsConnectorId, + mockSmsConnectorConfig ); - expect(updatedTwilioSmsConnector.config).toEqual(twilioSmsConnectorConfig); - const enabledTwilioSmsConnector = await enableConnector(twilioSmsConnectorId); - expect(enabledTwilioSmsConnector.enabled).toBeTruthy(); + expect(updatedMockSmsConnector.config).toEqual(mockSmsConnectorConfig); + const enabledMockSmsConnector = await enableConnector(mockSmsConnectorId); + expect(enabledMockSmsConnector.enabled).toBeTruthy(); // There should be exactly one enabled SMS connector after changing to another SMS connector. const connectorsAfterChangingSmsConnector = await listConnectors(); @@ -76,7 +76,7 @@ test('connector flow', async () => { (connector) => connector.type === ConnectorType.SMS && connector.enabled ); expect(enabledSmsConnectors.length).toEqual(1); - expect(enabledSmsConnectors[0]?.id).toEqual(twilioSmsConnectorId); + expect(enabledSmsConnectors[0]?.id).toEqual(mockSmsConnectorId); /* * Set up an email connector @@ -92,13 +92,13 @@ test('connector flow', async () => { /* * Change to another email connector */ - const updatedSendgridEmailConnector = await updateConnectorConfig( - sendgridEmailConnectorId, - sendgridEmailConnectorConfig + const updatedMockEmailConnector = await updateConnectorConfig( + mockEmailConnectorId, + mockEmailConnectorConfig ); - expect(updatedSendgridEmailConnector.config).toEqual(sendgridEmailConnectorConfig); - const enabledSendgridEmailConnector = await enableConnector(sendgridEmailConnectorId); - expect(enabledSendgridEmailConnector.enabled).toBeTruthy(); + expect(updatedMockEmailConnector.config).toEqual(mockEmailConnectorConfig); + const enabledMockEmailConnector = await enableConnector(mockEmailConnectorId); + expect(enabledMockEmailConnector.enabled).toBeTruthy(); // There should be exactly one enabled email connector after changing to another email connector. const connectorsAfterChangingEmailConnector = await listConnectors(); @@ -106,14 +106,14 @@ test('connector flow', async () => { (connector) => connector.type === ConnectorType.Email && connector.enabled ); expect(enabledEmailConnector.length).toEqual(1); - expect(enabledEmailConnector[0]?.id).toEqual(sendgridEmailConnectorId); + expect(enabledEmailConnector[0]?.id).toEqual(mockEmailConnectorId); /* * It should update the connector config successfully when it is valid; otherwise, it should fail. * We will test updating to the invalid connector config, that is the case not covered above. */ await expect( - updateConnectorConfig(aliyunEmailConnectorId, sendgridEmailConnectorConfig) + updateConnectorConfig(aliyunEmailConnectorId, mockEmailConnectorConfig) ).rejects.toThrow(HTTPError); // To confirm the failed updating request above did not modify the original config, // we check: the Aliyun email connector config should stay the same. @@ -126,10 +126,10 @@ test('connector flow', async () => { * We have not provided the API to delete a connector for now. * Deleting a connector using Admin Console means disabling a connector using Management API. */ - const disabledSendgridEmailConnector = await disableConnector(sendgridEmailConnectorId); - expect(disabledSendgridEmailConnector.enabled).toBeFalsy(); - const sendgridEmailConnector = await getConnector(sendgridEmailConnectorId); - expect(sendgridEmailConnector.enabled).toBeFalsy(); + const disabledMockEmailConnector = await disableConnector(mockEmailConnectorId); + expect(disabledMockEmailConnector.enabled).toBeFalsy(); + const mockEmailConnector = await getConnector(mockEmailConnectorId); + expect(mockEmailConnector.enabled).toBeFalsy(); /** * List connectors after manually setting up connectors. @@ -148,8 +148,8 @@ test('connector flow', async () => { enabled: false, }), expect.objectContaining({ - id: twilioSmsConnectorId, - config: twilioSmsConnectorConfig, + id: mockSmsConnectorId, + config: mockSmsConnectorConfig, enabled: true, }), expect.objectContaining({ @@ -158,8 +158,8 @@ test('connector flow', async () => { enabled: false, }), expect.objectContaining({ - id: sendgridEmailConnectorId, - config: sendgridEmailConnectorConfig, + id: mockEmailConnectorId, + config: mockEmailConnectorConfig, enabled: false, }), ]) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e5cd89b9e..d72042ea8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -412,6 +412,64 @@ importers: tsc-watch: 5.0.3_typescript@4.6.3 typescript: 4.6.3 + packages/connector-mock-mail: + specifiers: + '@logto/connector-types': ^1.0.0-beta.1 + '@logto/shared': ^1.0.0-beta.1 + '@silverhand/eslint-config': ^0.17.0 + '@silverhand/essentials': ^1.1.6 + '@silverhand/ts-config': ^0.17.0 + '@types/node': ^16.3.1 + eslint: ^8.19.0 + lint-staged: ^13.0.0 + prettier: ^2.3.2 + tsc-watch: ^5.0.0 + typescript: ^4.6.2 + zod: ^3.14.3 + dependencies: + '@logto/connector-types': link:../connector-types + '@logto/shared': link:../shared + '@silverhand/essentials': 1.1.7 + zod: 3.14.3 + devDependencies: + '@silverhand/eslint-config': 0.17.0_zheml67kdyttrjblcc5k6h6tmu + '@silverhand/ts-config': 0.17.0_typescript@4.7.2 + '@types/node': 16.11.12 + eslint: 8.19.0 + lint-staged: 13.0.0 + prettier: 2.5.1 + tsc-watch: 5.0.3_typescript@4.7.2 + typescript: 4.7.2 + + packages/connector-mock-sms: + specifiers: + '@logto/connector-types': ^1.0.0-beta.1 + '@logto/shared': ^1.0.0-beta.1 + '@silverhand/eslint-config': ^0.17.0 + '@silverhand/essentials': ^1.1.6 + '@silverhand/ts-config': ^0.17.0 + '@types/node': ^16.3.1 + eslint: ^8.19.0 + lint-staged: ^13.0.0 + prettier: ^2.3.2 + tsc-watch: ^5.0.0 + typescript: ^4.6.2 + zod: ^3.14.3 + dependencies: + '@logto/connector-types': link:../connector-types + '@logto/shared': link:../shared + '@silverhand/essentials': 1.1.7 + zod: 3.14.3 + devDependencies: + '@silverhand/eslint-config': 0.17.0_zheml67kdyttrjblcc5k6h6tmu + '@silverhand/ts-config': 0.17.0_typescript@4.7.2 + '@types/node': 16.11.12 + eslint: 8.19.0 + lint-staged: 13.0.0 + prettier: 2.5.1 + tsc-watch: 5.0.3_typescript@4.7.2 + typescript: 4.7.2 + packages/connector-sendgrid-mail: specifiers: '@jest/types': ^27.5.1