1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

fix: copy feature variants (#1750)

* fix: copy feature variants

* add e2e test for cloning with variants
This commit is contained in:
Nuno Góis 2022-06-28 07:54:09 +01:00 committed by GitHub
parent f96b4525a5
commit b49654c3f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 3 deletions

View File

@ -192,6 +192,7 @@ export default class FeatureToggleStore implements IFeatureToggleStore {
stale: data.stale,
created_at: data.createdAt,
impression_data: data.impressionData,
variants: JSON.stringify(data.variants),
};
if (!row.created_at) {
delete row.created_at;

View File

@ -92,6 +92,12 @@ export const featureMetadataSchema = joi
.default(false)
.optional(),
createdAt: joi.date().optional().allow(null),
variants: joi
.array()
.allow(null)
.unique((a, b) => a.name === b.name)
.optional()
.items(variantsSchema),
})
.options({ allowUnknown: false, stripUnknown: true, abortEarly: false });

View File

@ -47,13 +47,13 @@ export interface FeatureToggleDTO {
archived?: boolean;
createdAt?: Date;
impressionData?: boolean;
variants?: IVariant[];
}
export interface FeatureToggle extends FeatureToggleDTO {
project: string;
lastSeenAt?: Date;
createdAt?: Date;
variants?: IVariant[];
}
export interface IFeatureToggleClient {

View File

@ -1701,10 +1701,63 @@ test('should clone feature toggle WITH strategies', async () => {
});
});
test('should clone feature toggle without replacing groupId', async () => {
const envName = 'default';
test('should clone feature toggle WITH variants', async () => {
const envName = 'some-env-5';
const featureName = 'feature.toggle.base.3';
const cloneName = 'feature.toggle.clone.3';
const type = 'eExperiment';
const description = 'Lorem ipsum...';
const variants = [
{ name: 'variant1', weight: 50 },
{ name: 'variant2', weight: 50 },
];
// Create environment
await db.stores.environmentStore.create({
name: envName,
type: 'production',
});
// Connect environment to project
await app.request
.post('/api/admin/projects/default/environments')
.send({
environment: envName,
})
.expect(200);
await app.request
.post('/api/admin/projects/default/features')
.send({
name: featureName,
description,
type,
variants,
})
.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(res.body.variants).toHaveLength(2);
res.body.variants.forEach((variant, i) => {
expect(variant.name).toBe(variants[i].name);
});
});
});
test('should clone feature toggle without replacing groupId', async () => {
const envName = 'default';
const featureName = 'feature.toggle.base.4';
const cloneName = 'feature.toggle.clone.4';
await app.request
.post('/api/admin/projects/default/features')