Skip to content

Commit

Permalink
Chore: updated test before all
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Jun 22, 2024
1 parent 47dfcda commit 9024f9e
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions plugins/mongoose-aggregate-paginate-v2/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import mongooseAggregatePaginate from "../src";
const execute = promisify(exec);

const connectToDatabase = async () => {
await execute("docker run -d -p 27017:27017 mongo:5.0")
await new Promise((resolve) => setTimeout(resolve, 3000))
await mongoose.connect("mongodb://localhost:27017/test")
await mongoose.connection.db.dropDatabase();

};

const AuthorSchema = new mongoose.Schema({
Expand All @@ -33,30 +30,29 @@ BookSchema.plugin(mongooseAggregatePaginate);

const Book = mongoose.model("Book", BookSchema);

beforeAll(connectToDatabase);

describe("mongoose-paginate", function () {
beforeAll(function () {
let book,
books = [];
let date = new Date();
return Author.create({
name: "Arthur Conan Doyle"
}).then(function (author) {
for (let i = 1; i <= 100; i++) {
book = new Book({
title: "Book #" + i,
date: new Date(date.getTime() + i),
author: author._id
});
books.push(book);
}
return Book.create(books);
});
beforeAll(async () => {
await execute("docker run -d -p 27017:27017 mongo:5.0")
await new Promise((resolve) => setTimeout(resolve, 3000))
await mongoose.connect("mongodb://localhost:27017/test")
await mongoose.connection.db.dropDatabase();
let book, books = [];
const date = new Date();
await Author.create({
name: "Arthur Conan Doyle"
}).then(async function (author) {
for (let i = 1; i <= 100; i++) {
book = new Book({
title: "Book #" + i,
date: new Date(date.getTime() + i),
author: author._id
});
books.push(book);
}
await Book.create(books);
});
});

afterEach(function () { });

describe("mongoose-paginate", function () {
it("promise return test", function () {
var aggregate = Book.aggregate([
{
Expand Down

0 comments on commit 9024f9e

Please sign in to comment.