Skip to content

Commit

Permalink
final tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
aarsilv committed Jul 1, 2024
1 parent 3e3b8e1 commit 357cdcc
Showing 1 changed file with 60 additions and 31 deletions.
91 changes: 60 additions & 31 deletions src/client/eppo-client-with-bandits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,41 +298,70 @@ describe('EppoClient Bandits E2E test', () => {
expect(banditAssignment.action).toBe('reebok');
expect(banditAssignment.variation).toBe('banner_bandit');
});
});

it('Can take non-contextual action attributes', async () => {
const actionsWithNonContextualAttributes: Record<string, Attributes> = {
nike: { brand_affinity: -1.7, loyalty_tier: 'silver', zip: '81427' },
adidas: { brand_affinity: 0.0, loyalty_tier: 'bronze' },
reebok: { brand_affinity: 15, loyalty_tier: 'gold' }, // TODO: tweak
};
it('Can take non-contextual action attributes', async () => {
const actionsWithNonContextualAttributes: Record<string, Attributes> = {
nike: { brand_affinity: -15, loyalty_tier: 'silver', zip: '81427' },
adidas: { brand_affinity: 0.0, loyalty_tier: 'bronze' },
reebok: { brand_affinity: 15, loyalty_tier: 'gold' },
};

let banditAssignment = client.getBanditAction(
flagKey,
'imogene',
subjectAttributes,
actionsWithNonContextualAttributes,
'default',
);
expect(banditAssignment.action).toBe('nike');
expect(banditAssignment.variation).toBe('banner_bandit');
let banditAssignment = client.getBanditAction(
flagKey,
'imogene',
subjectAttributes,
actionsWithNonContextualAttributes,
'default',
);
expect(banditAssignment.action).toBe('nike');
expect(banditAssignment.variation).toBe('banner_bandit');

// changing zip code to a number should result in a different evaluation
actionsWithNonContextualAttributes.nike.zip = 81427;
// changing zip code to a number should result in a different evaluation
actionsWithNonContextualAttributes.nike.zip = 81427;

banditAssignment = client.getBanditAction(
flagKey,
'imogene',
subjectAttributes,
actionsWithNonContextualAttributes,
'default',
);
expect(banditAssignment.action).toBe('nike');
expect(banditAssignment.variation).toBe('banner_bandit');
});
});
banditAssignment = client.getBanditAction(
flagKey,
'imogene',
subjectAttributes,
actionsWithNonContextualAttributes,
'default',
);
expect(banditAssignment.action).toBe('adidas');
expect(banditAssignment.variation).toBe('banner_bandit');
});

it('Can take actions without any context', async () => {
const actionNamesOnly = ['nike', 'adidas', 'reebok'];

let banditAssignment = client.getBanditAction(
flagKey,
'imogene',
subjectAttributes,
actionNamesOnly,
'default',
);
expect(banditAssignment.action).toBe('nike');
expect(banditAssignment.variation).toBe('banner_bandit');

it('Can take actions without any context', async () => {
// TODO
expect(mockLogBanditAction).toHaveBeenCalledTimes(1);
expect(mockLogBanditAction.mock.calls[0][0].actionProbability).toBeCloseTo(0.256);

// Duplicates should be ignored and not change anything
actionNamesOnly.push('nike');

banditAssignment = client.getBanditAction(
flagKey,
'imogene',
subjectAttributes,
actionNamesOnly,
'default',
);
expect(banditAssignment.action).toBe('nike');
expect(banditAssignment.variation).toBe('banner_bandit');

expect(mockLogBanditAction).toHaveBeenCalledTimes(2);
expect(mockLogBanditAction.mock.calls[1][0].actionProbability).toBeCloseTo(0.256);
});
});
});
});

0 comments on commit 357cdcc

Please sign in to comment.