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

feat: getExperimentContainer helper function for CMS app integration #123

Merged
merged 3 commits into from
Oct 1, 2024

Conversation

greghuels
Copy link
Contributor

@greghuels greghuels commented Sep 30, 2024

Fixes: FF-3282

Motivation and Context

This provides agetExperimentContainerEntry function for working with content management systems that integrate with Eppo. For instance, the "Eppo" Contentful app will automatically create a new flag with variations "control", "variation-1", "variation-2", etc. The getExperimentContainerEntry will map the correct CMS container (e.g. "blog post", "header image", etc) given the string assignment returned.

How has this been tested?

Unit testing

@greghuels greghuels added the enhancement New feature or request label Sep 30, 2024
Copy link
Member

@felipecsl felipecsl left a comment

Choose a reason for hiding this comment

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

LGTM once comments expanded a bit, but I'd recommend getting another stamp from @leoromanovsky before merging 👍🏽

controlContainer,
);
expect(loggerWarnSpy).toHaveBeenCalled();
});
Copy link
Member

Choose a reason for hiding this comment

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

nice tests

src/client/eppo-client.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

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

Looks good to me 💪 A couple of comments, with the big ones being:

  1. Should we punt on a templated IFlagExperiment now and/or call that interface something to do with containers?
  2. Possible bug for checking length

await initConfiguration(storage);
client = new EppoClient(storage);
client.setIsGracefulFailureMode(true);
flagExperiment = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't use any variables set up in beforeEach() should it just be declared as a const up with the containers?

Copy link
Contributor Author

@greghuels greghuels Sep 30, 2024

Choose a reason for hiding this comment

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

I generally like to leave anything with Arrays and objects that are referenced by the production code in a before each to prevent against potential mutations that could affect subsequent tests, which then become difficult to diagnose. It's unlikely, but it can happen.

Copy link
Contributor Author

@greghuels greghuels Sep 30, 2024

Choose a reason for hiding this comment

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

If you feel strongly though, I can move it!

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope that's defensible too!

expect(loggerWarnSpy).not.toHaveBeenCalled();
});

it('should default to the control container if an unknown variation is assigned', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

);
await configurationRequestor.fetchAndStoreConfigurations();
}
import { initConfiguration } from './test-utils';
Copy link
Contributor

Choose a reason for hiding this comment

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

nice cleanup

@@ -68,6 +68,12 @@ export type FlagConfigurationRequestParameters = {
skipInitialPoll?: boolean;
};

export interface IFlagExperiment<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to call this something different that is more clear what it is doing and how it is used

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this templatized so in case future CMS inputs take on different shapes?

Copy link
Contributor Author

@greghuels greghuels Sep 30, 2024

Choose a reason for hiding this comment

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

We may want to call this something different that is more clear what it is doing and how it is used

Any suggestions? We could call it IContainerExperiment?

Is this templatized so in case future CMS inputs take on different shapes?

Yes, exactly. This is looking forward a bit to subsequent CMS work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated with IContainerExperiment, but let me know if you have another suggestion

src/client/test-utils.ts Outdated Show resolved Hide resolved
return controlVariation;
}
const treatmentVariationIndex = Number.parseInt(assignment.split('-')[1]);
if (treatmentVariationIndex > treatmentVariations.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be >=? (0-based indexing vs 1-based length)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No because the numbers that are parsed from the key are 1-indexed (e.g. treatment-1, treatment-2, etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make this more clear by the naming though. Index does make it seem like it should start with zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

@greghuels greghuels force-pushed the greg/FF-3282-contentul-sdk-helper branch from 139d20d to e650c4d Compare September 30, 2024 19:20
@greghuels greghuels assigned aarsilv and unassigned greghuels Sep 30, 2024
@greghuels greghuels force-pushed the greg/FF-3282-contentul-sdk-helper branch 3 times, most recently from 5e5ea30 to 10614d6 Compare September 30, 2024 19:32
@greghuels greghuels force-pushed the greg/FF-3282-contentul-sdk-helper branch from 10614d6 to 04dfca0 Compare September 30, 2024 19:38
Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

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

Thanks for iterating! 💪

await initConfiguration(storage);
client = new EppoClient(storage);
client.setIsGracefulFailureMode(true);
flagExperiment = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nope that's defensible too!

}
const treatmentVariationIndex = Number.parseInt(assignment.split('-')[1]);
if (treatmentVariationIndex > treatmentVariations.length) {
if (treatmentVariationIndex >= treatmentVariationEntries.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants