0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-22 11:08:10 +00:00

Mock DB ready state for Admin API tests

This commit is contained in:
G.Ambatte
2025-12-30 10:38:58 +13:00
parent 859dbea0bc
commit 99d320e6a2

View File

@@ -1,4 +1,5 @@
/*eslint max-lines: ["warn", {"max": 1000, "skipBlankLines": true, "skipComments": true}]*/
import mongoose from 'mongoose';
import supertest from 'supertest';
import HBApp from './app.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
const app = supertest.agent(HBApp).set('X-Forwarded-Proto', 'https');
let dbState;
describe('Tests for admin api', ()=>{
beforeEach(()=>{
// Mock DB ready (for dbCheck middleware)
dbState = mongoose.connection.readyState;
mongoose.connection.readyState = 1;
});
afterEach(()=>{
// Restore DB ready state
mongoose.connection.readyState = dbState;
jest.resetAllMocks();
});