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

View File

@@ -7,6 +7,14 @@ e2e('should create test app correctly', async t => {
t.truthy(app); 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 => { e2e('should handle http request', async t => {
const res = await app.GET('/info'); const res = await app.GET('/info');
t.is(res.status, 200); t.is(res.status, 200);

View File

@@ -14,6 +14,7 @@ import {
CacheInterceptor, CacheInterceptor,
CloudThrottlerGuard, CloudThrottlerGuard,
GlobalExceptionFilter, GlobalExceptionFilter,
JobQueue,
OneMB, OneMB,
} from '../../base'; } from '../../base';
import { SocketIoAdapter } from '../../base/websocket'; import { SocketIoAdapter } from '../../base/websocket';
@@ -22,6 +23,7 @@ import { Mailer } from '../../core/mail';
import { import {
createFactory, createFactory,
MockedUser, MockedUser,
MockJobQueue,
MockMailer, MockMailer,
MockUser, MockUser,
MockUserInput, MockUserInput,
@@ -40,6 +42,7 @@ export class TestingApp extends NestApplication {
create = createFactory(this.get(PrismaClient, { strict: false })); create = createFactory(this.get(PrismaClient, { strict: false }));
mails = this.get(Mailer, { strict: false }) as MockMailer; mails = this.get(Mailer, { strict: false }) as MockMailer;
queue = this.get(JobQueue, { strict: false }) as MockJobQueue;
get url() { get url() {
const server = this.getHttpServer(); const server = this.getHttpServer();
@@ -193,6 +196,9 @@ export async function createApp(
imports: [buildAppModule()], imports: [buildAppModule()],
}); });
builder.overrideProvider(Mailer).useValue(new MockMailer());
builder.overrideProvider(JobQueue).useValue(new MockJobQueue());
// when custom override happens // when custom override happens
if (tapModule) { if (tapModule) {
tapModule(builder); tapModule(builder);