11import { beforeAll , afterAll , describe , it , expect } from 'vitest'
22import feathers from '@feathersjs/feathers'
33import { MongoClient } from 'mongodb'
4- import makeDebug from 'debug'
5-
64import plugin from '../src/index.js'
75
8- const debug = makeDebug ( 'feathers-mongodb-management:tests' )
9-
106describe ( 'feathers-mongodb-management' , ( ) => {
117 let app , client , adminDb , testDb , databaseService , collectionService , userService
128
@@ -41,10 +37,9 @@ describe('feathers-mongodb-management', () => {
4137 } )
4238
4339 it ( 'creates a database' , async ( ) => {
44- const db = await databaseService . create ( {
40+ await databaseService . create ( {
4541 name : 'test-db'
4642 } )
47- debug ( db )
4843 testDb = client . db ( 'test-db' )
4944 expect ( testDb ) . toBeDefined ( )
5045 } )
@@ -53,7 +48,6 @@ describe('feathers-mongodb-management', () => {
5348 const serviceDbs = await databaseService . find ( {
5449 query : { $select : [ 'name' , 'collections' ] }
5550 } )
56- debug ( serviceDbs )
5751 const dbsInfo = await adminDb . listDatabases ( )
5852 expect ( serviceDbs . length ) . toBe ( dbsInfo . databases . length )
5953 serviceDbs . forEach ( db => expect ( db . collections ) . toBeDefined ( ) )
@@ -70,22 +64,18 @@ describe('feathers-mongodb-management', () => {
7064 } )
7165
7266 it ( 'creates a collection' , async ( ) => {
73- const collection = await collectionService . create ( {
67+ await collectionService . create ( {
7468 name : 'test-collection'
7569 } )
76-
77- debug ( collection )
7870 // Need to use strict mode to ensure the delete operation has been taken into account
7971 const createdCollection = await testDb . collection ( 'test-collection' , { strict : true } )
80-
8172 expect ( createdCollection ) . toBeDefined ( )
8273 } )
8374
8475 it ( 'finds collections' , async ( ) => {
8576 const serviceCollections = await collectionService . find ( {
8677 query : { $select : [ 'name' , 'count' ] }
8778 } )
88- debug ( serviceCollections )
8979 const collections = await testDb . collections ( )
9080 expect ( serviceCollections . length ) . toBe ( collections . length )
9181 serviceCollections . forEach ( collection => expect ( collection . count ) . toBeDefined ( ) )
@@ -94,12 +84,8 @@ describe('feathers-mongodb-management', () => {
9484 } )
9585
9686 it ( 'removes a collection' , async ( ) => {
97- const collection = await collectionService . remove ( 'test-collection' )
98-
99- debug ( collection )
100-
87+ await collectionService . remove ( 'test-collection' )
10188 const collections = await testDb . collections ( )
102-
10389 expect ( ! collections . includes ( 'test-collection' ) )
10490 } )
10591
@@ -114,12 +100,11 @@ describe('feathers-mongodb-management', () => {
114100 } )
115101
116102 it ( 'creates a user' , async ( ) => {
117- const serviceUser = await userService . create ( {
103+ await userService . create ( {
118104 name : 'test-user' ,
119105 password : 'test-password' ,
120106 roles : [ 'readWrite' ]
121107 } )
122- debug ( serviceUser )
123108 const user = await testDb . command ( { usersInfo : 'test-user' } )
124109 expect ( user ) . toBeDefined ( )
125110 } )
@@ -128,7 +113,6 @@ describe('feathers-mongodb-management', () => {
128113 const serviceUsers = await userService . find ( {
129114 query : { $select : [ 'name' , 'roles' ] }
130115 } )
131- debug ( serviceUsers )
132116 const data = await testDb . command ( { usersInfo : 1 } )
133117 expect ( serviceUsers . length ) . toBe ( data . users . length )
134118 serviceUsers . forEach ( user => expect ( user . name ) . toBeDefined ( ) )
@@ -137,8 +121,7 @@ describe('feathers-mongodb-management', () => {
137121 } )
138122
139123 it ( 'removes a user' , async ( ) => {
140- const serviceUser = await userService . remove ( 'test-user' )
141- debug ( serviceUser )
124+ await userService . remove ( 'test-user' )
142125 try {
143126 await testDb . command ( { usersInfo : 'test-user' } )
144127 } catch ( error ) {
@@ -147,8 +130,7 @@ describe('feathers-mongodb-management', () => {
147130 } )
148131
149132 it ( 'removes a database' , async ( ) => {
150- const db = await databaseService . remove ( 'test-db' )
151- debug ( db )
133+ await databaseService . remove ( 'test-db' )
152134 const dbsInfo = await adminDb . listDatabases ( )
153135 expect ( dbsInfo . databases . find ( item => item . name === 'test-db' ) ) . toBeUndefined ( )
154136 } )
0 commit comments