Skip to content

Commit

Permalink
Fix tests and async/await issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kjkurtz committed Dec 18, 2023
1 parent 1fa0d24 commit b8cda2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function createdUpdatedPlugin(schema: Schema<any, any, any, any>) {
next();
});

schema.pre(/save|updateOne|insertMany/, async function (next) {
await this.updateOne({}, {$set: {updated: new Date()}});
schema.pre(/save|updateOne|insertMany/, function (next) {
void this.updateOne({}, {$set: {updated: new Date()}});
next();
});
}
Expand Down
6 changes: 4 additions & 2 deletions src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import supertest from "supertest";
import {logger} from "./logger";
import {createdUpdatedPlugin} from "./plugins";

mongoose.connect("mongodb://127.0.0.1/ferns?&connectTimeoutMS=360000").catch(logger.catch);

export interface User {
admin: boolean;
username: string;
Expand Down Expand Up @@ -152,6 +150,10 @@ export function getBaseServer(): Express {
return app;
}

beforeAll(async () => {
await mongoose.connect("mongodb://127.0.0.1/ferns?&connectTimeoutMS=360000").catch(logger.catch);
});

afterAll(async () => {
await mongoose.connection.close();
});
Expand Down

0 comments on commit b8cda2d

Please sign in to comment.