mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-22 08:58:11 +00:00
Mock DB ready state for Admin API tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 1000, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 1000, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
|
import mongoose from 'mongoose';
|
||||||
import supertest from 'supertest';
|
import supertest from 'supertest';
|
||||||
import HBApp from './app.js';
|
import HBApp from './app.js';
|
||||||
import { model as NotificationModel } from './notifications.model.js';
|
import { model as NotificationModel } from './notifications.model.js';
|
||||||
@@ -8,8 +9,19 @@ import { model as HomebrewModel } from './homebrew.model.js';
|
|||||||
// Mimic https responses to avoid being redirected all the time
|
// Mimic https responses to avoid being redirected all the time
|
||||||
const app = supertest.agent(HBApp).set('X-Forwarded-Proto', 'https');
|
const app = supertest.agent(HBApp).set('X-Forwarded-Proto', 'https');
|
||||||
|
|
||||||
|
let dbState;
|
||||||
|
|
||||||
describe('Tests for admin api', ()=>{
|
describe('Tests for admin api', ()=>{
|
||||||
|
beforeEach(()=>{
|
||||||
|
// Mock DB ready (for dbCheck middleware)
|
||||||
|
dbState = mongoose.connection.readyState;
|
||||||
|
mongoose.connection.readyState = 1;
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(()=>{
|
afterEach(()=>{
|
||||||
|
// Restore DB ready state
|
||||||
|
mongoose.connection.readyState = dbState;
|
||||||
|
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user