1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: handle check against non existing projects (#5368)

Instead of throwing an error when the project doesn't exist, we say that
the names are valid, because we have nothing to say that they're not.
Presumably there is already something in place to prevent you from
importing into a non-existent project.
This commit is contained in:
Thomas Heartman 2023-11-20 17:02:41 +01:00 committed by GitHub
parent 90d6c7c0ba
commit 0ba99a6162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 10 deletions

View File

@ -1168,19 +1168,31 @@ class FeatureToggleService {
projectId: string,
featureNames: string[],
): Promise<FeatureNameCheckResultWithFeaturePattern> {
const project = await this.projectStore.get(projectId);
const patternData = project.featureNaming;
const namingPattern = patternData?.pattern;
try {
const project = await this.projectStore.get(projectId);
if (namingPattern) {
const result = checkFeatureFlagNamesAgainstPattern(
featureNames,
namingPattern,
const patternData = project.featureNaming;
const namingPattern = patternData?.pattern;
if (namingPattern) {
const result = checkFeatureFlagNamesAgainstPattern(
featureNames,
namingPattern,
);
if (result.state === 'invalid') {
return { ...result, featureNaming: patternData };
}
}
} catch (error) {
// the project doesn't exist, so there's nothing to
// validate against
this.logger.info(
"Got an error when trying to validate flag naming patterns. It is probably because the target project doesn't exist. Here's the error:",
error.message,
);
if (result.state === 'invalid') {
return { ...result, featureNaming: patternData };
}
return { state: 'valid' };
}
return { state: 'valid' };

View File

@ -641,6 +641,20 @@ describe('flag name validation', () => {
).resolves.toBeFalsy();
}
});
test("should allow anything if the project doesn't exist", async () => {
const projectId = 'project-that-doesnt-exist';
const validFeatures = ['testpattern-feature', 'testpattern-feature2'];
for (const feature of validFeatures) {
await expect(
service.validateFeatureFlagNameAgainstPattern(
feature,
projectId,
),
).resolves.toBeFalsy();
}
});
});
test('Should return last seen at per environment', async () => {