-
-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sdk reporting flag and e2e test (#6216)
1. Add flag 2. Add e2e test with more complete example 3. Some bug fixes
- Loading branch information
Showing
9 changed files
with
229 additions
and
36 deletions.
There are no files selected for viewing
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
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
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
179 changes: 179 additions & 0 deletions
179
src/lib/features/project/project-applications.e2e.test.ts
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,179 @@ | ||
import dbInit, { ITestDb } from '../../../test/e2e/helpers/database-init'; | ||
import { | ||
IUnleashTest, | ||
setupAppWithCustomConfig, | ||
} from '../../../test/e2e/helpers/test-helper'; | ||
import getLogger from '../../../test/fixtures/no-logger'; | ||
|
||
import { ApiTokenType, IApiToken } from '../../types/models/api-token'; | ||
|
||
let app: IUnleashTest; | ||
let db: ITestDb; | ||
let defaultToken: IApiToken; | ||
|
||
const metrics = { | ||
appName: 'appName', | ||
instanceId: 'instanceId', | ||
bucket: { | ||
start: '2016-11-03T07:16:43.572Z', | ||
stop: '2016-11-03T07:16:53.572Z', | ||
toggles: { | ||
'toggle-name-1': { | ||
yes: 123, | ||
no: 321, | ||
variants: { | ||
'variant-1': 123, | ||
'variant-2': 321, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
beforeAll(async () => { | ||
db = await dbInit('projects_applications_serial', getLogger); | ||
app = await setupAppWithCustomConfig( | ||
db.stores, | ||
{ | ||
experimental: { | ||
flags: { | ||
strictSchemaValidation: true, | ||
sdkReporting: true, | ||
}, | ||
}, | ||
}, | ||
db.rawDatabase, | ||
); | ||
defaultToken = | ||
await app.services.apiTokenService.createApiTokenWithProjects({ | ||
type: ApiTokenType.CLIENT, | ||
projects: ['default'], | ||
environment: 'default', | ||
tokenName: 'tester', | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
await db.stores.clientMetricsStoreV2.deleteAll(); | ||
await db.stores.clientInstanceStore.deleteAll(); | ||
await db.stores.featureToggleStore.deleteAll(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.destroy(); | ||
await db.destroy(); | ||
}); | ||
|
||
test('should return applications', async () => { | ||
await app.createFeature('toggle-name-1'); | ||
|
||
await app.request.post('/api/client/register').send({ | ||
appName: metrics.appName, | ||
instanceId: metrics.instanceId, | ||
strategies: ['default'], | ||
sdkVersion: 'unleash-client-test:1.2', | ||
started: Date.now(), | ||
interval: 10, | ||
}); | ||
await app.services.clientInstanceService.bulkAdd(); | ||
await app.request | ||
.post('/api/client/metrics') | ||
.set('Authorization', defaultToken.secret) | ||
.send(metrics) | ||
.expect(202); | ||
|
||
await app.services.clientMetricsServiceV2.bulkAdd(); | ||
|
||
const { body } = await app.request | ||
.get('/api/admin/projects/default/applications') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
|
||
expect(body).toMatchObject([ | ||
{ | ||
environments: ['default'], | ||
instances: ['instanceId'], | ||
name: 'appName', | ||
sdks: [ | ||
{ | ||
name: 'unleash-client-test', | ||
versions: ['1.2'], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
test('should return applications if sdk was not in database', async () => { | ||
await app.createFeature('toggle-name-1'); | ||
|
||
await app.request.post('/api/client/register').send({ | ||
appName: metrics.appName, | ||
instanceId: metrics.instanceId, | ||
strategies: ['default'], | ||
started: Date.now(), | ||
interval: 10, | ||
}); | ||
await app.services.clientInstanceService.bulkAdd(); | ||
await app.request | ||
.post('/api/client/metrics') | ||
.set('Authorization', defaultToken.secret) | ||
.send(metrics) | ||
.expect(202); | ||
|
||
await app.services.clientMetricsServiceV2.bulkAdd(); | ||
|
||
const { body } = await app.request | ||
.get('/api/admin/projects/default/applications') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
|
||
expect(body).toMatchObject([ | ||
{ | ||
environments: ['default'], | ||
instances: ['instanceId'], | ||
name: 'appName', | ||
sdks: [], | ||
}, | ||
]); | ||
}); | ||
|
||
test('should return application without version if sdk has just name', async () => { | ||
await app.createFeature('toggle-name-1'); | ||
|
||
await app.request.post('/api/client/register').send({ | ||
appName: metrics.appName, | ||
instanceId: metrics.instanceId, | ||
strategies: ['default'], | ||
sdkVersion: 'unleash-client-test', | ||
started: Date.now(), | ||
interval: 10, | ||
}); | ||
await app.services.clientInstanceService.bulkAdd(); | ||
await app.request | ||
.post('/api/client/metrics') | ||
.set('Authorization', defaultToken.secret) | ||
.send(metrics) | ||
.expect(202); | ||
|
||
await app.services.clientMetricsServiceV2.bulkAdd(); | ||
|
||
const { body } = await app.request | ||
.get('/api/admin/projects/default/applications') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
|
||
expect(body).toMatchObject([ | ||
{ | ||
environments: ['default'], | ||
instances: ['instanceId'], | ||
name: 'appName', | ||
sdks: [ | ||
{ | ||
name: 'unleash-client-test', | ||
versions: [], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); |
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
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
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
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
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