From d7a082d4772db338f15b6f34881eadbea6723597 Mon Sep 17 00:00:00 2001 From: Fredrik Oseberg Date: Fri, 28 Jan 2022 12:23:58 +0100 Subject: [PATCH] fix: add tests for impressionData --- .../api/admin/project/features.e2e.test.ts | 56 ++++++++++++++++++- src/test/e2e/api/client/feature.e2e.test.ts | 19 +++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/test/e2e/api/admin/project/features.e2e.test.ts b/src/test/e2e/api/admin/project/features.e2e.test.ts index 449a5d87f7..6681f15a82 100644 --- a/src/test/e2e/api/admin/project/features.e2e.test.ts +++ b/src/test/e2e/api/admin/project/features.e2e.test.ts @@ -512,13 +512,19 @@ test('Should patch feature toggle', async () => { const name = 'new.toggle.patch'; await app.request .post(url) - .send({ name, description: 'some', type: 'release' }) + .send({ + name, + description: 'some', + type: 'release', + impressionData: true, + }) .expect(201); await app.request .patch(`${url}/${name}`) .send([ { op: 'replace', path: '/description', value: 'New desc' }, { op: 'replace', path: '/type', value: 'kill-switch' }, + { op: 'replace', path: '/impressionData', value: false }, ]) .expect(200); @@ -527,6 +533,7 @@ test('Should patch feature toggle', async () => { expect(toggle.name).toBe(name); expect(toggle.description).toBe('New desc'); expect(toggle.type).toBe('kill-switch'); + expect(toggle.impressionData).toBe(false); expect(toggle.archived).toBeFalsy(); const events = await db.stores.eventStore.getAll({ type: FEATURE_METADATA_UPDATED, @@ -1983,3 +1990,50 @@ test('should not update project with PATCH', async () => { }) .expect(200); }); + +test('Can create a feature with impression data', async () => { + await app.request + .post('/api/admin/projects/default/features') + .send({ + name: 'new.toggle.with.impressionData', + impressionData: true, + }) + .expect(201) + .expect((res) => { + expect(res.body.impressionData).toBe(true); + }); +}); + +test('Can create a feature without impression data', async () => { + await app.request + .post('/api/admin/projects/default/features') + .send({ + name: 'new.toggle.without.impressionData', + }) + .expect(201) + .expect((res) => { + expect(res.body.impressionData).toBe(false); + }); +}); + +test('Can update impression data with PUT', async () => { + const toggle = { + name: 'update.toggle.with.impressionData', + impressionData: true, + }; + await app.request + .post('/api/admin/projects/default/features') + .send(toggle) + .expect(201) + .expect((res) => { + expect(res.body.impressionData).toBe(true); + }); + + await app.request + .put(`/api/admin/projects/default/features/${toggle.name}`) + .send({ ...toggle, impressionData: false }) + .expect(200) + .expect((res) => { + expect(res.body.impressionData).toBe(false); + }); +}); diff --git a/src/test/e2e/api/client/feature.e2e.test.ts b/src/test/e2e/api/client/feature.e2e.test.ts index d1ffe22886..4c6207becf 100644 --- a/src/test/e2e/api/client/feature.e2e.test.ts +++ b/src/test/e2e/api/client/feature.e2e.test.ts @@ -14,6 +14,7 @@ beforeAll(async () => { { name: 'featureX', description: 'the #1 feature', + impressionData: true, }, 'test', ); @@ -134,6 +135,24 @@ test('gets a feature by name', async () => { .expect(200); }); +test('returns a feature toggles impression data', async () => { + return app.request + .get('/api/client/features/featureX') + .expect('Content-Type', /json/) + .expect((res) => { + expect(res.body.impressionData).toBe(true); + }); +}); + +test('returns a false for impression data when not specified', async () => { + return app.request + .get('/api/client/features/featureZ') + .expect('Content-Type', /json/) + .expect((res) => { + expect(res.body.impressionData).toBe(false); + }); +}); + test('cant get feature that does not exist', async () => { return app.request .get('/api/client/features/myfeature')