41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { uuidTransformer } from '@/utils/uuidTransformer';
|
|
import { NIL } from 'uuid';
|
|
|
|
describe('uuidTransformer util', () => {
|
|
const transformer = uuidTransformer;
|
|
beforeEach(() => {});
|
|
|
|
it('Should have a to member', () => {
|
|
expect(transformer.to).toBeDefined();
|
|
});
|
|
|
|
it('Should have a from member', () => {
|
|
expect(transformer.from).toBeDefined();
|
|
});
|
|
|
|
it('From method should return a nil uuid if null is passed', () => {
|
|
expect(transformer.from(null)).toBe(NIL);
|
|
});
|
|
|
|
it('From method should throw an error if paring an invalid length buffer', () => {
|
|
expect(() => transformer.from(Buffer.alloc(15))).toThrow();
|
|
});
|
|
|
|
it('From method should return a nil uuid if empty 16 length buffer is passed', () => {
|
|
expect(transformer.from(Buffer.alloc(16))).toBe(NIL);
|
|
});
|
|
|
|
it('From and To methods should be each others inverse', () => {
|
|
const uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
|
|
expect(transformer.from(transformer.to(uuid))).toBe(uuid);
|
|
});
|
|
|
|
it('To method should return a buffer matching the uuid', () => {
|
|
expect(transformer.to(NIL)).toEqual(Buffer.alloc(16));
|
|
});
|
|
|
|
it('To method throw an error if passing a string that does not match a uuid', () => {
|
|
expect(() => transformer.to('test')).toThrow();
|
|
});
|
|
});
|