1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| import { describe, expect, it } from 'vitest';
|
| import { buildReferenceTag, buildTag, generateOpaqueId, parseTag } from '../../src/domain/tags';
|
| describe('tag domain rules', () => {
| it('builds primary and reference tags from authoritative field codes without normalization', () => {
| expect(buildTag('Sample_ID')).toBe('eln.field.Sample_ID');
| expect(buildReferenceTag('Sample_ID', 'instance-01')).toBe('eln.ref.Sample_ID.instance-01');
| });
|
| it('parses primary, reference and repeat tags', () => {
| expect(parseTag('eln.field.sample_id')).toEqual({
| type: 'primary',
| fieldCode: 'sample_id',
| });
| expect(parseTag('eln.ref.sample_id.instance-01')).toEqual({
| type: 'reference',
| fieldCode: 'sample_id',
| instanceId: 'instance-01',
| });
| expect(parseTag('eln.repeat.test_results.r_01.result')).toEqual({
| type: 'repeat',
| groupCode: 'test_results',
| rowId: 'r_01',
| fieldCode: 'result',
| });
| });
|
| it.each([null, 1, 'other.field.sample_id', 'eln.field', 'eln.field.sample.extra', 'eln.ref.field', 'eln.ref.field.instance.extra', 'eln.repeat.group.row'])(
| 'rejects non-ELN or structurally invalid tag %s',
| (tag) => {
| expect(parseTag(tag)).toBeNull();
| },
| );
|
| it('generates deterministic operation and instance IDs without touching field codes', () => {
| const operationId = generateOpaqueId('op', (values) => {
| values[0] = 0x0123abcd;
| values[1] = 0xfedcba98;
| });
|
| expect(operationId).toBe('op_0123abcdfedcba98');
| expect(operationId).toMatch(/^op_[0-9a-f]{16}$/);
| });
| });
|
|