0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-04-07 23:01:25 -05:00

test: integration tests for setting up and changing SMS conectors (#1638)

This commit is contained in:
IceHe.life 2022-07-21 17:22:16 +08:00 committed by GitHub
parent 34b465c7d8
commit ee17590bcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,5 @@
import { ConnectorType } from '@logto/schemas';
import {
enableConnector,
getConnector,
@ -11,8 +13,52 @@ const facebookConnectorConfig = {
clientSecret: 'secret_bar',
};
const aliyunSmsConnectorId = 'aliyun-short-message-service';
const aliyunSmsConnectorConfig = {
signName: 'sign-name-value',
templates: [
{
usageType: 'SignIn',
templateCode: 'template-code-value',
},
{
usageType: 'Register',
templateCode: 'template-code-value',
},
{
usageType: 'Test',
templateCode: 'template-code-value',
},
],
accessKeyId: 'access-key-id-value',
accessKeySecret: 'access-key-secret-value',
};
const twilioSmsConnectorId = 'twilio-short-message-service';
const twilioSmsConnectorConfig = {
authToken: 'auth-token-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',
},
],
accountSID: 'account-sid-value',
fromMessagingServiceSID: 'from-messaging-service-sid-value',
};
test('connector flow', async () => {
// List connectors after initializing a new Logto instance
/*
* List connectors after initializing a new Logto instance
*/
const allConnectors = await listConnectors();
// There should be no connectors, or all connectors should be disabled.
@ -20,7 +66,9 @@ test('connector flow', async () => {
expect(connectorDto.enabled).toBeFalsy();
}
// Set up a social connector
/*
* Set up a social connector
*/
const updatedFacebookConnector = await updateConnectorConfig(
facebookConnectorId,
facebookConnectorConfig
@ -34,8 +82,37 @@ test('connector flow', async () => {
expect(facebookConnector.enabled).toBeTruthy();
expect(facebookConnector.config).toEqual(facebookConnectorConfig);
/*
* Set up an SMS connector
*/
const updatedAliyunSmsConnector = await updateConnectorConfig(
aliyunSmsConnectorId,
aliyunSmsConnectorConfig
);
expect(updatedAliyunSmsConnector.config).toEqual(aliyunSmsConnectorConfig);
const enabledAliyunSmsConnector = await enableConnector(aliyunSmsConnectorId);
expect(enabledAliyunSmsConnector.enabled).toBeTruthy();
/*
* Change to another SMS connector
*/
const updatedTwilioSmsConnector = await updateConnectorConfig(
twilioSmsConnectorId,
twilioSmsConnectorConfig
);
expect(updatedTwilioSmsConnector.config).toEqual(twilioSmsConnectorConfig);
const enabledTwilioSmsConnector = await enableConnector(twilioSmsConnectorId);
expect(enabledTwilioSmsConnector.enabled).toBeTruthy();
// There should be exactly one enabled SMS connector after changing to another SMS connector.
const connectorsAfterChangingSmsConnector = await listConnectors();
const enabledSmsConnectors = connectorsAfterChangingSmsConnector.filter(
(connector) => connector.type === ConnectorType.SMS && connector.enabled
);
expect(enabledSmsConnectors.length).toEqual(1);
expect(enabledSmsConnectors[0]?.id).toEqual(twilioSmsConnectorId);
// Next up:
// - set up an SMS connector and then change to another SMS connector
// - set up an email connector and then change to another email connector
// - validate wrong connector config
// - send sms/email test message