1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

fix: failing tests

This commit is contained in:
Ivar Conradi Østhus 2021-08-10 13:50:59 +02:00
parent 1dfa996c00
commit 806b4a4a59
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09
3 changed files with 52 additions and 18 deletions

View File

@ -12,7 +12,6 @@ const {
DROP_STRATEGIES,
TAG_TYPE_IMPORT,
TAG_IMPORT,
FEATURE_TAG_IMPORT,
PROJECT_IMPORT,
} = require('../types/events');
@ -236,23 +235,16 @@ test('should import a tag and tag type', async () => {
{ name: 'simple', description: 'some description', icon: '#' },
],
tags: [{ type: 'simple', value: 'test' }],
featureTags: [
{
featureName: 'demo-feature',
tagType: 'simple',
tagValue: 'test',
},
],
};
await stateService.import({ data });
const events = await stores.eventStore.getEvents();
expect(events).toHaveLength(3);
expect(events).toHaveLength(2);
expect(events[0].type).toBe(TAG_TYPE_IMPORT);
expect(events[0].data.name).toBe('simple');
expect(events[1].type).toBe(TAG_IMPORT);
expect(events[1].data.value).toBe('test');
expect(events[2].type).toBe(FEATURE_TAG_IMPORT);
expect(events[2].data.featureName).toBe('demo-feature');
});
test('Should not import an existing tag', async () => {
@ -314,7 +306,7 @@ test('Should not keep existing tags if drop-before-import', async () => {
expect(tagTypes).toHaveLength(1);
});
test('should export tag, tagtypes and feature tags', async () => {
test('should export tag, tagtypes', async () => {
const { stateService, stores } = getSetup();
const data = {
@ -343,12 +335,52 @@ test('should export tag, tagtypes and feature tags', async () => {
includeTags: true,
includeProjects: false,
});
expect(exported.tags).toHaveLength(1);
expect(exported.tags[0].type).toBe(data.tags[0].type);
expect(exported.tags[0].value).toBe(data.tags[0].value);
expect(exported.tagTypes).toHaveLength(1);
expect(exported.tagTypes[0].name).toBe(data.tagTypes[0].name);
expect(exported.featureTags).toHaveLength(0);
});
test('should export tag, tagtypes, featureTags and features', async () => {
const { stateService, stores } = getSetup();
const data = {
tagTypes: [
{ name: 'simple', description: 'some description', icon: '#' },
],
tags: [{ type: 'simple', value: 'test' }],
featureTags: [
{
featureName: 'demo-feature',
tagType: 'simple',
tagValue: 'test',
},
],
};
await stores.tagTypeStore.createTagType(data.tagTypes[0]);
await stores.tagStore.createTag(data.tags[0]);
await stores.featureTagStore.tagFeature(data.featureTags[0].featureName, {
type: data.featureTags[0].tagType,
value: data.featureTags[0].tagValue,
});
const exported = await stateService.export({
includeFeatureToggles: true,
includeStrategies: false,
includeTags: true,
includeProjects: false,
});
expect(exported.tags).toHaveLength(1);
expect(exported.tags[0].type).toBe(data.tags[0].type);
expect(exported.tags[0].value).toBe(data.tags[0].value);
expect(exported.tagTypes).toHaveLength(1);
expect(exported.tagTypes[0].name).toBe(data.tagTypes[0].name);
expect(exported.featureTags).toHaveLength(1);
expect(exported.featureTags[0].featureName).toBe(
data.featureTags[0].featureName,
);

View File

@ -161,9 +161,11 @@ export default class StateService {
tagTypes: data.tagTypes,
tags: data.tags,
featureTags:
data.featureTags
(data.featureTags || [])
.filter(t =>
data.features.some(f => f.name === t.featureName),
(data.features || []).some(
f => f.name === t.featureName,
),
)
.map(t => ({
featureName: t.featureName,

View File

@ -7034,10 +7034,10 @@ universalify@^0.1.0, universalify@^0.1.2:
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
unleash-frontend@4.0.5-beta.2:
version "4.0.5-beta.2"
resolved "https://registry.yarnpkg.com/unleash-frontend/-/unleash-frontend-4.0.5-beta.2.tgz#33129a75db98f57db69b362e3eaab36847cdb3dc"
integrity sha512-vnPB+9aQdw0U4M889GoU/RkRVneI+7ATRJBecSexwQHa6FGDwv04X57VcUnEJudJu7x+NvJrOYojZQsaIgQcOw==
unleash-frontend@4.0.9:
version "4.0.9"
resolved "https://registry.yarnpkg.com/unleash-frontend/-/unleash-frontend-4.0.9.tgz#f2ef490c2b68fa77979c33b7488ec98080d5278e"
integrity sha512-ufJ1OV4mY6Y6qvSbybA9gXIo+xBkYrVRiwmqgqkYy62b2s5SB5C6Iu/J2wUTmlOeKO20e5Kfp3EmhLznP3i8hA==
unpipe@1.0.0, unpipe@~1.0.0:
version "1.0.0"