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

chore: change to fs/promises and add an import from file e2e test (#7240)

This commit is contained in:
David Leek 2024-06-03 12:10:12 +02:00 committed by GitHub
parent e8c9897c69
commit 63e300da3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 97 additions and 9 deletions

View File

@ -57,7 +57,7 @@ import type { IDependentFeaturesReadModel } from '../dependent-features/dependen
import groupBy from 'lodash.groupby';
import { allSettledWithRejection } from '../../util/allSettledWithRejection';
import type { ISegmentReadModel } from '../segment/segment-read-model-type';
import { readFile } from './import-file-reader';
import { readFile } from '../../util/read-file';
export type IImportService = {
validate(

View File

@ -1280,3 +1280,31 @@ test(`should give errors with flag names if the flags don't match the project pa
expect(body.message).toContain(pattern);
expect(body.message).toContain(flagName);
});
test('should import features from file', async () => {
await db.stores.environmentStore.create({
name: DEFAULT_ENV,
type: 'production',
});
await db.stores.projectStore.create({
name: DEFAULT_PROJECT,
description: '',
id: DEFAULT_PROJECT,
mode: 'open' as const,
});
await app.linkProjectToEnvironment(DEFAULT_PROJECT, DEFAULT_ENV);
await app.services.importService.importFromFile(
'src/lib/features/export-import-toggles/import-data.json',
DEFAULT_PROJECT,
DEFAULT_ENV,
);
const { body: importedFeature } = await getFeature(defaultFeatureName);
expect(importedFeature).toMatchObject({
name: defaultFeatureName,
project: DEFAULT_PROJECT,
type: 'release',
variants,
});
});

View File

@ -0,0 +1,64 @@
{
"features": [
{ "project": "old_project", "name": "first_feature", "type": "release" }
],
"featureStrategies": [
{
"featureName": "first_feature",
"id": "798cb25a-2abd-47bd-8a95-40ec13472309",
"name": "default",
"parameters": {},
"constraints": [
{
"values": ["conduit"],
"inverted": false,
"operator": "IN",
"contextName": "appName",
"caseInsensitive": false
}
]
}
],
"featureEnvironments": [
{
"enabled": true,
"environment": "irrelevant",
"featureName": "first_feature",
"name": "first_feature",
"variants": [
{
"name": "variantA",
"weight": 500,
"payload": { "type": "string", "value": "payloadA" },
"overrides": [],
"stickiness": "default",
"weightType": "variable"
},
{
"name": "variantB",
"weight": 500,
"payload": { "type": "string", "value": "payloadB" },
"overrides": [],
"stickiness": "default",
"weightType": "variable"
}
]
}
],
"featureTags": [
{ "featureName": "first_feature", "tagType": "simple", "tagValue": "tag1" },
{ "featureName": "first_feature", "tagType": "simple", "tagValue": "tag2" },
{
"featureName": "first_feature",
"tagType": "special_tag",
"tagValue": "feature_tagged"
}
],
"tagTypes": [
{ "name": "bestt", "description": "test" },
{ "name": "special_tag", "description": "this is my special tag" },
{ "name": "special_tag", "description": "this is my special tag" }
],
"contextFields": [],
"segments": []
}

View File

@ -1,8 +0,0 @@
import * as fs from 'fs';
export const readFile: (file: string) => Promise<string> = async (file) =>
new Promise((resolve, reject) =>
fs.readFile(file, (err, v) =>
err ? reject(err) : resolve(v.toString('utf-8')),
),
);

View File

@ -0,0 +1,4 @@
import { promises as fs } from 'fs';
export const readFile: (file: string) => Promise<string> = async (file) =>
await fs.readFile(file, 'utf-8');