import { Namespace } from 'cls-hooked'; import { getClsNamespace } from '../../../cls'; import { TenantUtil, TENANT_ID_NAME, TENANT_UAA_AUTHORIZATION } from '../../../utils/Tenant.util'; describe('Tenant.util', () => { let namespace: Namespace; beforeEach(() => { namespace = getClsNamespace(); jest.clearAllMocks(); }); it('prepareTenantHeader should return valid header', () => { namespace.run(() => { TenantUtil.setTenantIdName('beesafe'); const header = TenantUtil.prepareTenantHeader(); expect(header) .toEqual({ 'X-Tenant-Id': 'beesafe' }); }); }); it('setTenantIdName should set tenant id for beesafe', () => { namespace.run(() => { TenantUtil.setTenantIdName('beesafe'); expect(namespace.get(TENANT_ID_NAME)) .toBe('beesafe'); }); }); it('setTenantIdName should set tenant id for other name', () => { namespace.run(() => { TenantUtil.setTenantIdName('test'); expect(namespace.get(TENANT_ID_NAME)) .toBe('test'); }); }); it('setTenantIdName should set default tenant id if no name passed', () => { namespace.run(() => { TenantUtil.setTenantIdName(); expect(namespace.get(TENANT_ID_NAME)) .toBe('beesafe'); }); }); it('setAuthorizationToken should set token based on request', () => { namespace.run(() => { TenantUtil.setAuthorizationToken('token'); expect(namespace.get(TENANT_UAA_AUTHORIZATION)) .toBe('token'); }); }); it('setAuthorizationToken should be undefined based on request', () => { namespace.run(() => { TenantUtil.setAuthorizationToken(); expect(namespace.get(TENANT_UAA_AUTHORIZATION)) .toEqual(undefined); }); }); });