test(server): add mock mail and queue tests (#11061)

This commit is contained in:
fengmk2
2025-03-24 03:32:25 +00:00
parent d62c8642fb
commit b0871331de
2 changed files with 14 additions and 0 deletions
@@ -7,6 +7,14 @@ e2e('should create test app correctly', async t => {
t.truthy(app);
});
e2e('should mock mails work', async t => {
t.is(app.mails.count('MemberInvitation'), 0);
});
e2e('should mock queue work', async t => {
t.is(app.queue.count('notification.sendInvitation'), 0);
});
e2e('should handle http request', async t => {
const res = await app.GET('/info');
t.is(res.status, 200);
@@ -14,6 +14,7 @@ import {
CacheInterceptor,
CloudThrottlerGuard,
GlobalExceptionFilter,
JobQueue,
OneMB,
} from '../../base';
import { SocketIoAdapter } from '../../base/websocket';
@@ -22,6 +23,7 @@ import { Mailer } from '../../core/mail';
import {
createFactory,
MockedUser,
MockJobQueue,
MockMailer,
MockUser,
MockUserInput,
@@ -40,6 +42,7 @@ export class TestingApp extends NestApplication {
create = createFactory(this.get(PrismaClient, { strict: false }));
mails = this.get(Mailer, { strict: false }) as MockMailer;
queue = this.get(JobQueue, { strict: false }) as MockJobQueue;
get url() {
const server = this.getHttpServer();
@@ -193,6 +196,9 @@ export async function createApp(
imports: [buildAppModule()],
});
builder.overrideProvider(Mailer).useValue(new MockMailer());
builder.overrideProvider(JobQueue).useValue(new MockJobQueue());
// when custom override happens
if (tapModule) {
tapModule(builder);