mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-15 17:50:48 +02:00
fix: copy feature variants (#1750)
* fix: copy feature variants * add e2e test for cloning with variants
This commit is contained in:
parent
f96b4525a5
commit
b49654c3f0
@ -192,6 +192,7 @@ export default class FeatureToggleStore implements IFeatureToggleStore {
|
|||||||
stale: data.stale,
|
stale: data.stale,
|
||||||
created_at: data.createdAt,
|
created_at: data.createdAt,
|
||||||
impression_data: data.impressionData,
|
impression_data: data.impressionData,
|
||||||
|
variants: JSON.stringify(data.variants),
|
||||||
};
|
};
|
||||||
if (!row.created_at) {
|
if (!row.created_at) {
|
||||||
delete row.created_at;
|
delete row.created_at;
|
||||||
|
@ -92,6 +92,12 @@ export const featureMetadataSchema = joi
|
|||||||
.default(false)
|
.default(false)
|
||||||
.optional(),
|
.optional(),
|
||||||
createdAt: joi.date().optional().allow(null),
|
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 });
|
.options({ allowUnknown: false, stripUnknown: true, abortEarly: false });
|
||||||
|
|
||||||
|
@ -47,13 +47,13 @@ export interface FeatureToggleDTO {
|
|||||||
archived?: boolean;
|
archived?: boolean;
|
||||||
createdAt?: Date;
|
createdAt?: Date;
|
||||||
impressionData?: boolean;
|
impressionData?: boolean;
|
||||||
|
variants?: IVariant[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FeatureToggle extends FeatureToggleDTO {
|
export interface FeatureToggle extends FeatureToggleDTO {
|
||||||
project: string;
|
project: string;
|
||||||
lastSeenAt?: Date;
|
lastSeenAt?: Date;
|
||||||
createdAt?: Date;
|
createdAt?: Date;
|
||||||
variants?: IVariant[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IFeatureToggleClient {
|
export interface IFeatureToggleClient {
|
||||||
|
@ -1701,10 +1701,63 @@ test('should clone feature toggle WITH strategies', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should clone feature toggle without replacing groupId', async () => {
|
test('should clone feature toggle WITH variants', async () => {
|
||||||
const envName = 'default';
|
const envName = 'some-env-5';
|
||||||
const featureName = 'feature.toggle.base.3';
|
const featureName = 'feature.toggle.base.3';
|
||||||
const cloneName = 'feature.toggle.clone.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
|
await app.request
|
||||||
.post('/api/admin/projects/default/features')
|
.post('/api/admin/projects/default/features')
|
||||||
|
Loading…
Reference in New Issue
Block a user