Skip to content

Commit

Permalink
test: advanced playground (#3968)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Jun 14, 2023
1 parent b91b727 commit edd67f7
Show file tree
Hide file tree
Showing 2 changed files with 254 additions and 142 deletions.
254 changes: 254 additions & 0 deletions src/lib/features/playground/advanced-playground.test.ts
@@ -0,0 +1,254 @@
import {
IUnleashTest,
setupAppWithCustomConfig,
} from '../../../test/e2e/helpers/test-helper';
import dbInit, { ITestDb } from '../../../test/e2e/helpers/database-init';
import getLogger from '../../../test/fixtures/no-logger';

let app: IUnleashTest;
let db: ITestDb;

beforeAll(async () => {
db = await dbInit('advanced_playground', getLogger);
app = await setupAppWithCustomConfig(
db.stores,
{
experimental: {
flags: {
advancedPlayground: true,
},
},
},
db.rawDatabase,
);
});

const createFeatureToggle = async (featureName: string) => {
await app.request
.post('/api/admin/projects/default/features')
.send({
name: featureName,
})
.set('Content-Type', 'application/json')
.expect(201);
};

const createFeatureToggleWithStrategy = async (featureName: string) => {
await createFeatureToggle(featureName);
return app.request
.post(
`/api/admin/projects/default/features/${featureName}/environments/default/strategies`,
)
.send({
name: 'default',
parameters: {},
})
.expect(200);
};

const enableToggle = (featureName: string) =>
app.request
.post(
`/api/admin/projects/default/features/${featureName}/environments/default/on`,
)
.send({})
.expect(200);

afterAll(async () => {
await app.destroy();
await db.destroy();
});

test('advanced playground evaluation with no toggles', async () => {
const { body: result } = await app.request
.post('/api/admin/playground/advanced')
.send({
environments: ['default'],
projects: ['default'],
context: { appName: 'test', userId: '1,2', channel: 'web,mobile' },
})
.set('Content-Type', 'application/json')
.expect(200);

expect(result).toMatchObject({
input: {
environments: ['default'],
projects: ['default'],
context: {
appName: 'test',
userId: '1,2',
channel: 'web,mobile',
},
},
features: [],
});
});

test('advanced playground evaluation happy path', async () => {
await createFeatureToggleWithStrategy('test-playground-feature');
await enableToggle('test-playground-feature');

const { body: result } = await app.request
.post('/api/admin/playground/advanced')
.send({
environments: ['default'],
projects: ['default'],
context: { appName: 'test', userId: '1,2', channel: 'web,mobile' },
})
.set('Content-Type', 'application/json')
.expect(200);

expect(result).toMatchObject({
input: {
environments: ['default'],
projects: ['default'],
context: {
appName: 'test',
userId: '1,2',
channel: 'web,mobile',
},
},
features: [
{
name: 'test-playground-feature',
projectId: 'default',
environments: {
default: [
{
isEnabled: true,
isEnabledInCurrentEnvironment: true,
strategies: {
result: true,
data: [
{
name: 'default',
disabled: false,
parameters: {},
result: {
enabled: true,
evaluationStatus: 'complete',
},
constraints: [],
segments: [],
},
],
},
projectId: 'default',
variant: {
name: 'disabled',
enabled: false,
},
name: 'test-playground-feature',
environment: 'default',
context: {
appName: 'test',
userId: '1',
channel: 'web',
},
variants: [],
},
{
isEnabled: true,
isEnabledInCurrentEnvironment: true,
strategies: {
result: true,
data: [
{
name: 'default',
disabled: false,
parameters: {},
result: {
enabled: true,
evaluationStatus: 'complete',
},
constraints: [],
segments: [],
},
],
},
projectId: 'default',
variant: {
name: 'disabled',
enabled: false,
},
name: 'test-playground-feature',
environment: 'default',
context: {
appName: 'test',
userId: '1',
channel: 'mobile',
},
variants: [],
},
{
isEnabled: true,
isEnabledInCurrentEnvironment: true,
strategies: {
result: true,
data: [
{
name: 'default',
disabled: false,
parameters: {},
result: {
enabled: true,
evaluationStatus: 'complete',
},
constraints: [],
segments: [],
},
],
},
projectId: 'default',
variant: {
name: 'disabled',
enabled: false,
},
name: 'test-playground-feature',
environment: 'default',
context: {
appName: 'test',
userId: '2',
channel: 'web',
},
variants: [],
},
{
isEnabled: true,
isEnabledInCurrentEnvironment: true,
strategies: {
result: true,
data: [
{
name: 'default',
disabled: false,
parameters: {},
result: {
enabled: true,
evaluationStatus: 'complete',
},
constraints: [],
segments: [],
},
],
},
projectId: 'default',
variant: {
name: 'disabled',
enabled: false,
},
name: 'test-playground-feature',
environment: 'default',
context: {
appName: 'test',
userId: '2',
channel: 'mobile',
},
variants: [],
},
],
},
},
],
});
});
142 changes: 0 additions & 142 deletions src/lib/features/playground/hardcodedReponse.ts

This file was deleted.

0 comments on commit edd67f7

Please sign in to comment.