Skip to content

Commit

Permalink
update set-up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuqi-Du committed Nov 28, 2023
1 parent cfab036 commit bbd7b7b
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions photography-site-demo.js/tests/setup.test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,22 @@

require('dotenv').config({ path: `${__dirname}/../.env.test` });

const Photo = require('../server/models/Photo');
const Category = require('../server/models/Category');
const PhotoEmbedding = require('../server/models/PhotoEmbedding');

const { before } = require('mocha');
const { before, after } = require('mocha');
const connect = require('../server/models/connect');
const mongoose = require('../server/models/mongoose');

const uri = process.env.JSON_API_URL;
const jsonApiConnectOptions = {
username: process.env.JSON_API_AUTH_USERNAME,
password: process.env.JSON_API_AUTH_PASSWORD,
authUrl: process.env.JSON_API_AUTH_URL
};

before(async function() {
console.log('Connecting to', uri);
this.timeout(30000);
await mongoose.connect(uri, jsonApiConnectOptions);
await Photo.db.dropCollection('photos').catch(() => {});
await Category.db.dropCollection('categorys').catch(() => {});
await PhotoEmbedding.db.dropCollection('photoEmbeddings').catch(() => {});
await Photo.createCollection();
await Category.createCollection();
await PhotoEmbedding.createCollection();

await connect();
await Promise.all(Object.values(mongoose.connection.models).map(Model => Model.createCollection()));
await Promise.all(Object.values(mongoose.connection.models).map(Model => Model.deleteMany({})));
});

after(async function() {
this.timeout(30000);
await Promise.all(Object.values(mongoose.connection.models).map(async Model => {
await mongoose.connection.dropCollection(Model.collection.collectionName);
}));

await mongoose.disconnect();
});

0 comments on commit bbd7b7b

Please sign in to comment.