From 96f9c3c3a6e9ccfee903220980118c86012531d1 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 9 Jul 2026 15:34:49 +0100 Subject: [PATCH] feat: add UuidService with UUID generation functionality --- .../src/lib/services/uuid-service.spec.ts | 44 +++++++++++++++++++ lib/core/src/lib/services/uuid-service.ts | 26 +++++++++++ 2 files changed, 70 insertions(+) create mode 100644 lib/core/src/lib/services/uuid-service.spec.ts create mode 100644 lib/core/src/lib/services/uuid-service.ts diff --git a/lib/core/src/lib/services/uuid-service.spec.ts b/lib/core/src/lib/services/uuid-service.spec.ts new file mode 100644 index 0000000000..f2fd7fcff7 --- /dev/null +++ b/lib/core/src/lib/services/uuid-service.spec.ts @@ -0,0 +1,44 @@ +/*! + * @license + * Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { TestBed } from '@angular/core/testing'; +import { UuidService } from './uuid-service'; + +describe('UuidService', () => { + let service: UuidService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(UuidService); + }); + + it('should call crypto.randomUUID when generate is called', () => { + const randomUuidSpy = spyOn(crypto, 'randomUUID').and.returnValue('11111111-1111-4111-8111-111111111111'); + + service.generate(); + + expect(randomUuidSpy).toHaveBeenCalledTimes(1); + }); + + it('should return value from crypto.randomUUID when generate is called', () => { + spyOn(crypto, 'randomUUID').and.returnValue('22222222-2222-4222-8222-222222222222'); + + const result = service.generate(); + + expect(result).toBe('22222222-2222-4222-8222-222222222222'); + }); +}); diff --git a/lib/core/src/lib/services/uuid-service.ts b/lib/core/src/lib/services/uuid-service.ts new file mode 100644 index 0000000000..c425b4890c --- /dev/null +++ b/lib/core/src/lib/services/uuid-service.ts @@ -0,0 +1,26 @@ +/*! + * @license + * Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Injectable } from '@angular/core'; + +@Injectable({ providedIn: 'root' }) +export class UuidService { + // creates RFC 4122 v4 (random) UUID + generate(): string { + return crypto.randomUUID(); + } +}