2025-02-01 21:48:13 +00:00
|
|
|
import { UniqueID } from "./value-objects/unique-id";
|
2025-01-30 10:45:31 +00:00
|
|
|
|
|
|
|
|
describe("UniqueID Value Object", () => {
|
|
|
|
|
it("should generate a new UUID using generateNewID()", () => {
|
|
|
|
|
const result = UniqueID.generateNewID();
|
|
|
|
|
|
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
|
|
|
expect(result.data.getValue()).toMatch(
|
|
|
|
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return an error for an invalid UUID", () => {
|
|
|
|
|
const result = UniqueID.create("invalid-uuid");
|
|
|
|
|
|
|
|
|
|
expect(result.isError()).toBe(true);
|
|
|
|
|
expect(result.error.message).toBe("Invalid UUID format");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should create a valid UniqueID from an existing UUID", () => {
|
|
|
|
|
const validUUID = "550e8400-e29b-41d4-a716-446655440000";
|
|
|
|
|
const result = UniqueID.create(validUUID);
|
|
|
|
|
|
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
|
|
|
expect(result.data.getValue()).toBe(validUUID);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should correctly convert UniqueID to string", () => {
|
|
|
|
|
const validUUID = "550e8400-e29b-41d4-a716-446655440000";
|
|
|
|
|
const result = UniqueID.create(validUUID);
|
|
|
|
|
|
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
|
|
|
expect(result.data.toString()).toBe(validUUID);
|
|
|
|
|
});
|
|
|
|
|
});
|