mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 05:47:09 +08:00
test(server): utils (#10028)
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import type { TestFn } from 'ava';
|
||||
import ava from 'ava';
|
||||
import Sinon from 'sinon';
|
||||
|
||||
import { AppModule } from '../app.module';
|
||||
import { MailService } from '../base/mailer';
|
||||
import { createTestingApp, createWorkspace, inviteUser, signUp } from './utils';
|
||||
import {
|
||||
createTestingApp,
|
||||
createWorkspace,
|
||||
inviteUser,
|
||||
TestingApp,
|
||||
} from './utils';
|
||||
const test = ava as TestFn<{
|
||||
app: INestApplication;
|
||||
app: TestingApp;
|
||||
mail: MailService;
|
||||
}>;
|
||||
import * as renderers from '../mails';
|
||||
|
||||
test.beforeEach(async t => {
|
||||
const { module, app } = await createTestingApp({
|
||||
imports: [AppModule],
|
||||
});
|
||||
const app = await createTestingApp();
|
||||
|
||||
const mail = module.get(MailService);
|
||||
const mail = app.get(MailService);
|
||||
t.context.app = app;
|
||||
t.context.mail = mail;
|
||||
});
|
||||
@@ -30,14 +31,12 @@ test('should send invite email', async t => {
|
||||
const { mail, app } = t.context;
|
||||
|
||||
if (mail.hasConfigured()) {
|
||||
const u1 = await signUp(app, 'u1', 'u1@affine.pro', '1');
|
||||
const u2 = await signUp(app, 'u2', 'u2@affine.pro', '1');
|
||||
|
||||
const workspace = await createWorkspace(app, u1.token.token);
|
||||
|
||||
const u2 = await app.signup('u2@affine.pro');
|
||||
const u1 = await app.signup('u1@affine.pro');
|
||||
const stub = Sinon.stub(mail, 'send');
|
||||
|
||||
await inviteUser(app, u1.token.token, workspace.id, u2.email, true);
|
||||
const workspace = await createWorkspace(app);
|
||||
await inviteUser(app, workspace.id, u2.email, true);
|
||||
|
||||
t.true(stub.calledOnce);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user