/*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ import { faker } from '@faker-js/faker'; import { parsePartitionKey } from './ParsePartitionKey'; import { InternalServerError } from '../errors'; import { ENTITY_TYPES } from '../constants/Repository.constants'; describe('parsePartitionKey', () => { const tenant = faker.string.uuid(); it.each([ [ENTITY_TYPES.context, `${ENTITY_TYPES.context}~${tenant}`], [ENTITY_TYPES.job, `${ENTITY_TYPES.job}~${tenant}`], [ENTITY_TYPES.jobExecution, `${ENTITY_TYPES.jobExecution}~${tenant}`], [ENTITY_TYPES.manifest, `${ENTITY_TYPES.manifest}~${tenant}`], ])('should parse %s partition key', (entityType: string, pk: string) => { expect(parsePartitionKey(pk)).toEqual({ entityType, tenant }); }); it('should throw an error for an invalid status', () => { const invalidType = 'invalid'; expect(() => parsePartitionKey(invalidType)).toThrow( new InternalServerError(`'${invalidType}' is an invalid type`), ); }); it('should throw if an invalid multi-tenant partition key is provided', () => { const invalidType = `invalid~${tenant}`; expect(() => parsePartitionKey(invalidType)).toThrow( new InternalServerError(`'${invalidType}' is an invalid type`), ); }); });