mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-10 01:16:39 +02:00
This PR is part of #4380 - Remove legacy `/api/feature` endpoint. ## About the changes ### Frontend - Removes the useFeatures hook - Removes the part of StrategyView that displays features using this strategy (not been working since v4.4) - Removes 2 unused features entries from routes ### Backend - Removes the /api/admin/features endpoint - Moves a couple of non-feature related tests (auth etc) to use /admin/projects endpoint instead - Removes a test that was directly related to the removed endpoint - Moves a couple of tests to the projects/features endpoint - Reworks some tests to fetch features from projects features endpoint and strategies from project strategies
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { setupAppWithCustomAuth } from '../../helpers/test-helper';
|
|
import AuthenticationRequired from '../../../../lib/types/authentication-required';
|
|
|
|
import dbInit, { type ITestDb } from '../../helpers/database-init';
|
|
import getLogger from '../../../fixtures/no-logger';
|
|
import type { IUnleashStores } from '../../../../lib/types';
|
|
|
|
let stores: IUnleashStores;
|
|
let db: ITestDb;
|
|
|
|
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/projects/default/features').expect(401);
|
|
await destroy();
|
|
});
|
|
|
|
test('creates new feature flag 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 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(email);
|
|
});
|
|
|
|
await destroy();
|
|
});
|