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

test: integration tests for sending SMS or email test messages (#1680)

* test: integration tests for sending SMS or email test messages

* refactor(test): integration tests for sending SMS or email test messages
This commit is contained in:
IceHe.Life 2022-07-27 11:33:32 +08:00 committed by GitHub
parent 162998f414
commit 17e5476955
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 5 deletions

View file

@ -28,3 +28,26 @@ const updateConnectorEnabledProperty = (connectorId: string, enabled: boolean) =
json: { enabled },
})
.json<ConnectorDto>();
export const sendSmsTestMessage = async (
connectorId: string,
phone: string,
config: Record<string, unknown>
) => sendTestMessage(connectorId, 'phone', phone, config);
export const sendEmailTestMessage = async (
connectorId: string,
email: string,
config: Record<string, unknown>
) => sendTestMessage(connectorId, 'email', email, config);
const sendTestMessage = async (
connectorId: string,
receiverType: 'phone' | 'email',
receiver: string,
config: Record<string, unknown>
) =>
authedAdminApi.post({
url: `connectors/${connectorId}/test`,
json: { [receiverType]: receiver, config },
});

View file

@ -18,6 +18,8 @@ import {
enableConnector,
getConnector,
listConnectors,
sendEmailTestMessage,
sendSmsTestMessage,
updateConnectorConfig,
} from '@/api/connector';
@ -164,9 +166,25 @@ test('connector flow', async () => {
}),
])
);
// Next up
// - validate `config` parameter before sending
// - send sms test message
// - send email test message
});
describe('send SMS/email test message', () => {
const phone = '8612345678901';
const email = 'test@example.com';
it('should send the test message successfully when the config is valid', async () => {
await expect(
sendSmsTestMessage(mockSmsConnectorId, phone, mockSmsConnectorConfig)
).resolves.not.toThrow();
await expect(
sendEmailTestMessage(mockEmailConnectorId, email, mockEmailConnectorConfig)
).resolves.not.toThrow();
});
it('should fail to send the test message when the config is invalid', async () => {
await expect(sendSmsTestMessage(mockSmsConnectorId, phone, {})).rejects.toThrow(HTTPError);
await expect(sendEmailTestMessage(mockEmailConnectorId, email, {})).rejects.toThrow(HTTPError);
});
});
// Next up: refactor connectors.test.ts