From bf451f65490288fc820a226aeda5b66f9aa4411a Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Thu, 14 Sep 2023 09:50:20 +0200 Subject: [PATCH] test: enforce behavior via test (#4701) This test enforces that descriptions and examples are cleared if they are not present in the feature naming data. This behavior is already present, but it hasn't been encoded in any tests before. --- .../e2e/services/project-service.e2e.test.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/test/e2e/services/project-service.e2e.test.ts b/src/test/e2e/services/project-service.e2e.test.ts index d0692867f3..cd860a93f1 100644 --- a/src/test/e2e/services/project-service.e2e.test.ts +++ b/src/test/e2e/services/project-service.e2e.test.ts @@ -1777,3 +1777,43 @@ test('should return average time to production per toggle and include archived t expect(resultProject1.features).toHaveLength(3); }); + +describe('feature flag naming patterns', () => { + test(`should clear existing example and description if the payload doesn't contain them`, async () => { + const featureNaming = { + pattern: '.+', + example: 'example', + description: 'description', + }; + + const project = { + id: 'feature-flag-naming-patterns-cleanup', + name: 'Project', + mode: 'open' as const, + defaultStickiness: 'clientId', + description: 'description', + featureNaming, + }; + + await projectService.createProject(project, user.id); + + expect( + (await projectService.getProject(project.id)).featureNaming, + ).toMatchObject(featureNaming); + + const newPattern = 'new-pattern.+'; + await projectService.updateProject( + { + ...project, + featureNaming: { pattern: newPattern }, + }, + user.id, + ); + + const updatedProject = await projectService.getProject(project.id); + + expect(updatedProject.featureNaming!.pattern).toBe(newPattern); + expect(updatedProject.featureNaming!.example).toBeFalsy(); + expect(updatedProject.featureNaming!.description).toBeFalsy(); + }); +});