2022-12-21 12:23:44 +01:00
|
|
|
import dbInit, { ITestDb } from '../../helpers/database-init';
|
2023-02-27 14:36:56 +01:00
|
|
|
import { setupApp, setupAppWithCustomConfig } from '../../helpers/test-helper';
|
2022-12-21 12:23:44 +01:00
|
|
|
import getLogger from '../../../fixtures/no-logger';
|
|
|
|
|
|
|
|
let db: ITestDb;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
db = await dbInit('maintenance_api_serial', getLogger);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await db.stores.featureToggleStore.deleteAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await db.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not allow to create feature toggles in maintenance mode', async () => {
|
|
|
|
const appWithMaintenanceMode = await setupAppWithCustomConfig(db.stores, {
|
|
|
|
experimental: {
|
|
|
|
flags: {
|
|
|
|
maintenanceMode: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return appWithMaintenanceMode.request
|
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'maintenance-feature',
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(503);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('maintenance mode is off by default', async () => {
|
2023-02-27 14:36:56 +01:00
|
|
|
const appWithMaintenanceMode = await setupApp(db.stores);
|
2022-12-21 12:23:44 +01:00
|
|
|
|
|
|
|
return appWithMaintenanceMode.request
|
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'maintenance-feature1',
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(201);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should go into maintenance mode, when user has set it', async () => {
|
2023-02-27 14:36:56 +01:00
|
|
|
const appWithMaintenanceMode = await setupApp(db.stores);
|
2022-12-21 12:23:44 +01:00
|
|
|
|
|
|
|
await appWithMaintenanceMode.request
|
|
|
|
.post('/api/admin/maintenance')
|
|
|
|
.send({
|
|
|
|
enabled: true,
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(204);
|
|
|
|
|
|
|
|
return appWithMaintenanceMode.request
|
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'maintenance-feature1',
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(503);
|
|
|
|
});
|
|
|
|
test('maintenance mode flag should take precedence over maintenance mode setting', async () => {
|
|
|
|
const appWithMaintenanceMode = await setupAppWithCustomConfig(db.stores, {
|
|
|
|
experimental: {
|
|
|
|
flags: {
|
|
|
|
maintenanceMode: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await appWithMaintenanceMode.request
|
|
|
|
.post('/api/admin/maintenance')
|
|
|
|
.send({
|
|
|
|
enabled: false,
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(204);
|
|
|
|
|
|
|
|
return appWithMaintenanceMode.request
|
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'maintenance-feature1',
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(503);
|
|
|
|
});
|