@api-client/core 0.20.2 → 0.20.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,113 +0,0 @@
1
- import { test } from '@japa/runner'
2
- import {
3
- SemanticType,
4
- SemanticTiming,
5
- SemanticOperation,
6
- getSemanticsForOperation,
7
- canSemanticBeDisabled,
8
- type AppliedDataSemantic,
9
- } from '../../../src/modeling/Semantics.js'
10
-
11
- test.group('Semantic Runtime Control', () => {
12
- test('getSemanticsForOperation should filter semantics by operation and timing', ({ assert }) => {
13
- const semantics: AppliedDataSemantic[] = [
14
- { id: SemanticType.Password },
15
- { id: SemanticType.CreatedTimestamp },
16
- { id: SemanticType.UpdatedTimestamp },
17
- { id: SemanticType.Status },
18
- { id: SemanticType.Title },
19
- ]
20
-
21
- // Test CREATE operation with BEFORE timing
22
- const createBeforeSemantics = getSemanticsForOperation(semantics, SemanticOperation.Create, SemanticTiming.Before)
23
- const createBeforeTypes = createBeforeSemantics.map((s) => s.id)
24
-
25
- assert.includeMembers(createBeforeTypes, [SemanticType.Password, SemanticType.CreatedTimestamp])
26
- assert.notInclude(createBeforeTypes, SemanticType.UpdatedTimestamp) // Only runs on UPDATE
27
- assert.notInclude(createBeforeTypes, SemanticType.Title) // No runtime operations
28
-
29
- // Test UPDATE operation with BEFORE timing
30
- const updateBeforeSemantics = getSemanticsForOperation(semantics, SemanticOperation.Update, SemanticTiming.Before)
31
- const updateBeforeTypes = updateBeforeSemantics.map((s) => s.id)
32
-
33
- assert.includeMembers(updateBeforeTypes, [SemanticType.Password, SemanticType.UpdatedTimestamp])
34
- assert.notInclude(updateBeforeTypes, SemanticType.CreatedTimestamp) // Only runs on CREATE
35
-
36
- // Test Status semantic runs on both CREATE and UPDATE
37
- assert.include(createBeforeTypes, SemanticType.Status)
38
- assert.include(updateBeforeTypes, SemanticType.Status)
39
- })
40
-
41
- test('getSemanticsForOperation should sort semantics by priority', ({ assert }) => {
42
- const semantics: AppliedDataSemantic[] = [
43
- { id: SemanticType.Password }, // priority: 10
44
- { id: SemanticType.ResourceOwnerIdentifier }, // priority: 5
45
- { id: SemanticType.UserRole }, // priority: 20
46
- ]
47
-
48
- const createSemantics = getSemanticsForOperation(semantics, SemanticOperation.Create, SemanticTiming.Before)
49
-
50
- // Should be sorted by priority: ResourceOwnerIdentifier (5), Password (10), UserRole (20)
51
- assert.equal(createSemantics[0].id, SemanticType.ResourceOwnerIdentifier)
52
- assert.equal(createSemantics[1].id, SemanticType.Password)
53
- assert.equal(createSemantics[2].id, SemanticType.UserRole)
54
- })
55
-
56
- test('getSemanticsForOperation should handle BOTH timing correctly', ({ assert }) => {
57
- const semantics: AppliedDataSemantic[] = [
58
- { id: SemanticType.Status }, // timing: Both
59
- { id: SemanticType.Password }, // timing: Before
60
- ]
61
-
62
- const beforeSemantics = getSemanticsForOperation(semantics, SemanticOperation.Create, SemanticTiming.Before)
63
- const afterSemantics = getSemanticsForOperation(semantics, SemanticOperation.Create, SemanticTiming.After)
64
-
65
- // Status should appear in both BEFORE and AFTER
66
- assert.equal(beforeSemantics.length, 2) // Status and Password
67
- assert.equal(afterSemantics.length, 1) // Only Status
68
- assert.equal(afterSemantics[0].id, SemanticType.Status)
69
- })
70
-
71
- test('canSemanticBeDisabled should check if semantic can be disabled', ({ assert }) => {
72
- // Security semantics cannot be disabled
73
- assert.isFalse(canSemanticBeDisabled(SemanticType.Password))
74
- assert.isFalse(canSemanticBeDisabled(SemanticType.ResourceOwnerIdentifier))
75
-
76
- // Other semantics can be disabled (default)
77
- assert.isTrue(canSemanticBeDisabled(SemanticType.CreatedTimestamp))
78
- assert.isTrue(canSemanticBeDisabled(SemanticType.Email))
79
- assert.isTrue(canSemanticBeDisabled(SemanticType.Status))
80
- })
81
-
82
- test('getSemanticsForOperation should return empty array for semantics with no runtime', ({ assert }) => {
83
- const semantics: AppliedDataSemantic[] = [
84
- { id: SemanticType.Title }, // No runtime operations
85
- { id: SemanticType.Description }, // No runtime operations
86
- { id: SemanticType.User }, // No runtime operations
87
- ]
88
-
89
- const result = getSemanticsForOperation(semantics, SemanticOperation.Create, SemanticTiming.Before)
90
- assert.lengthOf(result, 0)
91
- })
92
-
93
- test('getSemanticsForOperation should filter by specific operations', ({ assert }) => {
94
- const semantics: AppliedDataSemantic[] = [
95
- { id: SemanticType.CreatedTimestamp }, // Only CREATE
96
- { id: SemanticType.UpdatedTimestamp }, // Only UPDATE
97
- { id: SemanticType.DeletedTimestamp }, // Only DELETE
98
- ]
99
-
100
- const createSemantics = getSemanticsForOperation(semantics, SemanticOperation.Create, SemanticTiming.Before)
101
- const updateSemantics = getSemanticsForOperation(semantics, SemanticOperation.Update, SemanticTiming.Before)
102
- const deleteSemantics = getSemanticsForOperation(semantics, SemanticOperation.Delete, SemanticTiming.Before)
103
-
104
- assert.lengthOf(createSemantics, 1)
105
- assert.equal(createSemantics[0].id, SemanticType.CreatedTimestamp)
106
-
107
- assert.lengthOf(updateSemantics, 1)
108
- assert.equal(updateSemantics[0].id, SemanticType.UpdatedTimestamp)
109
-
110
- assert.lengthOf(deleteSemantics, 1)
111
- assert.equal(deleteSemantics[0].id, SemanticType.DeletedTimestamp)
112
- })
113
- })