Skip to content

Commit

Permalink
fix: add missing property enabled to IVariant interface (#78)
Browse files Browse the repository at this point in the history
* fix: add missing property `enabled` to `IVariant` interface

* test: add test for returning the default variant
  • Loading branch information
christian98 authored Apr 7, 2022
1 parent d494a66 commit 22c7b06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,29 @@ test('Should have correct variant', async () => {
const payload = variant.payload || { type: 'undef', value: '' };
client.stop();
expect(variant.name).toBe('green');
expect(variant.enabled).toBe(true);
expect(payload.type).toBe('string');
expect(payload.value).toBe('some-text');
});

test('Should return default variant if not found', async () => {
fetchMock.mockResponseOnce(JSON.stringify(data));
const config: IConfig = {
url: 'http://localhost/test',
clientKey: '12',
appName: 'web',
};
const client = new UnleashClient(config);
await client.start();
const variant = client.getVariant('missingToggle');
const payload = variant.payload || { type: 'undef', value: '' };
client.stop();
expect(variant.name).toBe('disabled');
expect(variant.enabled).toBe(false);
expect(payload.type).toBe('undef');
expect(payload.value).toBe('');
});

test('Should handle error and return false for isEnabled', async () => {
jest.spyOn(global.console, 'error').mockImplementation(() => jest.fn());
fetchMock.mockReject();
Expand Down Expand Up @@ -739,7 +758,7 @@ test('Should note include context fields with "null" value', async () => {
expect(url.searchParams.has('remoteAddress')).toBe(false);
expect(url.searchParams.has('sessionId')).toBe(true);
expect(url.searchParams.get('sessionId')).toBe('0');

});

test('Should update context fields on request', async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface IConfig extends IStaticContext {

interface IVariant {
name: string;
enabled: boolean;
payload?: {
type: string;
value: string;
Expand All @@ -67,7 +68,7 @@ const IMPRESSION_EVENTS = {
GET_VARIANT: 'getVariant',
};

const defaultVariant: IVariant = { name: 'disabled' };
const defaultVariant: IVariant = { name: 'disabled', enabled: false };
const storeKey = 'repo';

export const resolveFetch = () => {
Expand Down

0 comments on commit 22c7b06

Please sign in to comment.