mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-18 20:09:08 +02:00
e8d542af0f
* refactor: remove unused API definition routes * feat: add support for proxy keys * feat: support listening for any event * feat: embed proxy endpoints * refactor: add an experimental flag for the embedded proxy
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
// Copy of https://github.com/Unleash/unleash-proxy/blob/main/src/test/create-context.test.ts.
|
|
|
|
import { createContext } from './create-context';
|
|
|
|
test('should remove undefined properties', () => {
|
|
const context = createContext({
|
|
appName: undefined,
|
|
userId: '123',
|
|
});
|
|
|
|
expect(context).not.toHaveProperty('appName');
|
|
expect(context).toHaveProperty('userId');
|
|
expect(context.userId).toBe('123');
|
|
});
|
|
|
|
test('should move rest props to properties', () => {
|
|
const context = createContext({
|
|
userId: '123',
|
|
tenantId: 'some-tenant',
|
|
region: 'eu',
|
|
});
|
|
|
|
expect(context.userId).toBe('123');
|
|
expect(context).not.toHaveProperty('tenantId');
|
|
expect(context).not.toHaveProperty('region');
|
|
expect(context.properties?.region).toBe('eu');
|
|
expect(context.properties?.tenantId).toBe('some-tenant');
|
|
});
|
|
|
|
test('should keep properties', () => {
|
|
const context = createContext({
|
|
userId: '123',
|
|
tenantId: 'some-tenant',
|
|
region: 'eu',
|
|
properties: {
|
|
a: 'b',
|
|
b: 'test',
|
|
},
|
|
});
|
|
|
|
expect(context.userId).toBe('123');
|
|
expect(context).not.toHaveProperty('tenantId');
|
|
expect(context).not.toHaveProperty('region');
|
|
expect(context.properties?.region).toBe('eu');
|
|
expect(context.properties?.tenantId).toBe('some-tenant');
|
|
expect(context.properties?.a).toBe('b');
|
|
expect(context.properties?.b).toBe('test');
|
|
});
|
|
|
|
test('will not blow up if properties is an array', () => {
|
|
const context = createContext({
|
|
userId: '123',
|
|
tenantId: 'some-tenant',
|
|
region: 'eu',
|
|
properties: ['some'],
|
|
});
|
|
|
|
// console.log(context);
|
|
|
|
expect(context.userId).toBe('123');
|
|
expect(context).not.toHaveProperty('tenantId');
|
|
expect(context).not.toHaveProperty('region');
|
|
});
|
|
|
|
test.skip('will not blow up if userId is an array', () => {
|
|
const context = createContext({
|
|
userId: ['123'],
|
|
tenantId: 'some-tenant',
|
|
region: 'eu',
|
|
properties: ['some'],
|
|
});
|
|
|
|
// console.log(context);
|
|
|
|
expect(context.userId).toBe('123');
|
|
expect(context).not.toHaveProperty('tenantId');
|
|
expect(context).not.toHaveProperty('region');
|
|
});
|