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

FF-2465 adds "environment" and "allocation.name" to details #107

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/assignment-logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('IAssignmentEvent', () => {
subjectAttributes: { age: 25, country: 'USA' },
holdoutKey: 'holdout_key_123',
details: {
environment: 'Test',
variationKey: 'variationKey',
variationValue: 'variation_123',
flagEvaluationCode: 'MATCH',
Expand All @@ -22,6 +23,7 @@ describe('IAssignmentEvent', () => {
matchedRule: null,
matchedAllocation: {
key: 'allocation_123',
name: 'Allocation for allocation_123',
allocationEvaluationCode: AllocationEvaluationCode.MATCH,
orderPosition: 1,
},
Expand Down
14 changes: 13 additions & 1 deletion src/client/eppo-client-assignment-details.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('EppoClient get*AssignmentDetails', () => {
);
const expected: IAssignmentDetails<number> = {
value: 3,
environment: 'Test',
variationKey: 'three',
variationValue: 3,
flagEvaluationCode: 'MATCH',
Expand All @@ -77,13 +78,15 @@ describe('EppoClient get*AssignmentDetails', () => {
},
matchedAllocation: {
key: 'targeted allocation',
name: 'Allocation for targeted allocation',
greghuels marked this conversation as resolved.
Show resolved Hide resolved
allocationEvaluationCode: AllocationEvaluationCode.MATCH,
orderPosition: 0,
},
unmatchedAllocations: [],
unevaluatedAllocations: [
{
key: '50/50 split',
name: 'Allocation for 50/50 split',
greghuels marked this conversation as resolved.
Show resolved Hide resolved
allocationEvaluationCode: AllocationEvaluationCode.UNEVALUATED,
orderPosition: 1,
},
Expand All @@ -92,7 +95,7 @@ describe('EppoClient get*AssignmentDetails', () => {
expect(result).toMatchObject(expected);
});

it.only('should set the details for a matched split', () => {
greghuels marked this conversation as resolved.
Show resolved Hide resolved
it('should set the details for a matched split', () => {
const client = new EppoClient(storage);
client.setIsGracefulFailureMode(false);
const subjectAttributes = { email: '[email protected]', country: 'Brazil' };
Expand All @@ -104,6 +107,7 @@ describe('EppoClient get*AssignmentDetails', () => {
);
const expected: IAssignmentDetails<number> = {
value: 2,
environment: 'Test',
variationKey: 'two',
variationValue: 2,
flagEvaluationCode: 'MATCH',
Expand All @@ -114,12 +118,14 @@ describe('EppoClient get*AssignmentDetails', () => {
matchedRule: null,
matchedAllocation: {
key: '50/50 split',
name: 'Allocation for 50/50 split',
allocationEvaluationCode: AllocationEvaluationCode.MATCH,
orderPosition: 2,
},
unmatchedAllocations: [
{
key: 'targeted allocation',
name: 'Allocation for targeted allocation',
allocationEvaluationCode: AllocationEvaluationCode.FAILING_RULE,
orderPosition: 1,
},
Expand All @@ -141,6 +147,7 @@ describe('EppoClient get*AssignmentDetails', () => {
);
const expected: IAssignmentDetails<string> = {
value: 'control',
environment: 'Test',
flagEvaluationCode: 'MATCH',
flagEvaluationDescription:
'Supplied attributes match rules defined in allocation "experiment" and alice belongs to the range of traffic assigned to "control".',
Expand All @@ -159,24 +166,28 @@ describe('EppoClient get*AssignmentDetails', () => {
},
matchedAllocation: {
key: 'experiment',
name: 'Allocation for experiment',
allocationEvaluationCode: AllocationEvaluationCode.MATCH,
orderPosition: 2,
},
unmatchedAllocations: [
{
key: 'id rule',
name: 'Allocation for id rule',
allocationEvaluationCode: AllocationEvaluationCode.FAILING_RULE,
orderPosition: 0,
},
{
key: 'internal users',
name: 'Allocation for internal users',
greghuels marked this conversation as resolved.
Show resolved Hide resolved
allocationEvaluationCode: AllocationEvaluationCode.FAILING_RULE,
orderPosition: 1,
},
],
unevaluatedAllocations: [
{
key: 'rollout',
name: 'Allocation for rollout',
allocationEvaluationCode: AllocationEvaluationCode.UNEVALUATED,
orderPosition: 3,
},
Expand All @@ -191,6 +202,7 @@ describe('EppoClient get*AssignmentDetails', () => {
const result = client.getIntegerAssignmentDetails('asdf', 'alice', {}, 0);
expect(result).toMatchObject({
value: 0,
environment: 'Test',
flagEvaluationCode: 'FLAG_UNRECOGNIZED_OR_DISABLED',
flagEvaluationDescription: 'Unrecognized or disabled flag: asdf',
variationKey: null,
Expand Down
6 changes: 6 additions & 0 deletions src/client/eppo-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ describe('EppoClient E2E test', () => {
};

const mockFlag: Flag = {
environment: 'Test',
key: flagKey,
enabled: true,
variationType: VariationType.STRING,
variations: { a: variationA, b: variationB },
allocations: [
{
key: 'allocation-a',
name: 'Allocation for allocation-a',
rules: [],
splits: [
{
Expand Down Expand Up @@ -453,6 +455,7 @@ describe('EppoClient E2E test', () => {
allocations: [
{
key: 'allocation-a-2',
name: 'Allocation for allocation-a-2',
rules: [],
splits: [
{
Expand All @@ -473,6 +476,7 @@ describe('EppoClient E2E test', () => {
allocations: [
{
key: 'allocation-a-3',
name: 'Allocation for allocation-a-3',
rules: [],
splits: [
{
Expand Down Expand Up @@ -505,6 +509,7 @@ describe('EppoClient E2E test', () => {
allocations: [
{
key: 'allocation-a', // note: same key
name: 'Allocation for allocation-a',
rules: [],
splits: [
{
Expand Down Expand Up @@ -534,6 +539,7 @@ describe('EppoClient E2E test', () => {
allocations: [
{
key: 'allocation-b', // note: different key
name: 'Allocation for allocation-b',
rules: [],
splits: [
{
Expand Down
11 changes: 7 additions & 4 deletions src/client/eppo-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,12 @@ export default class EppoClient {
};
} catch (error) {
const eppoValue = this.rethrowIfNotGraceful(error, defaultValue);
const flagEvaluationDetails = new FlagEvaluationDetailsBuilder([], '', '').buildForNoneResult(
'ASSIGNMENT_ERROR',
`Assignment Error: ${error.message}`,
);
const flagEvaluationDetails = new FlagEvaluationDetailsBuilder(
'',
[],
'',
'',
).buildForNoneResult('ASSIGNMENT_ERROR', `Assignment Error: ${error.message}`);
return {
eppoValue,
flagEvaluationDetails,
Expand Down Expand Up @@ -464,6 +466,7 @@ export default class EppoClient {

const { flag, configFetchedAt, configPublishedAt } = this.getFlagDetails(flagKey);
const flagEvaluationDetailsBuilder = new FlagEvaluationDetailsBuilder(
flag?.environment ?? '',
flag?.allocations ?? [],
configFetchedAt,
configPublishedAt,
Expand Down
4 changes: 4 additions & 0 deletions src/decoding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ describe('decoding', () => {
it('should correctly decode allocation without startAt and endAt', () => {
const obfuscatedAllocation = {
key: 'ZXhwZXJpbWVudA==',
name: 'QWxsb2NhdGlvbiBmb3IgZXhwZXJpbWVudA==',
rules: [],
splits: [], // tested in decodeSplit
doLog: true,
};

const expectedAllocation = {
key: 'experiment',
name: 'Allocation for experiment',
rules: [],
splits: [],
doLog: true,
Expand All @@ -156,6 +158,7 @@ describe('decoding', () => {
it('should correctly decode allocation with startAt and endAt', () => {
const obfuscatedAllocation = {
key: 'ZXhwZXJpbWVudA==',
name: 'QWxsb2NhdGlvbiBmb3IgZXhwZXJpbWVudA==',
startAt: 'MjAyMC0wNC0wMVQxODo1ODo1NS44Mjla',
endAt: 'MjAyNS0wNy0yOVQwOTowMDoxMy4yMDVa',
rules: [],
Expand All @@ -165,6 +168,7 @@ describe('decoding', () => {

const expectedAllocation = {
key: 'experiment',
name: 'Allocation for experiment',
rules: [],
splits: [],
doLog: true,
Expand Down
1 change: 1 addition & 0 deletions src/decoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function decodeAllocation(allocation: ObfuscatedAllocation): Allocation {
return {
...allocation,
key: decodeBase64(allocation.key),
name: decodeBase64(allocation.name),
splits: allocation.splits.map(decodeSplit),
startAt: allocation.startAt
? new Date(decodeBase64(allocation.startAt)).toISOString()
Expand Down
Loading
Loading