UNPKG

nestjs-uuid

Version:
36 lines (35 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const testing_1 = require("@nestjs/testing"); const uuid_generator_service_1 = require("./uuid-generator.service"); const uuid_module_1 = require("../uuid.module"); describe('UuidService', () => { let service; beforeEach(async () => { const module = await testing_1.Test.createTestingModule({ imports: [uuid_module_1.UuidModule], }).compile(); service = module.get(uuid_generator_service_1.UuidService); }); it('should be defined', () => { expect(service).toBeDefined(); expect(service).toHaveProperty('generate'); expect(service).toHaveProperty('validate'); }); it('should generate a valid UUID v4', () => { const uuid = service.generate(); expect(uuid.at(14)).toBe('4'); expect(service.validate(uuid)).toBe(true); }); it('should generate a valid UUID v1', () => { const uuid = service.generate({ version: 1 }); expect(uuid.at(14)).toBe('1'); expect(service.validate(uuid)).toBe(true); }); it('should validate an UUID', () => { expect(service.validate('41a5bb97-c1d9-42e8-9bb6-dca5977ac628')).toBeTruthy(); }); it('should fail when an invalid UUID is provided', () => { expect(service.validate('00000000-0000-0000-0000-000000000000 ')).toBeFalsy(); }); });