Skip to content

Commit 30a69c7

Browse files
committed
fix: e2e test
1 parent 583eadf commit 30a69c7

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

test/auth-login-logout.e2e-spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ describe('Web auth (e2e)', () => {
3131
let userService: UserService;
3232
let namespaceService: NamespaceService;
3333

34-
const mongoUrl = `${mongoTestBaseUrl}/auth-login-logout-e2e`;
34+
const dbName = 'auth-login-logout-e2e';
35+
const mongoUrl = `${mongoTestBaseUrl}/${dbName}`;
3536

3637
beforeAll(async () => {
3738
const moduleFixture: TestingModule = await Test.createTestingModule({
@@ -41,6 +42,10 @@ describe('Web auth (e2e)', () => {
4142
app = moduleFixture.createNestApplication();
4243
await app.init();
4344

45+
// drop the database
46+
const connection = app.get<Connection>(getConnectionToken()); // 获取连接
47+
await connection.db.dropDatabase({ dbName }); // 使用从 MongooseModule 中获得的连接删除数据库
48+
4449
userService = moduleFixture.get<UserService>(UserService);
4550
namespaceService = moduleFixture.get<NamespaceService>(NamespaceService);
4651

@@ -52,9 +57,6 @@ describe('Web auth (e2e)', () => {
5257
});
5358

5459
afterAll(async () => {
55-
// drop the database
56-
const connection = app.get<Connection>(getConnectionToken()); // 获取连接
57-
await connection.db.dropDatabase(); // 使用从 MongooseModule 中获得的连接删除数据库
5860
// close app
5961
await app.close();
6062
});

test/captcha.e2e-spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('Captcha workflow (e2e)', () => {
2121
let app: INestApplication;
2222
let captchaService: CaptchaService;
2323

24-
const mongoUrl = `${mongoTestBaseUrl}/captcha-e2e`;
24+
const dbName = 'captcha-e2e';
25+
const mongoUrl = `${mongoTestBaseUrl}/${dbName}`;
2526

2627
beforeAll(async () => {
2728
const moduleFixture: TestingModule = await Test.createTestingModule({
@@ -33,13 +34,14 @@ describe('Captcha workflow (e2e)', () => {
3334
app.useGlobalInterceptors(new MongoErrorsInterceptor());
3435
await app.init();
3536

37+
// drop the database
38+
const connection = app.get<Connection>(getConnectionToken()); // 获取连接
39+
await connection.db.dropDatabase({ dbName }); // 使用从 MongooseModule 中获得的连接删除数据库
40+
3641
captchaService = moduleFixture.get<CaptchaService>(CaptchaService);
3742
});
3843

3944
afterAll(async () => {
40-
// drop the database
41-
const connection = app.get<Connection>(getConnectionToken()); // 获取连接
42-
await connection.db.dropDatabase(); // 使用从 MongooseModule 中获得的连接删除数据库
4345
// close app
4446
await app.close();
4547
});

test/namespace.e2e-spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ describe('Namespace crud (e2e)', () => {
1717
let app: INestApplication;
1818
let namespaceService: NamespaceService;
1919

20-
const mongoUrl = `${mongoTestBaseUrl}/namesapce-e2e`;
20+
const dbName = 'namespace-e2e';
21+
const mongoUrl = `${mongoTestBaseUrl}/${dbName}`;
2122

2223
beforeAll(async () => {
2324
const moduleFixture: TestingModule = await Test.createTestingModule({
@@ -29,6 +30,10 @@ describe('Namespace crud (e2e)', () => {
2930
app.useGlobalInterceptors(new MongoErrorsInterceptor());
3031
await app.init();
3132

33+
// drop the database
34+
const connection = app.get<Connection>(getConnectionToken()); // 获取连接
35+
await connection.db.dropDatabase({ dbName }); // 使用从 MongooseModule 中获得的连接删除数据库
36+
3237
namespaceService = moduleFixture.get<NamespaceService>(NamespaceService);
3338

3439
// ensure index is created
@@ -39,9 +44,6 @@ describe('Namespace crud (e2e)', () => {
3944
});
4045

4146
afterAll(async () => {
42-
// drop the database
43-
const connection = app.get<Connection>(getConnectionToken()); // 获取连接
44-
await connection.db.dropDatabase(); // 使用从 MongooseModule 中获得的连接删除数据库
4547
// close app
4648
await app.close();
4749
});
@@ -97,7 +99,7 @@ describe('Namespace crud (e2e)', () => {
9799
.set('x-api-key', auth.apiKey)
98100
.set('Accept', 'application/json')
99101
.expect(200);
100-
expect(resp2.body).toHaveLength(5);
102+
expect(resp2.body).toHaveLength(2);
101103

102104
// 使用 ns_start 参数
103105
const resp3 = await request(app.getHttpServer())
@@ -106,7 +108,7 @@ describe('Namespace crud (e2e)', () => {
106108
.set('x-api-key', auth.apiKey)
107109
.set('Accept', 'application/json')
108110
.expect(200);
109-
expect(resp3.body).toHaveLength(5);
111+
expect(resp3.body).toHaveLength(3);
110112
});
111113

112114
it(`get namespace`, async () => {

test/user.e2e-spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ describe('User crud (e2e)', () => {
3131
let namespaceService: NamespaceService;
3232
let userService: UserService;
3333

34-
const mongoUrl = `${mongoTestBaseUrl}/user-e2e`;
34+
const dbName = 'user-e2e';
35+
const mongoUrl = `${mongoTestBaseUrl}/${dbName}`;
3536

3637
beforeAll(async () => {
3738
const moduleFixture: TestingModule = await Test.createTestingModule({
@@ -43,14 +44,15 @@ describe('User crud (e2e)', () => {
4344
app.useGlobalInterceptors(new MongoErrorsInterceptor());
4445
await app.init();
4546

47+
// drop the database
48+
const connection = app.get<Connection>(getConnectionToken()); // 获取连接
49+
await connection.db.dropDatabase({ dbName }); // 使用从 MongooseModule 中获得的连接删除数据库
50+
4651
namespaceService = moduleFixture.get<NamespaceService>(NamespaceService);
4752
userService = moduleFixture.get<UserService>(UserService);
4853
});
4954

5055
afterAll(async () => {
51-
// drop the database
52-
const connection = app.get<Connection>(getConnectionToken()); // 获取连接
53-
await connection.db.dropDatabase(); // 使用从 MongooseModule 中获得的连接删除数据库
5456
// close app
5557
await app.close();
5658
});

0 commit comments

Comments
 (0)