2019-03-14 17:56:02 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const test = require('ava');
|
|
|
|
const importData = require('../../../examples/import.json');
|
2019-10-03 15:01:33 +02:00
|
|
|
const dbInit = require('../../helpers/database-init');
|
|
|
|
const { setupApp } = require('../../helpers/test-helper');
|
|
|
|
const getLogger = require('../../../fixtures/no-logger');
|
|
|
|
|
|
|
|
let stores;
|
|
|
|
|
|
|
|
test.before(async () => {
|
|
|
|
const db = await dbInit('state_api_serial', getLogger);
|
|
|
|
stores = db.stores;
|
|
|
|
});
|
|
|
|
|
|
|
|
test.after(async () => {
|
|
|
|
await stores.db.destroy();
|
|
|
|
});
|
2019-03-14 17:56:02 +01:00
|
|
|
|
|
|
|
test.serial('exports strategies and features as json by default', async t => {
|
|
|
|
t.plan(2);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2019-03-14 17:56:02 +01:00
|
|
|
return request
|
|
|
|
.get('/api/admin/state/export')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
.expect(res => {
|
|
|
|
t.true('features' in res.body);
|
|
|
|
t.true('strategies' in res.body);
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2019-03-14 17:56:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('exports strategies and features as yaml', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2019-03-14 17:56:02 +01:00
|
|
|
return request
|
|
|
|
.get('/api/admin/state/export?format=yaml')
|
|
|
|
.expect('Content-Type', /yaml/)
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(200);
|
2019-03-14 17:56:02 +01:00
|
|
|
});
|
|
|
|
|
2020-07-30 23:57:13 +02:00
|
|
|
test.serial('exports only features as yaml', async t => {
|
|
|
|
t.plan(0);
|
|
|
|
const request = await setupApp(stores);
|
|
|
|
return request
|
|
|
|
.get('/api/admin/state/export?format=yaml&featureToggles=1')
|
|
|
|
.expect('Content-Type', /yaml/)
|
|
|
|
.expect(200);
|
|
|
|
});
|
|
|
|
|
2019-03-14 17:56:02 +01:00
|
|
|
test.serial('exports strategies and features as attachment', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2019-03-14 17:56:02 +01:00
|
|
|
return request
|
|
|
|
.get('/api/admin/state/export?download=1')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Content-Disposition', /attachment/)
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(200);
|
2019-03-14 17:56:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('imports strategies and features', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2019-03-14 17:56:02 +01:00
|
|
|
return request
|
|
|
|
.post('/api/admin/state/import')
|
|
|
|
.send(importData)
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(202);
|
2019-03-14 17:56:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('does not not accept gibberish', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2019-03-14 17:56:02 +01:00
|
|
|
return request
|
|
|
|
.post('/api/admin/state/import')
|
|
|
|
.send({ features: 'nonsense' })
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(400);
|
2019-03-14 17:56:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('imports strategies and features from json file', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2019-03-14 17:56:02 +01:00
|
|
|
return request
|
|
|
|
.post('/api/admin/state/import')
|
|
|
|
.attach('file', 'test/examples/import.json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(202);
|
2019-03-14 17:56:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('imports strategies and features from yaml file', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2019-03-14 17:56:02 +01:00
|
|
|
return request
|
|
|
|
.post('/api/admin/state/import')
|
|
|
|
.attach('file', 'test/examples/import.yml')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(202);
|
2019-03-14 17:56:02 +01:00
|
|
|
});
|