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

test: add test cases to assert certain behavior #168

Merged
merged 8 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading