Skip to content

Commit

Permalink
test: add test cases to assert certain behavior (#168)
Browse files Browse the repository at this point in the history
This is in relation to the Edge implementation. Everything this PR does is to assert how we handle something today, so that we can rely on it not changing in the future.
  • Loading branch information
thomasheartman authored Mar 12, 2024
1 parent 245b696 commit 82be9a8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/test/create-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ test('should move rest props to properties', () => {
expect(context.properties?.tenantId).toBe('some-tenant');
});

test('when an extra property is both on the top-level and under properties, the properties-level wins', () => {
const context = createContext({
customProperty: 'top-level',
properties: {
customProperty: 'properties-level',
},
});

expect(context).not.toHaveProperty('customProperty');
expect(context.properties?.customProperty).toBe('properties-level');
});

test('If you specify top-level properties under properties, they do not get moved up', () => {
const context = createContext({
properties: {
appName: 'name',
},
});

expect(context.properties?.appName).toBe('name');
expect(context.appName).toBe(undefined);
});

test('should keep properties', () => {
const context = createContext({
userId: '123',
Expand Down
28 changes: 28 additions & 0 deletions src/test/unleash-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,34 @@ test('Should remove "undefined" environment field from context', async () => {
expect(client.queriedContexts[0]).not.toHaveProperty('environment');
});

test('Providing a string for `properties` yields a 400', async () => {
const toggles = [
{
name: 'test',
enabled: true,
impressionData: true,
},
];
const client = new MockClient(toggles);

const proxySecrets = ['sdf'];
const app = createApp(
{
unleashUrl,
unleashApiToken,
proxySecrets,
environment: 'test',
},
client,
);
client.emit('ready');

await request(app)
.get('/proxy?userId=123&properties=string')
.set('Authorization', 'sdf')
.expect(400);
});

test('Should register metrics', () => {
const toggles = [
{
Expand Down

0 comments on commit 82be9a8

Please sign in to comment.