1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-18 01:18:23 +02:00
unleash.unleash/src/test/e2e/api/admin/feature.auth.e2e.test.ts
Jaanus Sellin 627768b96c
feat: start using event service composition root (#7871)
During adding privateProjectsChecker, I saw that events composition root
is not used almost at all.
Refactored code so we do not call new EventService anymore.
2024-08-15 08:33:46 +03:00

52 lines
1.3 KiB
TypeScript

import { setupAppWithAuth } from '../../helpers/test-helper';
import dbInit, { type ITestDb } from '../../helpers/database-init';
import getLogger from '../../../fixtures/no-logger';
let db: ITestDb;
beforeAll(async () => {
db = await dbInit('feature_api_auth', getLogger);
});
afterAll(async () => {
await db.destroy();
});
test('creates new feature flag with createdBy', async () => {
expect.assertions(1);
const { request, destroy } = await setupAppWithAuth(
db.stores,
{},
db.rawDatabase,
);
// Login
await request.post('/auth/demo/login').send({
email: 'user@mail.com',
});
// create flag
await request
.post('/api/admin/projects/default/features')
.send({
name: 'com.test.Username',
enabled: false,
strategies: [{ name: 'default' }],
})
.expect(201);
await request.get('/api/admin/events/com.test.Username').expect((res) => {
expect(res.body.events[0].createdBy).toBe('user@mail.com');
});
await destroy();
});
test('should require authenticated user', async () => {
expect.assertions(0);
const { request, destroy } = await setupAppWithAuth(db.stores);
await request.get('/api/admin/projects/default/features').expect(401);
await destroy();
});