Skip to content

Commit

Permalink
fix: clone feature toggle should not copy createdAt (#6442)
Browse files Browse the repository at this point in the history
This is a small fix to avoid that cloning a feature toggle also clones
the "createdAt" field, which does not make sense.

fixes: #6426
  • Loading branch information
ivarconr committed Mar 6, 2024
1 parent e7abdc6 commit 2185742
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/features/feature-toggle/feature-toggle-service.ts
Expand Up @@ -1324,6 +1324,7 @@ class FeatureToggleService {
...cToggle,
name: newFeatureName,
variants: undefined,
createdAt: undefined,
};
const created = await this.createFeatureToggle(
projectId,
Expand Down
36 changes: 36 additions & 0 deletions src/lib/features/feature-toggle/tests/feature-toggles.e2e.test.ts
Expand Up @@ -2191,6 +2191,42 @@ test('should clone feature toggle without replacing groupId', async () => {
});
});

test('should clone feature toggle WITHOUT createdAt field', async () => {
const featureName = 'feature.toggle.base.5';
const cloneName = 'feature.toggle.clone.5';
const type = 'eExperiment';
const description = 'Lorem ipsum...';
const originalCreatedAt = new Date(2011, 11, 11);

await app.request
.post('/api/admin/projects/default/features')
.send({
name: featureName,
description,
type,
createdAt: originalCreatedAt,
})
.expect(201);

await app.request
.post(`/api/admin/projects/default/features/${featureName}/clone`)
.send({ name: cloneName })
.expect(201);
await app.request
.get(`/api/admin/projects/default/features/${cloneName}`)
.expect(200)
.expect((res) => {
expect(res.body.name).toBe(cloneName);
expect(res.body.type).toBe(type);
expect(res.body.project).toBe('default');
expect(res.body.description).toBe(description);
expect(new Date(res.body.createdAt).getFullYear()).toBe(
new Date().getFullYear(),
);
expect(res.body.createdAt).not.toBe('2011-12-11T00:00:00.000Z');
});
});

test('Should not allow changing project to target project without the same enabled environments', async () => {
const envNameNotInBoth = 'not-in-both';
const featureName = 'feature.dont.allow.change.project';
Expand Down

0 comments on commit 2185742

Please sign in to comment.