@@ -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 ( ) => {
0 commit comments