2023-09-15 10:34:14 +03:00
|
|
|
/// <reference types="../src/global.d.ts" />
|
2023-09-02 21:13:59 +03:00
|
|
|
// This test case is for testing the mailer service.
|
|
|
|
// Please use local SMTP server for testing.
|
|
|
|
// See: https://github.com/mailhog/MailHog
|
2023-09-13 08:11:19 +03:00
|
|
|
import {
|
|
|
|
getCurrentMailMessageCount,
|
|
|
|
getLatestMailMessage,
|
|
|
|
} from '@affine-test/kit/utils/cloud';
|
2024-01-11 09:40:55 +03:00
|
|
|
import { TestingModule } from '@nestjs/testing';
|
2024-03-25 06:55:32 +03:00
|
|
|
import type { TestFn } from 'ava';
|
|
|
|
import ava from 'ava';
|
2023-09-02 21:13:59 +03:00
|
|
|
|
2024-01-22 10:40:28 +03:00
|
|
|
import { AuthService } from '../src/core/auth/service';
|
2024-01-12 07:18:39 +03:00
|
|
|
import { ConfigModule } from '../src/fundamentals/config';
|
2024-01-11 09:40:55 +03:00
|
|
|
import { createTestingModule } from './utils';
|
2023-09-02 21:13:59 +03:00
|
|
|
|
2023-09-15 10:34:14 +03:00
|
|
|
const test = ava as TestFn<{
|
|
|
|
auth: AuthService;
|
|
|
|
module: TestingModule;
|
|
|
|
skip: boolean;
|
|
|
|
}>;
|
2023-09-02 21:13:59 +03:00
|
|
|
|
2023-09-15 10:34:14 +03:00
|
|
|
test.beforeEach(async t => {
|
2024-01-11 09:40:55 +03:00
|
|
|
t.context.module = await createTestingModule({
|
2024-03-12 13:00:09 +03:00
|
|
|
imports: [ConfigModule.forRoot({})],
|
2024-01-11 09:40:55 +03:00
|
|
|
});
|
2023-09-15 10:34:14 +03:00
|
|
|
t.context.auth = t.context.module.get(AuthService);
|
2023-09-02 21:13:59 +03:00
|
|
|
});
|
|
|
|
|
2023-09-15 10:34:14 +03:00
|
|
|
test.afterEach.always(async t => {
|
|
|
|
await t.context.module.close();
|
2023-09-02 21:13:59 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should include callbackUrl in sending email', async t => {
|
2023-09-15 10:34:14 +03:00
|
|
|
const { auth } = t.context;
|
|
|
|
await auth.signUp('Alex Yang', 'alexyang@example.org', '123456');
|
2023-09-02 21:13:59 +03:00
|
|
|
for (const fn of [
|
|
|
|
'sendSetPasswordEmail',
|
|
|
|
'sendChangeEmail',
|
|
|
|
'sendChangePasswordEmail',
|
2023-09-13 19:54:02 +03:00
|
|
|
'sendVerifyChangeEmail',
|
2023-09-02 21:13:59 +03:00
|
|
|
] as const) {
|
|
|
|
const prev = await getCurrentMailMessageCount();
|
|
|
|
await auth[fn]('alexyang@example.org', 'https://test.com/callback');
|
|
|
|
const current = await getCurrentMailMessageCount();
|
|
|
|
const mail = await getLatestMailMessage();
|
|
|
|
t.regex(
|
2023-09-15 10:34:14 +03:00
|
|
|
mail?.Content?.Body,
|
2023-09-02 21:13:59 +03:00
|
|
|
/https:\/\/test.com\/callback/,
|
|
|
|
`should include callbackUrl when calling ${fn}`
|
|
|
|
);
|
|
|
|
t.is(current, prev + 1, `calling ${fn}`);
|
|
|
|
}
|
|
|
|
});
|