Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add targeting key to flipt web tests #1237

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions libs/providers/flipt-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/providers/flipt-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"undici": "^6.13.0"
},
"dependencies": {
"@flipt-io/flipt-client-browser": "^0.3.1",
"@flipt-io/flipt-client-browser": "^0.5.0",
"undici": "^5.0.0"
}
}
18 changes: 9 additions & 9 deletions libs/providers/flipt-web/src/lib/flipt-web-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ describe('FliptWebProvider', () => {
describe('method resolveStringEvaluation', () => {
it('should throw general error for non-existent flag', () => {
expect(() => {
provider.resolveStringEvaluation('nonExistent', 'default', { fizz: 'buzz' });
provider.resolveStringEvaluation('nonExistent', 'default', { targetingKey: '1234', fizz: 'buzz' });
}).toThrow(GeneralError);
});

it('should return right value if key exists', () => {
const value = provider.resolveStringEvaluation('flag_string', 'default', { fizz: 'buzz' });
const value = provider.resolveStringEvaluation('flag_string', 'default', { targetingKey: '1234', fizz: 'buzz' });
expect(value).toHaveProperty('value', 'variant1');
expect(value).toHaveProperty('reason', 'TARGETING_MATCH');
});
Expand All @@ -42,12 +42,12 @@ describe('FliptWebProvider', () => {
describe('method resolveNumberEvaluation', () => {
it('should throw general error for non-existent flag', () => {
expect(() => {
provider.resolveNumberEvaluation('nonExistent', 1, { fizz: 'buzz' });
provider.resolveNumberEvaluation('nonExistent', 1, { targetingKey: '1234', fizz: 'buzz' });
}).toThrow(GeneralError);
});

it('should return right value if key exists', () => {
const value = provider.resolveNumberEvaluation('flag_number', 0, { fizz: 'buzz' });
const value = provider.resolveNumberEvaluation('flag_number', 0, { targetingKey: '1234', fizz: 'buzz' });
expect(value).toHaveProperty('value', 5);
expect(value).toHaveProperty('reason', 'TARGETING_MATCH');
});
Expand All @@ -56,12 +56,12 @@ describe('FliptWebProvider', () => {
describe('method resolveBooleanEvaluation', () => {
it('should throw general error for non-existent flag', () => {
expect(() => {
provider.resolveBooleanEvaluation('nonExistent', false, { fizz: 'buzz' });
provider.resolveBooleanEvaluation('nonExistent', false, { targetingKey: '1234', fizz: 'buzz' });
}).toThrow(GeneralError);
});

it('should return right value if key exists', () => {
const value = provider.resolveBooleanEvaluation('flag_boolean', false, { fizz: 'buzz' });
const value = provider.resolveBooleanEvaluation('flag_boolean', false, { targetingKey: '1234', fizz: 'buzz' });
expect(value).toHaveProperty('value', true);
expect(value).toHaveProperty('reason', 'TARGETING_MATCH');
});
Expand All @@ -70,20 +70,20 @@ describe('FliptWebProvider', () => {
describe('method resolveObjectEvaluation', () => {
it('should throw general error for non-existent flag', () => {
expect(() => {
provider.resolveObjectEvaluation('nonExistent', {}, { fizz: 'buzz' });
provider.resolveObjectEvaluation('nonExistent', {}, { targetingKey: '1234', fizz: 'buzz' });
}).toThrow(GeneralError);
});

it('should return right value if key exists', () => {
const value = provider.resolveObjectEvaluation('flag_object', { fizz: 'buzz' }, { fizz: 'buzz' });
const value = provider.resolveObjectEvaluation('flag_object', { fizz: 'buzz' }, { targetingKey: '1234', fizz: 'buzz' });
expect(value).toHaveProperty('value', { foo: 'bar' });
expect(value).toHaveProperty('reason', 'TARGETING_MATCH');
});
});

it('should throw TypeMismatchError on non-number value', () => {
expect(() => {
provider.resolveNumberEvaluation('flag_string', 0, { fizz: 'buzz' });
provider.resolveNumberEvaluation('flag_string', 0, { targetingKey: '1234', fizz: 'buzz' });
}).toThrow(TypeMismatchError);
});
});
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@connectrpc/connect": "^1.4.0",
"@connectrpc/connect-web": "^1.4.0",
"@flipt-io/flipt": "^1.2.0",
"@flipt-io/flipt-client-browser": "^0.3.1",
"@flipt-io/flipt-client-browser": "^0.5.0",
"@growthbook/growthbook": "^1.3.1",
"@grpc/grpc-js": "^1.9.13",
"@opentelemetry/api": "^1.3.0",
Expand Down