Skip to content

Commit 1228744

Browse files
committed
Fixed broken e2e test
1 parent 128ee93 commit 1228744

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

test/auth.e2e-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Test} from "@nestjs/testing";
33
import {Request} from "express";
44
import * as request from "supertest";
55

6-
import {AuthModule} from "../src/auth/auth.module";
6+
import {AppModule} from "../src/app.module";
77
import {JwtAuthGuard} from "../src/auth/guards/jwt.guard";
88
import {mockAdmin} from "../src/user/user.mocks";
99

@@ -14,7 +14,7 @@ describe("AuthController (e2e)", () => {
1414

1515
beforeEach(async () => {
1616
const moduleRef = await Test.createTestingModule({
17-
imports: [AuthModule]
17+
imports: [AppModule]
1818
})
1919
.overrideGuard(JwtAuthGuard)
2020
.useValue({

test/booking.e2e-spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe("BookingController (e2e)", () => {
1414
let app: INestApplication;
1515
let prismaService: PrismaService;
1616
let bookingId: number;
17+
let userId: number;
1718

1819
const BOOKING_URL = "/api/booking";
1920

@@ -25,18 +26,21 @@ describe("BookingController (e2e)", () => {
2526
.useValue({
2627
canActivate: (context: ExecutionContext) => {
2728
const req = context.switchToHttp().getRequest<Request>();
28-
req.user = mockAdmin;
29+
// Override the mocked id with the actual userId
30+
req.user = {...mockAdmin, id: userId};
2931
return true;
3032
}
3133
})
3234
.compile();
3335

3436
app = moduleRef.createNestApplication();
35-
prismaService = moduleRef.get<PrismaService>(PrismaService);
37+
prismaService = moduleRef.get(PrismaService);
3638

3739
app.useGlobalPipes(new ValidationPipe({transform: true, whitelist: true}));
3840
app.setGlobalPrefix("api");
3941

42+
userId = (await prismaService.user.findFirst()).id;
43+
4044
await app.init();
4145
});
4246

@@ -46,7 +50,6 @@ describe("BookingController (e2e)", () => {
4650

4751
it(`${BOOKING_URL} (POST)`, async () => {
4852
const serviceId = (await prismaService.service.findFirst()).id;
49-
const userId = (await prismaService.user.findFirst()).id;
5053

5154
const createBookingDto: CreateBookingDto = {
5255
from: new Date(),

test/service.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("ServiceController (e2e)", () => {
3131
.compile();
3232

3333
app = moduleRef.createNestApplication();
34-
prismaService = moduleRef.get<PrismaService>(PrismaService);
34+
prismaService = moduleRef.get(PrismaService);
3535

3636
app.useGlobalPipes(new ValidationPipe({transform: true, whitelist: true}));
3737
app.setGlobalPrefix("api");

test/user.e2e-spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@ describe("UserController (e2e)", () => {
2323
.useValue({
2424
canActivate: (context: ExecutionContext) => {
2525
const req = context.switchToHttp().getRequest<Request>();
26-
req.user = mockAdmin;
26+
// Override the mocked id with the actual userId
27+
req.user = {...mockAdmin, id: userId};
2728
return true;
2829
}
2930
})
3031
.compile();
3132

3233
app = moduleRef.createNestApplication();
33-
prismaService = moduleRef.get<PrismaService>(PrismaService);
34+
prismaService = moduleRef.get(PrismaService);
3435

3536
app.useGlobalPipes(new ValidationPipe({transform: true, whitelist: true}));
3637
app.setGlobalPrefix("api");
3738

38-
userId = (await prismaService.user.findFirst()).id;
39+
// Get the id of the last user
40+
userId = (await prismaService.user.findFirst({orderBy: {id: "desc"}})).id;
3941

4042
await app.init();
4143
});

0 commit comments

Comments
 (0)