-
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a361dbd
commit 9494c74
Showing
2 changed files
with
115 additions
and
11 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...eatures/client-feature-toggles/tests/__snapshots__/client-feature-toggle.e2e.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should match snapshot from /api/client/features 1`] = ` | ||
{ | ||
"features": [ | ||
{ | ||
"description": null, | ||
"enabled": false, | ||
"impressionData": false, | ||
"name": "test1", | ||
"project": "default", | ||
"stale": false, | ||
"strategies": [ | ||
{ | ||
"constraints": [], | ||
"name": "flexibleRollout", | ||
"parameters": { | ||
"groupId": "test1", | ||
"rollout": "100", | ||
"stickiness": "default", | ||
}, | ||
"variants": [], | ||
}, | ||
], | ||
"type": "release", | ||
"variants": [], | ||
}, | ||
{ | ||
"description": null, | ||
"enabled": false, | ||
"impressionData": false, | ||
"name": "test2", | ||
"project": "default", | ||
"stale": false, | ||
"strategies": [ | ||
{ | ||
"constraints": [ | ||
{ | ||
"contextName": "userId", | ||
"operator": "IN", | ||
"values": [ | ||
"123", | ||
], | ||
}, | ||
], | ||
"name": "default", | ||
"parameters": {}, | ||
"variants": [], | ||
}, | ||
], | ||
"type": "release", | ||
"variants": [], | ||
}, | ||
], | ||
"meta": { | ||
"etag": ""61824cd0:11"", | ||
"queryHash": "61824cd0", | ||
"revisionId": 11, | ||
}, | ||
"query": { | ||
"environment": "default", | ||
"inlineSegmentConstraints": true, | ||
}, | ||
"version": 2, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,15 @@ let proApp: IUnleashTest; | |
let proDb: ITestDb; | ||
let enterpriseApp: IUnleashTest; | ||
let enterpriseDb: ITestDb; | ||
let enterpriseDummyAdmin: IUserWithRootRole; | ||
let proDummyAdmin: IUserWithRootRole; | ||
|
||
const apiClientResponse = [ | ||
const getApiClientResponse = (project = 'default') => [ | ||
{ | ||
name: 'test1', | ||
type: 'release', | ||
enabled: false, | ||
project: 'default', | ||
project: project, | ||
stale: false, | ||
strategies: [ | ||
{ | ||
|
@@ -45,7 +47,7 @@ const apiClientResponse = [ | |
name: 'test2', | ||
type: 'release', | ||
enabled: false, | ||
project: 'default', | ||
project: project, | ||
stale: false, | ||
strategies: [ | ||
{ | ||
|
@@ -82,11 +84,15 @@ const cleanup = async (db: ITestDb, app: IUnleashTest) => { | |
); | ||
}; | ||
|
||
const setupFeatures = async (db: ITestDb, app: IUnleashTest) => { | ||
const setupFeatures = async ( | ||
db: ITestDb, | ||
app: IUnleashTest, | ||
project = 'default', | ||
) => { | ||
await db.rawDatabase.raw('DELETE FROM features'); | ||
|
||
await app.createFeature('test1', 'default'); | ||
await app.createFeature('test2', 'default'); | ||
await app.createFeature('test1', project); | ||
await app.createFeature('test2', project); | ||
|
||
await app.addStrategyToFeatureEnv( | ||
{ | ||
|
@@ -100,6 +106,7 @@ const setupFeatures = async (db: ITestDb, app: IUnleashTest) => { | |
}, | ||
DEFAULT_ENV, | ||
'test1', | ||
project, | ||
); | ||
await app.addStrategyToFeatureEnv( | ||
{ | ||
|
@@ -111,6 +118,7 @@ const setupFeatures = async (db: ITestDb, app: IUnleashTest) => { | |
}, | ||
DEFAULT_ENV, | ||
'test2', | ||
project, | ||
); | ||
}; | ||
|
||
|
@@ -168,6 +176,24 @@ beforeAll(async () => { | |
}, | ||
TEST_AUDIT_USER, | ||
); | ||
|
||
enterpriseDummyAdmin = await enterpriseApp.services.userService.createUser( | ||
{ | ||
name: 'Some Name', | ||
email: '[email protected]', | ||
rootRole: RoleName.ADMIN, | ||
}, | ||
TEST_AUDIT_USER, | ||
); | ||
|
||
proDummyAdmin = await proApp.services.userService.createUser( | ||
{ | ||
name: 'Some Name', | ||
email: '[email protected]', | ||
rootRole: RoleName.ADMIN, | ||
}, | ||
TEST_AUDIT_USER, | ||
); | ||
}); | ||
|
||
afterEach(async () => { | ||
|
@@ -249,29 +275,41 @@ test('should return correct data structure from /api/client/features', async () | |
.expect('Content-Type', /json/) | ||
.expect(200); | ||
|
||
expect(result.body.features).toEqual(apiClientResponse); | ||
expect(result.body.features).toEqual(getApiClientResponse()); | ||
}); | ||
|
||
test('should return correct data structure from /api/client/features for pro', async () => { | ||
await setupFeatures(proDb, proApp); | ||
await proApp.services.projectService.createProject( | ||
{ name: 'Pro', id: 'pro' }, | ||
proDummyAdmin, | ||
TEST_AUDIT_USER, | ||
); | ||
|
||
await setupFeatures(proDb, proApp, 'pro'); | ||
|
||
const result = await proApp.request | ||
.get('/api/client/features') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
|
||
expect(result.body.features).toEqual(apiClientResponse); | ||
expect(result.body.features).toEqual(getApiClientResponse('pro')); | ||
}); | ||
|
||
test('should return correct data structure from /api/client/features for Enterprise', async () => { | ||
await setupFeatures(enterpriseDb, enterpriseApp); | ||
await enterpriseApp.services.projectService.createProject( | ||
{ name: 'Enterprise', id: 'enterprise' }, | ||
enterpriseDummyAdmin, | ||
TEST_AUDIT_USER, | ||
); | ||
|
||
await setupFeatures(enterpriseDb, enterpriseApp, 'enterprise'); | ||
|
||
const result = await enterpriseApp.request | ||
.get('/api/client/features') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
|
||
expect(result.body.features).toEqual(apiClientResponse); | ||
expect(result.body.features).toEqual(getApiClientResponse('enterprise')); | ||
}); | ||
|
||
test('should match snapshot from /api/client/features', async () => { | ||
|