Skip to content

Conversation

@bgiori
Copy link
Collaborator

@bgiori bgiori commented Jul 19, 2021

Summary

  • more tests for experiment client
  • fixes based on tests

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

Comment on lines +152 to +154
return { ...this.user, user_properties: userPropertiesCopy };
} else {
return { ...this.user };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does user_properties change anything?

It's valid to spread a null or undefined variable, you just won't get any properties. So the before and after here are mostly functionally the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to make testing easier. Comparing the original user (null/undefined user_properties) and the one as a result of get/setUser()would not be equal.

}
}

const API_KEY = 'client-DvWljIjiiuqLbyjqdvBaLFfEBrAvGuA3';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are tests against the live API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I could mock the response eventually, but its a lot easier to hit the live endpoint.

const client = new ExperimentClient(API_KEY, {
fetchTimeoutMillis: 1,
});
await client.fetch(testUser);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fetch wait from the retry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the retries occur in the background.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you assert that variant('sdk-ci-test') at this point returns the config fallback? I think that would help demonstrate the intention of the test.

expect(variant).toEqual({ value: 'on', payload: 'payload' });
});

test('ExperimentClient.fetch, fallbacks returned in correct order', async () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of the SDK I have no idea what this is testing.

I would like to see a clear description of the logic being tested step by step in any test with multiple steps.

On top of that this seems like it might be testing the API as much as the SDK?

We should have end-to-end tests somewhere but I'm not sure this suite is the right place for that. Probably a broader discussion to have outside of this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is mostly testing the order/priority of fallbacks within the SDK--both before and after fetching variants from the server.

I will add comments on each step describing what we are testing and what we expect.

@bgiori bgiori requested a review from trashstack July 21, 2021 00:28
@bgiori
Copy link
Collaborator Author

bgiori commented Jul 21, 2021

@ManThursday could you re-review? Added a comment for each test case & split up the big one.

Copy link

@trashstack trashstack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking up the big test definitely helped. The descriptions are good as well although I had actually been thinking more along the lines of smaller comments annotating individual steps within the tests

});
let variant = client.variant(serverKey);
expect(variant).toEqual(serverOffVariant);
await client.fetch(testUser);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just to populate local storage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

Comment on lines +163 to +164
let variant = client.variant(serverKey);
expect(variant).toEqual(serverOffVariant);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serverKey and serverOffVariant were initially quite confusing names for me, particularly in this test.

Have I got these right?

serverKey = An experiment key that does actually exist on the server.
serverOffVariant = The configured initial variant for serverKey which is not the same as any variant on the server for this experiment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct.

Copy link

@trashstack trashstack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@bgiori bgiori merged commit d0d196d into main Jul 22, 2021
@bgiori bgiori deleted the bgiori/client-tests branch July 22, 2021 00:51
kelsonpw pushed a commit to kelsonpw/experiment-js-client that referenced this pull request Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants