Skip to content

Commit

Permalink
test: no . nor .. in feature name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed Oct 21, 2024
1 parent bd7fbd1 commit 24789d2
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/lib/schema/feature-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,29 @@ test('should require URL firendly name', () => {
};

const { error } = featureSchema.validate(toggle);
expect(error.details[0].message).toEqual('"name" must be URL friendly');
expect(error?.details[0].message).toEqual('"name" must be URL friendly');
});

test("shouldn't allow . nor .. as name", () => {
const toggle1 = {
name: '.',
enabled: false,
impressionData: false,
strategies: [{ name: 'default' }],
};
const toggle2 = {
name: '..',
enabled: false,
impressionData: false,
strategies: [{ name: 'default' }],
};

expect(featureSchema.validate(toggle1).error?.details[0].message).toEqual(
'"name" must be URL friendly',
);
expect(featureSchema.validate(toggle2).error?.details[0].message).toEqual(
'"name" must be URL friendly',
);
});

test('should be valid toggle name', () => {
Expand Down Expand Up @@ -91,7 +113,7 @@ test('should not allow weightType=fix with floats', () => {
};

const { error } = featureSchema.validate(toggle);
expect(error.details[0].message).toEqual('Weight only supports 1 decimal');
expect(error?.details[0].message).toEqual('Weight only supports 1 decimal');
});

test('should not allow weightType=fix with more than 1000', () => {
Expand All @@ -115,7 +137,7 @@ test('should not allow weightType=fix with more than 1000', () => {
};

const { error } = featureSchema.validate(toggle);
expect(error.details[0].message).toEqual(
expect(error?.details[0].message).toEqual(
'"variants[0].weight" must be less than or equal to 1000',
);
});
Expand All @@ -139,7 +161,7 @@ test('should disallow weightType=unknown', () => {
};

const { error } = featureSchema.validate(toggle);
expect(error.details[0].message).toEqual(
expect(error?.details[0].message).toEqual(
'"variants[0].weightType" must be one of [variable, fix]',
);
});
Expand Down Expand Up @@ -255,7 +277,7 @@ test('should not accept empty constraint values', () => {
};

const { error } = featureSchema.validate(toggle);
expect(error.details[0].message).toEqual(
expect(error?.details[0].message).toEqual(
'"strategies[0].constraints[0].values[0]" is not allowed to be empty',
);
});
Expand Down Expand Up @@ -300,7 +322,7 @@ test('Filter queries should reject tag values with missing type prefix', () => {
tag: ['simple', 'simple'],
};
const { error } = querySchema.validate(query);
expect(error.details[0].message).toEqual(
expect(error?.details[0].message).toEqual(
'"tag[0]" with value "simple" fails to match the tag pattern',
);
});
Expand All @@ -318,7 +340,7 @@ test('Filter queries should reject project names that are not alphanum', () => {
project: ['project name with space'],
};
const { error } = querySchema.validate(query);
expect(error.details[0].message).toEqual(
expect(error?.details[0].message).toEqual(
'"project[0]" must be URL friendly',
);
});
Expand Down

0 comments on commit 24789d2

Please sign in to comment.