chore: fixes mongoose 6.0 upgrade

This commit is contained in:
hantsy 2021-08-30 23:50:18 +08:00
parent 2cb18ecf9c
commit bc4c004070
4 changed files with 13 additions and 12 deletions

1
package-lock.json generated
View File

@ -5,6 +5,7 @@
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "nestjs-sample",
"version": "0.0.1", "version": "0.0.1",
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {

View File

@ -34,10 +34,10 @@ describe('DatabaseConnectionProviders', () => {
//expect(conn).toBeDefined(); //expect(conn).toBeDefined();
//expect(createConnection).toHaveBeenCalledTimes(1); // it is 2 here. why? //expect(createConnection).toHaveBeenCalledTimes(1); // it is 2 here. why?
expect(createConnection).toHaveBeenCalledWith("mongodb://localhost/blog", { expect(createConnection).toHaveBeenCalledWith("mongodb://localhost/blog", {
useNewUrlParser: true, // useNewUrlParser: true,
useUnifiedTopology: true, // useUnifiedTopology: true,
//see: https://mongoosejs.com/docs/deprecations.html#findandmodify //see: https://mongoosejs.com/docs/deprecations.html#findandmodify
useFindAndModify: false // useFindAndModify: false
}); });
}) })

View File

@ -8,10 +8,10 @@ export const databaseConnectionProviders = [
provide: DATABASE_CONNECTION, provide: DATABASE_CONNECTION,
useFactory: (dbConfig: ConfigType<typeof mongodbConfig>): Connection => { useFactory: (dbConfig: ConfigType<typeof mongodbConfig>): Connection => {
const conn = createConnection(dbConfig.uri, { const conn = createConnection(dbConfig.uri, {
useNewUrlParser: true, //useNewUrlParser: true,
useUnifiedTopology: true, //useUnifiedTopology: true,
//see: https://mongoosejs.com/docs/deprecations.html#findandmodify //see: https://mongoosejs.com/docs/deprecations.html#findandmodify
useFindAndModify: false, //useFindAndModify: false,
}); });
// conn.on('disconnect', () => { // conn.on('disconnect', () => {

View File

@ -71,7 +71,7 @@ describe('API endpoints testing (e2e)', () => {
}); });
it('/posts (GET) if none existing should return 404', async () => { it('/posts (GET) if none existing should return 404', async () => {
const id = mongoose.Types.ObjectId(); const id = new mongoose.Types.ObjectId();
const res = await request(app.getHttpServer()).get('/posts/' + id); const res = await request(app.getHttpServer()).get('/posts/' + id);
expect(res.status).toBe(404); expect(res.status).toBe(404);
}); });
@ -90,7 +90,7 @@ describe('API endpoints testing (e2e)', () => {
}); });
it('/posts (PUT) should return 401', async () => { it('/posts (PUT) should return 401', async () => {
const id = mongoose.Types.ObjectId(); const id = new mongoose.Types.ObjectId();
const res = await request(app.getHttpServer()) const res = await request(app.getHttpServer())
.put('/posts/' + id) .put('/posts/' + id)
.send({ title: 'test title', content: 'test content' }); .send({ title: 'test title', content: 'test content' });
@ -98,7 +98,7 @@ describe('API endpoints testing (e2e)', () => {
}); });
it('/posts (DELETE) should return 401', async () => { it('/posts (DELETE) should return 401', async () => {
const id = mongoose.Types.ObjectId(); const id = new mongoose.Types.ObjectId();
const res = await request(app.getHttpServer()) const res = await request(app.getHttpServer())
.delete('/posts/' + id) .delete('/posts/' + id)
.send(); .send();
@ -134,7 +134,7 @@ describe('API endpoints testing (e2e)', () => {
}); });
it('/posts (PUT) if none existing should return 404', async () => { it('/posts (PUT) if none existing should return 404', async () => {
const id = mongoose.Types.ObjectId(); const id = new mongoose.Types.ObjectId();
const res = await request(app.getHttpServer()) const res = await request(app.getHttpServer())
.put('/posts/' + id) .put('/posts/' + id)
.set('Authorization', 'Bearer ' + jwttoken) .set('Authorization', 'Bearer ' + jwttoken)
@ -143,7 +143,7 @@ describe('API endpoints testing (e2e)', () => {
}); });
it('/posts (DELETE) if none existing should return 403', async () => { it('/posts (DELETE) if none existing should return 403', async () => {
const id = mongoose.Types.ObjectId(); const id = new mongoose.Types.ObjectId();
const res = await request(app.getHttpServer()) const res = await request(app.getHttpServer())
.delete('/posts/' + id) .delete('/posts/' + id)
.set('Authorization', 'Bearer ' + jwttoken) .set('Authorization', 'Bearer ' + jwttoken)
@ -217,7 +217,7 @@ describe('API endpoints testing (e2e)', () => {
}); });
it('/posts (DELETE) if none existing should return 404', async () => { it('/posts (DELETE) if none existing should return 404', async () => {
const id = mongoose.Types.ObjectId(); const id = new mongoose.Types.ObjectId();
const res = await request(app.getHttpServer()) const res = await request(app.getHttpServer())
.delete('/posts/' + id) .delete('/posts/' + id)
.set('Authorization', 'Bearer ' + jwttoken) .set('Authorization', 'Bearer ' + jwttoken)