2017-11-16 16:45:01 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 09:24:49 +01:00
|
|
|
const test = require('ava');
|
2020-04-14 22:29:11 +02:00
|
|
|
const { setupAppWithAuth } = require('../../helpers/test-helper');
|
2019-10-03 15:01:33 +02:00
|
|
|
const dbInit = require('../../helpers/database-init');
|
|
|
|
const getLogger = require('../../../fixtures/no-logger');
|
|
|
|
|
|
|
|
let stores;
|
|
|
|
|
|
|
|
test.before(async () => {
|
|
|
|
const db = await dbInit('feature_api_auth', getLogger);
|
|
|
|
stores = db.stores;
|
|
|
|
});
|
|
|
|
|
|
|
|
test.after(async () => {
|
|
|
|
await stores.db.destroy();
|
|
|
|
});
|
2017-11-16 16:45:01 +01:00
|
|
|
|
|
|
|
test.serial('creates new feature toggle with createdBy', async t => {
|
|
|
|
t.plan(1);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupAppWithAuth(stores);
|
2017-11-16 16:45:01 +01:00
|
|
|
// Login
|
|
|
|
await request.post('/api/admin/login').send({
|
|
|
|
email: 'user@mail.com',
|
|
|
|
});
|
|
|
|
|
|
|
|
// create toggle
|
|
|
|
await request.post('/api/admin/features').send({
|
|
|
|
name: 'com.test.Username',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
|
|
|
|
2019-10-03 15:01:33 +02:00
|
|
|
await request.get('/api/admin/events').expect(res => {
|
|
|
|
t.true(res.body.events[0].createdBy === 'user@mail.com');
|
|
|
|
});
|
2017-11-16 16:45:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('should require authenticated user', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupAppWithAuth(stores);
|
|
|
|
return request.get('/api/admin/features').expect(401);
|
2017-11-16 16:45:01 +01:00
|
|
|
});
|