📄 src/models/test/uid_methods.test.ts
D-OPEN SOVEREIGN
1/*
2 * Copyright (c) 2026 DataPond D-Library Pty Ltd. ("The Sanctuary")
3 * Non-Profit Public Library — The World Library
4 *
5 * D-SAFE Certification issued by POND Enterprise.
6 * Published under the D-Open Code Sovereign Licence v1.0 framework
7 * DataPond D-Library All exclusive Right reserved on modifiying the code - CC Attribution to data pond, Non modifiable, Non Commercial.
8 * https://registry.world.bibliotech.com/licence
9 * Source code donated to DataPond D-Library by it's author: data pond.
10 *
11 * Technical Guardian ("The Shield"): Pond Enterprise Pty Ltd. (ACN 694 747 987)
12 * All liability claims about D-SAFE certification issues coming from the published D-Safe direction must be addressed with Pond Enterprise Pty Ltd.
13 * Code Modification automatically voids the certified liability protection provided by Pond Enterprise.
14 */
15import { describe, it, expect, beforeAll } from 'vitest';
16import { Book, Person, NewBookWithId, NewPersonWithId } from '../generated-src/index.js';
17import { setDefaultLanguage } from '../orm.ts';
18
19beforeAll(() => {
20 setDefaultLanguage('eng');
21});
22
23describe('Generated UID Methods', () => {
24 it('toPID/fromPID round-trip', () => {
25 const book = NewBookWithId(42);
26 expect(Book.fromPID(book.toPID())).toEqual({ wireId: 42 });
27 });
28
29 it('fromPID returns null on invalid strings', () => {
30 expect(Book.fromPID('invalid-string')).toBeNull();
31 expect(Book.fromPID('DL:C:XX:invalid')).toBeNull();
32 });
33
34 it('sfcuid falls back to native PID when no standard set', () => {
35 const p = NewPersonWithId(1);
36 expect(p.sfcuid()).toBe(p.toNativePID());
37 });
38
39 it('sfcuid prefers isni over orcid over native', () => {
40 const p = NewPersonWithId(2);
41 p.isniId = '0000000121032683';
42 expect(p.sfcuid()).toMatch(/^isni:/);
43
44 p.orcidId = '0000-0002-1825-0097';
45 // Since isni is higher priority than orcid for Person, it should still be isni
46 expect(p.sfcuid()).toMatch(/^isni:/);
47 });
48
49 it('sfcuid returns orcid if isni is absent', () => {
50 const p = NewPersonWithId(3);
51 p.orcidId = '0000-0002-1825-0097';
52 expect(p.sfcuid()).toMatch(/^orcid:/);
53 });
54
55 it('identityCluster native field equals toNativePID()', () => {
56 const p = NewPersonWithId(4);
57 p.isniId = '0000000121032683';
58 p.orcidId = '0000-0002-1825-0097';
59
60 const c = p.identityCluster;
61 expect(c.sfcuid).toMatch(/^isni:/);
62 expect(c.native).toBe(p.toNativePID());
63 expect(c.wireId).toBe(4);
64 expect(c.aliases.length).toBeGreaterThan(0);
65 // It should contain the orcid and native PIDs in aliases
66 expect(c.aliases.some(a => a.startsWith('orcid:'))).toBe(true);
67 expect(c.aliases.some(a => a === p.toNativePID())).toBe(true);
68 });
69});
70