1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/src/test/e2e/api/admin/feature.custom-auth.e2e.test.ts
Christopher Kolstad 1fdf68eeec
task: removes deprecated feature api (#3609)
### What
We've had this marked as deprecated through our v4, this PR removes it.

### Worth noting
This updates the deprecation notices with removal notices in the
documentation as well.

### Considerations
The tags API is still located under
/api/admin/features/{featureName}/tags. It should be moved to
/api/admin/projects/{project}/features/{featureName}/tags. I vote we do
that in a separate PR, we'd probably also need to deprecate the existing
tags endpoints for v5 and remove in v6. We could use 308s to signify
that they are moved.

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2023-04-26 10:45:00 +02:00

70 lines
2.0 KiB
TypeScript

import { setupAppWithCustomAuth } from '../../helpers/test-helper';
import AuthenticationRequired from '../../../../lib/types/authentication-required';
import dbInit from '../../helpers/database-init';
import getLogger from '../../../fixtures/no-logger';
let stores;
let db;
beforeAll(async () => {
db = await dbInit('feature_api_custom_auth', getLogger);
stores = db.stores;
});
afterAll(async () => {
if (db) {
await db.destroy();
}
});
test('should require authenticated user', async () => {
expect.assertions(0);
const preHook = (app) => {
app.use('/api/admin/', (req, res) =>
res
.status(401)
.json(
new AuthenticationRequired({
path: '/auth/demo/login',
type: 'custom',
message: 'You have to identify yourself.',
}),
)
.end(),
);
};
const { request, destroy } = await setupAppWithCustomAuth(stores, preHook);
await request.get('/api/admin/features').expect(401);
await destroy();
});
test('creates new feature toggle with createdBy', async () => {
expect.assertions(1);
const email = 'custom-user@mail.com';
const preHook = (app, config, { userService }) => {
app.use('/api/admin/', async (req, res, next) => {
req.user = await userService.loginUserWithoutPassword(email, true);
next();
});
};
const { request, destroy } = await setupAppWithCustomAuth(stores, preHook);
// create toggle
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(email);
});
await destroy();
});