Skip to content

Commit

Permalink
Add await to relevent setuser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rafinutshaw-optimizely committed Jul 21, 2023
1 parent 3a40344 commit 026aef0
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('ReactSDKClient', () => {
});

it('fulfills the returned promise with success: true when a user is set', async () => {
instance.setUser({
await instance.setUser({
id: 'user12345',
});
const result = await instance.onReady();
Expand All @@ -164,7 +164,7 @@ describe('ReactSDKClient', () => {
});

it('fulfills the returned promise with success: false when a user is set', async () => {
instance.setUser({
await instance.setUser({
id: 'user12345',
});
const result = await instance.onReady();
Expand All @@ -178,7 +178,7 @@ describe('ReactSDKClient', () => {
resolveInnerClientOnReady = res;
});
mockInnerClientOnReady.mockReturnValueOnce(mockReadyPromise);
instance.setUser({
await instance.setUser({
id: 'user999',
});
resolveInnerClientOnReady!({ success: true });
Expand All @@ -194,7 +194,7 @@ describe('ReactSDKClient', () => {
resolveInnerClientOnReady = res;
});
mockInnerClientOnReady.mockReturnValueOnce(mockReadyPromise);
instance.setUser({
await instance.setUser({
id: 'user999',
});
resolveInnerClientOnReady!({ success: true });
Expand All @@ -204,9 +204,9 @@ describe('ReactSDKClient', () => {
});

describe('setUser', () => {
it('updates the user object with id and attributes', () => {
it('updates the user object with id and attributes', async () => {
const instance = createInstance(config);
instance.setUser({
await instance.setUser({
id: 'xxfueaojfe8&86',
attributes: {
foo: 'bar',
Expand Down Expand Up @@ -256,9 +256,9 @@ describe('ReactSDKClient', () => {

describe('pre-set user and user overrides', () => {
let instance: ReactSDKClient;
beforeEach(() => {
beforeEach(async () => {
instance = createInstance(config);
instance.setUser({
await instance.setUser({
id: 'user1',
attributes: {
foo: 'bar',
Expand Down Expand Up @@ -913,7 +913,7 @@ describe('ReactSDKClient', () => {
});

describe('if Optimizely client is null', () => {
it('does not return an object with variables of all types returned from the inner sdk ', () => {
it('does not return an object with variables of all types returned from the inner sdk ', async () => {
(mockInnerClient.getOptimizelyConfig as jest.Mock).mockReturnValue({
featuresMap: {
feat1: {
Expand Down Expand Up @@ -971,7 +971,7 @@ describe('ReactSDKClient', () => {
}
);
const instance = createInstance(config);
instance.setUser({
await instance.setUser({
id: 'user1123',
});
// @ts-ignore
Expand All @@ -981,7 +981,7 @@ describe('ReactSDKClient', () => {
});
});

it('returns an object with variables of all types returned from the inner sdk ', () => {
it('returns an object with variables of all types returned from the inner sdk ', async () => {
(mockInnerClient.getOptimizelyConfig as jest.Mock).mockReturnValue({
featuresMap: {
feat1: {
Expand Down Expand Up @@ -1039,7 +1039,7 @@ describe('ReactSDKClient', () => {
}
);
const instance = createInstance(config);
instance.setUser({
await instance.setUser({
id: 'user1123',
});
const result = instance.getFeatureVariables('feat1');
Expand All @@ -1057,7 +1057,7 @@ describe('ReactSDKClient', () => {

describe('getAllFeatureVariables', () => {
describe('if Optimizely client is null', () => {
it('does not return an object with variables of all types returned from the inner sdk ', () => {
it('does not return an object with variables of all types returned from the inner sdk ', async () => {
const anyClient = mockInnerClient.getAllFeatureVariables as jest.Mock;
anyClient.mockReturnValue({
bvar: true,
Expand All @@ -1071,14 +1071,14 @@ describe('ReactSDKClient', () => {
const instance = createInstance(config);
// @ts-ignore
instance._client = null;
instance.setUser({
await instance.setUser({
id: 'user1123',
});
const result = instance.getAllFeatureVariables('feat1', 'user1');
expect(result).toEqual({});
});

it('cannot use pre-set and override user for getAllFeatureVariables', () => {
it('cannot use pre-set and override user for getAllFeatureVariables', async () => {
const mockFn = mockInnerClient.getAllFeatureVariables as jest.Mock;
mockFn.mockReturnValue({
bvar: true,
Expand All @@ -1092,7 +1092,7 @@ describe('ReactSDKClient', () => {
const instance = createInstance(config);
// @ts-ignore
instance._client = null;
instance.setUser({
await instance.setUser({
id: 'user1',
attributes: {
foo: 'bar',
Expand All @@ -1111,7 +1111,7 @@ describe('ReactSDKClient', () => {
expect(result).toEqual({});
});

it('returns an object with variables of all types returned from the inner sdk ', () => {
it('returns an object with variables of all types returned from the inner sdk ', async () => {
const anyClient = mockInnerClient.getAllFeatureVariables as jest.Mock;
anyClient.mockReturnValue({
bvar: true,
Expand All @@ -1123,7 +1123,7 @@ describe('ReactSDKClient', () => {
},
});
const instance = createInstance(config);
instance.setUser({
await instance.setUser({
id: 'user1123',
});
const result = instance.getAllFeatureVariables('feat1', 'user1');
Expand All @@ -1138,7 +1138,7 @@ describe('ReactSDKClient', () => {
});
});

it('can use pre-set and override user for getAllFeatureVariables', () => {
it('can use pre-set and override user for getAllFeatureVariables', async () => {
const mockFn = mockInnerClient.getAllFeatureVariables as jest.Mock;
mockFn.mockReturnValue({
bvar: true,
Expand All @@ -1150,7 +1150,7 @@ describe('ReactSDKClient', () => {
},
});
const instance = createInstance(config);
instance.setUser({
await instance.setUser({
id: 'user1',
attributes: {
foo: 'bar',
Expand Down Expand Up @@ -1215,7 +1215,7 @@ describe('ReactSDKClient', () => {
});

it('should return false if fetch fails', async () => {
instance.setUser({
await instance.setUser({
id: 'user1',
});

Expand All @@ -1226,7 +1226,7 @@ describe('ReactSDKClient', () => {
});

it('should return true if fetch successful', async () => {
instance.setUser({
await instance.setUser({
id: 'user1',
});

Expand All @@ -1239,9 +1239,9 @@ describe('ReactSDKClient', () => {

describe('onForcedVariationsUpdate', () => {
let instance: ReactSDKClient;
beforeEach(() => {
beforeEach(async () => {
instance = createInstance(config);
instance.setUser({
await instance.setUser({
id: 'xxfueaojfe8&86',
attributes: {
foo: 'bar',
Expand Down Expand Up @@ -1293,10 +1293,10 @@ describe('ReactSDKClient', () => {
});

describe('if Optimizely client is null', () => {
it('should return false', () => {
it('should return false', async () => {
// @ts-ignore
instance._client = null;
instance.setUser({
await instance.setUser({
id: 'user1',
});
const mockFn = mockOptimizelyUserContext.removeAllForcedDecisions as jest.Mock;
Expand All @@ -1310,8 +1310,8 @@ describe('ReactSDKClient', () => {
});
});

it('should return true if user context has been set ', () => {
instance.setUser({
it('should return true if user context has been set ', async () => {
await instance.setUser({
id: 'user1',
});
const mockFn = mockOptimizelyUserContext.removeAllForcedDecisions as jest.Mock;
Expand All @@ -1327,9 +1327,9 @@ describe('ReactSDKClient', () => {

describe('setForcedDecision', () => {
let instance: ReactSDKClient;
beforeEach(() => {
beforeEach(async () => {
instance = createInstance(config);
instance.setUser({
await instance.setUser({
id: 'user1',
attributes: {
foo: 'bar',
Expand Down Expand Up @@ -1436,9 +1436,9 @@ describe('ReactSDKClient', () => {

describe('removeForcedDecision', () => {
let instance: ReactSDKClient;
beforeEach(() => {
beforeEach(async () => {
instance = createInstance(config);
instance.setUser({
await instance.setUser({
id: 'user1',
attributes: {
foo: 'bar',
Expand Down

0 comments on commit 026aef0

Please sign in to comment.