@things-factory/figure-service 10.1.278 → 10.1.279
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.
- package/package.json +23 -8
- package/coverage/clover.xml +0 -6
- package/coverage/coverage-final.json +0 -1
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -101
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov.info +0 -0
- package/dist-server/index.js.map +0 -1
- package/dist-server/migrations/index.js.map +0 -1
- package/dist-server/routers/figure-mesh-router.js.map +0 -1
- package/dist-server/routers/figure-package-router.js.map +0 -1
- package/dist-server/routers/figure-thumbnail-router.js.map +0 -1
- package/dist-server/routes.js.map +0 -1
- package/dist-server/service/figure/event-subscriber.js.map +0 -1
- package/dist-server/service/figure/figure-ai-scenarios-run.js.map +0 -1
- package/dist-server/service/figure/figure-ai-scenarios.js.map +0 -1
- package/dist-server/service/figure/figure-categories.js.map +0 -1
- package/dist-server/service/figure/figure-context.js.map +0 -1
- package/dist-server/service/figure/figure-format.js.map +0 -1
- package/dist-server/service/figure/figure-glb.js.map +0 -1
- package/dist-server/service/figure/figure-history.js.map +0 -1
- package/dist-server/service/figure/figure-llm-provider.js.map +0 -1
- package/dist-server/service/figure/figure-mesh-store.js.map +0 -1
- package/dist-server/service/figure/figure-mutation.js.map +0 -1
- package/dist-server/service/figure/figure-namespace-entity.js.map +0 -1
- package/dist-server/service/figure/figure-namespace-resolver.js.map +0 -1
- package/dist-server/service/figure/figure-namespace.js.map +0 -1
- package/dist-server/service/figure/figure-package-export.js.map +0 -1
- package/dist-server/service/figure/figure-proposal-record.js.map +0 -1
- package/dist-server/service/figure/figure-proposal.js.map +0 -1
- package/dist-server/service/figure/figure-propose-steps.js.map +0 -1
- package/dist-server/service/figure/figure-propose-type.js.map +0 -1
- package/dist-server/service/figure/figure-public.js.map +0 -1
- package/dist-server/service/figure/figure-query.js.map +0 -1
- package/dist-server/service/figure/figure-rename.js.map +0 -1
- package/dist-server/service/figure/figure-replaced-draft.js.map +0 -1
- package/dist-server/service/figure/figure-revert.js.map +0 -1
- package/dist-server/service/figure/figure-subject.js.map +0 -1
- package/dist-server/service/figure/figure-thumbnail-reader.js.map +0 -1
- package/dist-server/service/figure/figure-thumbnail-store.js.map +0 -1
- package/dist-server/service/figure/figure-thumbnail-upgrade.js.map +0 -1
- package/dist-server/service/figure/figure-tools.js.map +0 -1
- package/dist-server/service/figure/figure-type.js.map +0 -1
- package/dist-server/service/figure/figure-write.js.map +0 -1
- package/dist-server/service/figure/figure.js.map +0 -1
- package/dist-server/service/figure/index.js.map +0 -1
- package/dist-server/service/figure-recipe/figure-recipe-resolver.js.map +0 -1
- package/dist-server/service/figure-recipe/figure-recipe-templates.js.map +0 -1
- package/dist-server/service/figure-recipe/figure-recipe-type.js.map +0 -1
- package/dist-server/service/figure-recipe/index.js.map +0 -1
- package/dist-server/service/index.js.map +0 -1
- package/dist-server/tsconfig.tsbuildinfo +0 -1
- package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +0 -15
- package/logs/application-2026-09-14-23.log +0 -0
- package/logs/figure-ai-scenarios/2026-11-03T09-31-35-151Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1167
- package/logs/figure-ai-scenarios/2026-11-03T09-39-05-265Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -904
- package/logs/figure-ai-scenarios/2026-11-03T09-41-49-107Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1629
- package/logs/figure-ai-scenarios/2026-11-03T09-58-26-681Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4412
- package/logs/figure-ai-scenarios/2026-11-03T10-16-46-212Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4513
- package/logs/figure-ai-scenarios/2026-11-03T10-21-07-872Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4202
- package/logs/figure-ai-scenarios/2026-11-03T10-25-21-721Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1665
- package/logs/figure-ai-scenarios/2026-11-09T01-28-51-664Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4484
- package/scripts/build-templates.mts +0 -64
- package/scripts/figure-ai-scenarios-agent.cjs +0 -98
- package/scripts/rename-figures-to-full-names.mjs +0 -211
- package/scripts/templates.test.mts +0 -112
- package/server/index.ts +0 -46
- package/server/migrations/index.ts +0 -9
- package/server/routers/figure-mesh-router.ts +0 -63
- package/server/routers/figure-package-router.ts +0 -53
- package/server/routers/figure-thumbnail-router.ts +0 -159
- package/server/routes.ts +0 -30
- package/server/service/figure/catalog-db.test.ts +0 -162
- package/server/service/figure/event-subscriber.ts +0 -66
- package/server/service/figure/figure-ai-scenarios-run.ts +0 -127
- package/server/service/figure/figure-ai-scenarios.live.test.ts +0 -59
- package/server/service/figure/figure-ai-scenarios.test.ts +0 -109
- package/server/service/figure/figure-ai-scenarios.ts +0 -798
- package/server/service/figure/figure-blueprint-query.test.ts +0 -536
- package/server/service/figure/figure-catalog-seen-db.test.ts +0 -153
- package/server/service/figure/figure-categories.ts +0 -50
- package/server/service/figure/figure-category-db.test.ts +0 -127
- package/server/service/figure/figure-context.test.ts +0 -402
- package/server/service/figure/figure-context.ts +0 -510
- package/server/service/figure/figure-deprecation-db.test.ts +0 -218
- package/server/service/figure/figure-format.test.ts +0 -423
- package/server/service/figure/figure-format.ts +0 -783
- package/server/service/figure/figure-glb.test.ts +0 -112
- package/server/service/figure/figure-glb.ts +0 -251
- package/server/service/figure/figure-history.ts +0 -192
- package/server/service/figure/figure-inspect-db.test.ts +0 -131
- package/server/service/figure/figure-llm-provider.ts +0 -20
- package/server/service/figure/figure-llm-smoke.test.ts +0 -95
- package/server/service/figure/figure-mesh-db.test.ts +0 -246
- package/server/service/figure/figure-mesh-store.ts +0 -91
- package/server/service/figure/figure-mutation.ts +0 -656
- package/server/service/figure/figure-namespace-db.test.ts +0 -315
- package/server/service/figure/figure-namespace-entity.ts +0 -67
- package/server/service/figure/figure-namespace-resolver.ts +0 -54
- package/server/service/figure/figure-namespace.ts +0 -156
- package/server/service/figure/figure-package-export.ts +0 -136
- package/server/service/figure/figure-proposal-db.test.ts +0 -117
- package/server/service/figure/figure-proposal-record.ts +0 -38
- package/server/service/figure/figure-proposal.ts +0 -41
- package/server/service/figure/figure-propose-clips.test.ts +0 -69
- package/server/service/figure/figure-propose-steps.test.ts +0 -324
- package/server/service/figure/figure-propose-steps.ts +0 -354
- package/server/service/figure/figure-propose-type.ts +0 -46
- package/server/service/figure/figure-public-db.test.ts +0 -288
- package/server/service/figure/figure-public.ts +0 -60
- package/server/service/figure/figure-query.ts +0 -511
- package/server/service/figure/figure-release-check.test.ts +0 -63
- package/server/service/figure/figure-release-record-db.test.ts +0 -153
- package/server/service/figure/figure-release-size-db.test.ts +0 -156
- package/server/service/figure/figure-rename-db.test.ts +0 -237
- package/server/service/figure/figure-rename.test.ts +0 -117
- package/server/service/figure/figure-rename.ts +0 -143
- package/server/service/figure/figure-replaced-draft.ts +0 -99
- package/server/service/figure/figure-revert-db.test.ts +0 -163
- package/server/service/figure/figure-revert-race.pg.test.ts +0 -168
- package/server/service/figure/figure-revert.ts +0 -186
- package/server/service/figure/figure-subject.test.ts +0 -41
- package/server/service/figure/figure-subject.ts +0 -21
- package/server/service/figure/figure-thumbnail-db.test.ts +0 -279
- package/server/service/figure/figure-thumbnail-reader.ts +0 -20
- package/server/service/figure/figure-thumbnail-store.ts +0 -111
- package/server/service/figure/figure-thumbnail-upgrade.pg.test.ts +0 -93
- package/server/service/figure/figure-thumbnail-upgrade.ts +0 -70
- package/server/service/figure/figure-tool-doors.test.ts +0 -127
- package/server/service/figure/figure-tools-door-db.test.ts +0 -227
- package/server/service/figure/figure-tools.test.ts +0 -817
- package/server/service/figure/figure-tools.ts +0 -611
- package/server/service/figure/figure-type.ts +0 -241
- package/server/service/figure/figure-write.test.ts +0 -15
- package/server/service/figure/figure-write.ts +0 -131
- package/server/service/figure/figure.ts +0 -241
- package/server/service/figure/index.ts +0 -13
- package/server/service/figure-recipe/figure-recipe-resolver.ts +0 -38
- package/server/service/figure-recipe/figure-recipe-templates.test.ts +0 -47
- package/server/service/figure-recipe/figure-recipe-templates.ts +0 -70
- package/server/service/figure-recipe/figure-recipe-type.ts +0 -31
- package/server/service/figure-recipe/index.ts +0 -3
- package/server/service/index.ts +0 -34
- package/tsconfig.json +0 -14
|
@@ -1,536 +0,0 @@
|
|
|
1
|
-
import type { DataSource } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
const { DataSource: TypeOrmDataSource } = require('typeorm')
|
|
4
|
-
const shell = require('@things-factory/shell')
|
|
5
|
-
const authBase = require('@things-factory/auth-base')
|
|
6
|
-
|
|
7
|
-
let dataSource: DataSource | null = null
|
|
8
|
-
let Figure: any
|
|
9
|
-
let FigureHistory: any
|
|
10
|
-
let FigureQuery: any
|
|
11
|
-
let testDomain: any
|
|
12
|
-
|
|
13
|
-
function loadCompiled(modulePath: string): any {
|
|
14
|
-
const { existsSync } = require('fs')
|
|
15
|
-
const { join } = require('path')
|
|
16
|
-
const resolved = join(__dirname, '..', '..', '..', 'dist-server', `${modulePath}.js`)
|
|
17
|
-
|
|
18
|
-
if (!existsSync(resolved)) {
|
|
19
|
-
throw new Error(
|
|
20
|
-
`figure-service 산출물이 없다: ${resolved}\n` +
|
|
21
|
-
`이 시험은 tsc 산출물을 든다. 먼저 빌드할 것:\n` +
|
|
22
|
-
` yarn workspace @things-factory/figure-service build:server`
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return require(resolved)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const model = require('@hatiolab/figure-model')
|
|
30
|
-
|
|
31
|
-
/** A released figure's source: one box, named `part`, `size` mm on each side. */
|
|
32
|
-
const box = (part = 'box-1', size = 100) =>
|
|
33
|
-
model.serializeFigureAsset(model.addFigureBox(model.createFigureAsset('Test box'), { id: part, size: { x: size, y: size, z: size }, position: { x: 0, y: size / 2, z: 0 } }))
|
|
34
|
-
const sampleSource = box()
|
|
35
|
-
|
|
36
|
-
/** The same box under a different part name, so a test can tell the sources apart. */
|
|
37
|
-
const boxNamed = (_type: string, part: string) => box(part)
|
|
38
|
-
|
|
39
|
-
/** What a consumer was handed: the part ids of the asset, and a part's width. */
|
|
40
|
-
const partsOf = (payload: any): string[] => payload.asset.document.model.nodes.filter((n: any) => n.op === 'place@1').map((n: any) => n.id)
|
|
41
|
-
const widthOf = (payload: any, part: string): number => payload.asset.designInputs[`${part}.size.x`]
|
|
42
|
-
|
|
43
|
-
beforeAll(async () => {
|
|
44
|
-
Figure = loadCompiled('service/figure/figure').Figure
|
|
45
|
-
FigureHistory = loadCompiled('service/figure/figure-history').FigureHistory
|
|
46
|
-
FigureQuery = loadCompiled('service/figure/figure-query').FigureQuery
|
|
47
|
-
/* A released row is saved with its history row, as releasing does: a board reads the release's own copy there (ADR-0087 decision 6). */
|
|
48
|
-
const Subscriber = loadCompiled('service/figure/event-subscriber').FigureHistoryEntitySubscriber
|
|
49
|
-
|
|
50
|
-
dataSource = new TypeOrmDataSource({
|
|
51
|
-
type: 'sqlite',
|
|
52
|
-
database: ':memory:',
|
|
53
|
-
synchronize: true,
|
|
54
|
-
dropSchema: true,
|
|
55
|
-
namingStrategy: new shell.NamingStrategy(),
|
|
56
|
-
entities: [...shell.entities, ...authBase.entities, Figure, FigureHistory],
|
|
57
|
-
subscribers: [Subscriber],
|
|
58
|
-
logging: false
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
await dataSource.initialize()
|
|
62
|
-
shell.addDataSource('default', dataSource)
|
|
63
|
-
shell.addDataSource('tx', dataSource)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
beforeEach(async () => {
|
|
67
|
-
await dataSource!.synchronize(true)
|
|
68
|
-
testDomain = await dataSource!.getRepository(shell.Domain).save({
|
|
69
|
-
name: 'test-domain',
|
|
70
|
-
subdomain: 'test-domain'
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
afterAll(async () => {
|
|
75
|
-
if (!dataSource) return
|
|
76
|
-
shell.removeDataSource('default')
|
|
77
|
-
shell.removeDataSource('tx')
|
|
78
|
-
await dataSource.destroy()
|
|
79
|
-
dataSource = null
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
function makeContext() {
|
|
83
|
-
return {
|
|
84
|
-
state: {
|
|
85
|
-
domain: testDomain,
|
|
86
|
-
user: { id: 'user-1' }
|
|
87
|
-
}
|
|
88
|
-
} as any
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
describe('figureBlueprint 질의 — 소비처(board, twin, things-scene)에 발행된 자산 전달', () => {
|
|
92
|
-
it('존재하지 않는 타입은 null을 반환한다', async () => {
|
|
93
|
-
const query = new FigureQuery()
|
|
94
|
-
const result = await query.figureBlueprint('NON_EXISTENT', makeContext())
|
|
95
|
-
expect(result).toBeNull()
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('초안(draft) 상태이고 발행 이력이 없는 Figure는 null을 반환한다 (초안 유출 차단)', async () => {
|
|
99
|
-
const repo = dataSource!.getRepository(Figure)
|
|
100
|
-
await repo.save({
|
|
101
|
-
domain: testDomain,
|
|
102
|
-
type: 'DRAFT_FIGURE',
|
|
103
|
-
name: '초안 피규어',
|
|
104
|
-
state: 'draft',
|
|
105
|
-
source: sampleSource,
|
|
106
|
-
version: 0
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
const query = new FigureQuery()
|
|
110
|
-
const result = await query.figureBlueprint('DRAFT_FIGURE', makeContext())
|
|
111
|
-
expect(result).toBeNull()
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('발행된(released) Figure는 자산을 format · type 과 함께 반환한다', async () => {
|
|
115
|
-
const repo = dataSource!.getRepository(Figure)
|
|
116
|
-
await repo.save({
|
|
117
|
-
domain: testDomain,
|
|
118
|
-
type: 'RELEASED_FIGURE',
|
|
119
|
-
name: '발행 피규어',
|
|
120
|
-
state: 'released',
|
|
121
|
-
source: sampleSource,
|
|
122
|
-
version: 1
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
const query = new FigureQuery()
|
|
126
|
-
const result = await query.figureBlueprint('RELEASED_FIGURE', makeContext())
|
|
127
|
-
expect(result).not.toBeNull()
|
|
128
|
-
expect(result.format).toBeUndefined()
|
|
129
|
-
expect(result.type).toBe('RELEASED_FIGURE')
|
|
130
|
-
expect(result.asset.version).toBe('figure-asset-1')
|
|
131
|
-
expect(partsOf(result)).toEqual(['box-1'])
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('현재 저작 중(draft)이더라도 과거 발행 버전(FigureHistory)이 있으면 최신 발행 버전을 반환한다', async () => {
|
|
135
|
-
const repo = dataSource!.getRepository(Figure)
|
|
136
|
-
const historyRepo = dataSource!.getRepository(FigureHistory)
|
|
137
|
-
|
|
138
|
-
const v1Source = sampleSource
|
|
139
|
-
const draftSource = box('box-modified', 200)
|
|
140
|
-
|
|
141
|
-
const figure = await repo.save({
|
|
142
|
-
domain: testDomain,
|
|
143
|
-
type: 'UPDATING_FIGURE',
|
|
144
|
-
name: '수정 중인 피규어',
|
|
145
|
-
state: 'draft',
|
|
146
|
-
source: draftSource,
|
|
147
|
-
version: 1
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
// 과거 발행된 v1 이력
|
|
151
|
-
await historyRepo.save({
|
|
152
|
-
domain: testDomain,
|
|
153
|
-
originalId: figure.id,
|
|
154
|
-
type: 'UPDATING_FIGURE',
|
|
155
|
-
name: 'v1 발행 버전',
|
|
156
|
-
state: 'released',
|
|
157
|
-
version: 1,
|
|
158
|
-
source: v1Source
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
const query = new FigureQuery()
|
|
162
|
-
const result = await query.figureBlueprint('UPDATING_FIGURE', makeContext())
|
|
163
|
-
|
|
164
|
-
expect(result).not.toBeNull()
|
|
165
|
-
// 소비처는 수정 중인 초안(box-modified, size 200)이 아니라 기발행된 버전(box-1, size 100)을 본다!
|
|
166
|
-
expect(partsOf(result)).toEqual(['box-1'])
|
|
167
|
-
expect(widthOf(result, 'box-1')).toBe(100)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
/*
|
|
171
|
-
The test above proves a release is reached through history, with one history row. It cannot tell
|
|
172
|
-
`version: 'DESC'` from `'ASC'`, nor from no ordering at all — with a single row every one of them
|
|
173
|
-
answers the same. Consumers are promised the LATEST release, so the ordering is the claim, and it
|
|
174
|
-
needs more than one row to be a claim at all. The rows go in out of order because an ordering bug
|
|
175
|
-
that reads insertion order would otherwise pass.
|
|
176
|
-
*/
|
|
177
|
-
it('answers the highest released version when a type has several', async () => {
|
|
178
|
-
const repo = dataSource!.getRepository(Figure)
|
|
179
|
-
const historyRepo = dataSource!.getRepository(FigureHistory)
|
|
180
|
-
|
|
181
|
-
const figure = await repo.save({
|
|
182
|
-
domain: testDomain,
|
|
183
|
-
type: 'MULTI',
|
|
184
|
-
name: 'in authoring',
|
|
185
|
-
state: 'draft',
|
|
186
|
-
source: boxNamed('MULTI', 'unreleased-draft'),
|
|
187
|
-
version: 3
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
for (const version of [1, 3, 2]) {
|
|
191
|
-
await historyRepo.save({
|
|
192
|
-
domain: testDomain,
|
|
193
|
-
originalId: figure.id,
|
|
194
|
-
type: 'MULTI',
|
|
195
|
-
name: `v${version}`,
|
|
196
|
-
state: 'released',
|
|
197
|
-
version,
|
|
198
|
-
source: boxNamed('MULTI', `v${version}`)
|
|
199
|
-
})
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const result = await new FigureQuery().figureBlueprint('MULTI', makeContext())
|
|
203
|
-
|
|
204
|
-
expect(result).not.toBeNull()
|
|
205
|
-
expect(partsOf(result)).toEqual(['v3'])
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
/*
|
|
209
|
-
Every edit to a released figure writes a history row, and those rows are not all releases. A
|
|
210
|
-
draft row sitting at a higher version than the last release is the ordinary state of a figure
|
|
211
|
-
being worked on, so reading the newest row rather than the newest RELEASED row would hand
|
|
212
|
-
consumers unreleased work — the leak the whole door exists to stop.
|
|
213
|
-
*/
|
|
214
|
-
it('skips a draft history that sits above the last release', async () => {
|
|
215
|
-
const repo = dataSource!.getRepository(Figure)
|
|
216
|
-
const historyRepo = dataSource!.getRepository(FigureHistory)
|
|
217
|
-
|
|
218
|
-
const figure = await repo.save({
|
|
219
|
-
domain: testDomain,
|
|
220
|
-
type: 'WIP',
|
|
221
|
-
name: 'in authoring',
|
|
222
|
-
state: 'draft',
|
|
223
|
-
source: boxNamed('WIP', 'unreleased-draft'),
|
|
224
|
-
version: 5
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
await historyRepo.save({
|
|
228
|
-
domain: testDomain,
|
|
229
|
-
originalId: figure.id,
|
|
230
|
-
type: 'WIP',
|
|
231
|
-
name: 'v2',
|
|
232
|
-
state: 'released',
|
|
233
|
-
version: 2,
|
|
234
|
-
source: boxNamed('WIP', 'released-v2')
|
|
235
|
-
})
|
|
236
|
-
await historyRepo.save({
|
|
237
|
-
domain: testDomain,
|
|
238
|
-
originalId: figure.id,
|
|
239
|
-
type: 'WIP',
|
|
240
|
-
name: 'v5',
|
|
241
|
-
state: 'draft',
|
|
242
|
-
version: 5,
|
|
243
|
-
source: boxNamed('WIP', 'draft-v5')
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
const result = await new FigureQuery().figureBlueprint('WIP', makeContext())
|
|
247
|
-
|
|
248
|
-
expect(result).not.toBeNull()
|
|
249
|
-
expect(partsOf(result)).toEqual(['released-v2'])
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
/*
|
|
253
|
-
History rows are looked up by originalId, which is a figure id and so already unique. That makes
|
|
254
|
-
the domain in the same where-clause look redundant, and redundant-looking filters get deleted.
|
|
255
|
-
It is not redundant: it is the tenant boundary on a door that consumers call, so a test holds it.
|
|
256
|
-
*/
|
|
257
|
-
it('does not reach a history row that belongs to another domain', async () => {
|
|
258
|
-
const domainRepo = dataSource!.getRepository(shell.Domain)
|
|
259
|
-
const other = await domainRepo.save({ name: 'other-domain', subdomain: 'other-domain' })
|
|
260
|
-
|
|
261
|
-
const repo = dataSource!.getRepository(Figure)
|
|
262
|
-
const historyRepo = dataSource!.getRepository(FigureHistory)
|
|
263
|
-
|
|
264
|
-
const figure = await repo.save({
|
|
265
|
-
domain: testDomain,
|
|
266
|
-
type: 'LEAKY',
|
|
267
|
-
name: 'never released here',
|
|
268
|
-
state: 'draft',
|
|
269
|
-
source: boxNamed('LEAKY', 'unreleased-draft'),
|
|
270
|
-
version: 0
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
await historyRepo.save({
|
|
274
|
-
domain: other,
|
|
275
|
-
originalId: figure.id,
|
|
276
|
-
type: 'LEAKY',
|
|
277
|
-
name: 'released elsewhere',
|
|
278
|
-
state: 'released',
|
|
279
|
-
version: 1,
|
|
280
|
-
source: boxNamed('LEAKY', 'other-domain-release')
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
const result = await new FigureQuery().figureBlueprint('LEAKY', makeContext())
|
|
284
|
-
|
|
285
|
-
expect(result).toBeNull()
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
/*
|
|
289
|
-
This used to answer null, and that was the defect. Null says one thing on this door — nobody
|
|
290
|
-
published this type — and the board reads it that way: it draws the stand-in of ADR-0063 결정 1 and
|
|
291
|
-
the scene opens. A released figure whose stored source no longer compiles is a different fact. The
|
|
292
|
-
author published it, the catalogue says released, and with null the only trace was a console line
|
|
293
|
-
on the server, so the author saw "my figure does not show on the board" and nothing more. That is
|
|
294
|
-
the silence ADR-0053 refuses (chief architect, ADR-0063 결정 2 보탬).
|
|
295
|
-
|
|
296
|
-
So it refuses with a name, and the name carries what someone needs to find the figure: the type,
|
|
297
|
-
its id, and the edition that does not compile. The sentence is built where the request's language
|
|
298
|
-
is known, which is why the gate throws no sentence of its own (ADR-0054).
|
|
299
|
-
*/
|
|
300
|
-
it('refuses with a named refusal when the stored source cannot be compiled', async () => {
|
|
301
|
-
const repo = dataSource!.getRepository(Figure)
|
|
302
|
-
const saved = await repo.save({
|
|
303
|
-
domain: testDomain,
|
|
304
|
-
type: 'BROKEN',
|
|
305
|
-
name: 'corrupted',
|
|
306
|
-
state: 'released',
|
|
307
|
-
source: '{ this is not json',
|
|
308
|
-
version: 4
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
const query = new FigureQuery()
|
|
312
|
-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
313
|
-
try {
|
|
314
|
-
await expect(query.figureBlueprint('BROKEN', makeContext())).rejects.toMatchObject({
|
|
315
|
-
name: 'Refusal',
|
|
316
|
-
code: 'figure-release-does-not-compile',
|
|
317
|
-
params: { type: 'BROKEN', figureId: saved.id, version: 4 }
|
|
318
|
-
})
|
|
319
|
-
} finally {
|
|
320
|
-
spy.mockRestore()
|
|
321
|
-
}
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
/*
|
|
325
|
-
The edition named in that refusal is the one the board was handed, which is not the row's own
|
|
326
|
-
version once the author starts editing again: the row moves on to the next draft while the board
|
|
327
|
-
keeps drawing the last release. Naming the draft would send someone to look at a source that is
|
|
328
|
-
not the one failing.
|
|
329
|
-
*/
|
|
330
|
-
it('the refusal names the released edition, not the draft being edited', async () => {
|
|
331
|
-
const repo = dataSource!.getRepository(Figure)
|
|
332
|
-
const historyRepo = dataSource!.getRepository(FigureHistory)
|
|
333
|
-
|
|
334
|
-
const figure = await repo.save({
|
|
335
|
-
domain: testDomain,
|
|
336
|
-
type: 'BROKEN_HISTORY',
|
|
337
|
-
name: 'in authoring again',
|
|
338
|
-
state: 'draft',
|
|
339
|
-
source: boxNamed('BROKEN_HISTORY', 'healthy-draft'),
|
|
340
|
-
version: 9
|
|
341
|
-
})
|
|
342
|
-
await historyRepo.save({
|
|
343
|
-
domain: testDomain,
|
|
344
|
-
originalId: figure.id,
|
|
345
|
-
type: 'BROKEN_HISTORY',
|
|
346
|
-
name: 'v2',
|
|
347
|
-
state: 'released',
|
|
348
|
-
version: 2,
|
|
349
|
-
source: '{ this is not json'
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
353
|
-
try {
|
|
354
|
-
await expect(new FigureQuery().figureBlueprint('BROKEN_HISTORY', makeContext())).rejects.toMatchObject({
|
|
355
|
-
code: 'figure-release-does-not-compile',
|
|
356
|
-
params: { version: 2 }
|
|
357
|
-
})
|
|
358
|
-
} finally {
|
|
359
|
-
spy.mockRestore()
|
|
360
|
-
}
|
|
361
|
-
})
|
|
362
|
-
|
|
363
|
-
/*
|
|
364
|
-
A refusal only becomes a sentence in the caller's language by passing through `SpeakRefusals`,
|
|
365
|
-
which the class declares and which a direct call like the ones above never runs. Without that
|
|
366
|
-
declaration this refusal reaches the board as Apollo's INTERNAL_SERVER_ERROR carrying the English
|
|
367
|
-
fallback, and `extensions.refusal` — the thing that tells a client the server refused on purpose —
|
|
368
|
-
is absent. The tests above stay green either way, so the declaration is read from the source.
|
|
369
|
-
*/
|
|
370
|
-
it('declares SpeakRefusals on the class, or the refusal arrives as a server error', () => {
|
|
371
|
-
const { readFileSync } = require('fs')
|
|
372
|
-
const { join } = require('path')
|
|
373
|
-
const source = readFileSync(join(__dirname, 'figure-query.ts'), 'utf-8')
|
|
374
|
-
|
|
375
|
-
const at = source.indexOf('export class FigureQuery')
|
|
376
|
-
expect(at).toBeGreaterThan(-1)
|
|
377
|
-
expect(source.slice(0, at)).toContain('@UseMiddleware(SpeakRefusals)')
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
/* ADR-0104 decision 2: a consumer that pins a release asks for it by number; every answer carries its number. */
|
|
381
|
-
describe('a release asked for by number', () => {
|
|
382
|
-
async function threeReleases(type: string) {
|
|
383
|
-
const figure = await dataSource!.getRepository(Figure).save({ domain: testDomain, type, name: 'pinned', state: 'draft', source: boxNamed(type, 'unreleased'), version: 3 })
|
|
384
|
-
for (const version of [1, 2, 3])
|
|
385
|
-
await dataSource!.getRepository(FigureHistory).save({ domain: testDomain, originalId: figure.id, type, name: `v${version}`, state: 'released', version, source: boxNamed(type, `v${version}`) })
|
|
386
|
-
return figure
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
it('answers the latest with its number when no number is asked', async () => {
|
|
390
|
-
await threeReleases('PINNED')
|
|
391
|
-
const result = await new FigureQuery().figureBlueprint('PINNED', makeContext())
|
|
392
|
-
expect([result.version, partsOf(result)]).toEqual([3, ['v3']])
|
|
393
|
-
})
|
|
394
|
-
|
|
395
|
-
it('answers an older release by its number, not the latest', async () => {
|
|
396
|
-
await threeReleases('PINNED')
|
|
397
|
-
const result = await new FigureQuery().figureBlueprint('PINNED', makeContext(), 1)
|
|
398
|
-
expect([result.version, partsOf(result)]).toEqual([1, ['v1']])
|
|
399
|
-
})
|
|
400
|
-
|
|
401
|
-
it('refuses a number that was never released by name, never answering another release', async () => {
|
|
402
|
-
await threeReleases('PINNED')
|
|
403
|
-
await expect(new FigureQuery().figureBlueprint('PINNED', makeContext(), 7)).rejects.toMatchObject({ code: 'figure-release-not-found' })
|
|
404
|
-
for (const lang of ['ko', 'en']) expect(require(`../../../translations/${lang}.json`)['error.figure-release-not-found']).toMatch(/\{latest\}/)
|
|
405
|
-
})
|
|
406
|
-
|
|
407
|
-
it('a type nobody released is still null, whatever number is asked', async () => {
|
|
408
|
-
expect(await new FigureQuery().figureBlueprint('NOBODY', makeContext(), 1)).toBeNull()
|
|
409
|
-
})
|
|
410
|
-
|
|
411
|
-
it('a released row is answered with its own number', async () => {
|
|
412
|
-
await dataSource!.getRepository(Figure).save({ domain: testDomain, type: 'ROW', name: 'row', state: 'released', source: sampleSource, version: 4 })
|
|
413
|
-
expect((await new FigureQuery().figureBlueprint('ROW', makeContext())).version).toBe(4)
|
|
414
|
-
expect((await new FigureQuery().figureBlueprint('ROW', makeContext(), 4)).version).toBe(4)
|
|
415
|
-
})
|
|
416
|
-
})
|
|
417
|
-
|
|
418
|
-
describe('a child domain shadows its parent only with a released version', () => {
|
|
419
|
-
const boxOf = (_type: string, part: string) => box(part)
|
|
420
|
-
|
|
421
|
-
let childSeq = 0
|
|
422
|
-
|
|
423
|
-
async function childOf(parent: any) {
|
|
424
|
-
const repo = dataSource!.getRepository(shell.Domain)
|
|
425
|
-
/* A chain needs a distinct subdomain per level; the column is unique. */
|
|
426
|
-
const name = `child-domain-${++childSeq}`
|
|
427
|
-
const saved = await repo.save({ name, subdomain: name, parent })
|
|
428
|
-
return repo.findOne({ where: { id: saved.id } })
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const contextIn = (domain: any) => ({ state: { domain, user: { id: 'user-1' } } }) as any
|
|
432
|
-
|
|
433
|
-
it('falls back to the parent release when the child has only a draft', async () => {
|
|
434
|
-
const child = await childOf(testDomain)
|
|
435
|
-
expect(child.parentId).toBe(testDomain.id)
|
|
436
|
-
|
|
437
|
-
const repo = dataSource!.getRepository(Figure)
|
|
438
|
-
await repo.save({ domain: testDomain, type: 'CONVEYOR', name: '표준', state: 'released', source: boxOf('CONVEYOR', 'standard'), version: 1 })
|
|
439
|
-
await repo.save({ domain: child, type: 'CONVEYOR', name: '테넌트 초안', state: 'draft', source: boxOf('CONVEYOR', 'tenant'), version: 0 })
|
|
440
|
-
|
|
441
|
-
const result = await new FigureQuery().figureBlueprint('CONVEYOR', contextIn(child))
|
|
442
|
-
|
|
443
|
-
expect(result).not.toBeNull()
|
|
444
|
-
expect(partsOf(result)).toEqual(['standard'])
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
it('uses the child release when the child has one', async () => {
|
|
448
|
-
const child = await childOf(testDomain)
|
|
449
|
-
|
|
450
|
-
const repo = dataSource!.getRepository(Figure)
|
|
451
|
-
await repo.save({ domain: testDomain, type: 'CONVEYOR', name: '표준', state: 'released', source: boxOf('CONVEYOR', 'standard'), version: 1 })
|
|
452
|
-
await repo.save({ domain: child, type: 'CONVEYOR', name: '테넌트', state: 'released', source: boxOf('CONVEYOR', 'tenant'), version: 1 })
|
|
453
|
-
|
|
454
|
-
const result = await new FigureQuery().figureBlueprint('CONVEYOR', contextIn(child))
|
|
455
|
-
|
|
456
|
-
expect(partsOf(result)).toEqual(['tenant'])
|
|
457
|
-
})
|
|
458
|
-
|
|
459
|
-
/*
|
|
460
|
-
The two cases above give the child a row whose own state decides the answer. This is the case
|
|
461
|
-
between them: the child released once and is editing again, so its row says draft while a
|
|
462
|
-
release of its own exists. The fallback must not read "the child row is a draft" as "the child
|
|
463
|
-
has nothing" — a tenant that starts a second edit would then see the standard figure come back
|
|
464
|
-
in place of the one it published.
|
|
465
|
-
*/
|
|
466
|
-
it('uses the child own release when the child row is a draft again', async () => {
|
|
467
|
-
const child = await childOf(testDomain)
|
|
468
|
-
|
|
469
|
-
const repo = dataSource!.getRepository(Figure)
|
|
470
|
-
const historyRepo = dataSource!.getRepository(FigureHistory)
|
|
471
|
-
|
|
472
|
-
await repo.save({ domain: testDomain, type: 'CONVEYOR', name: '표준', state: 'released', source: boxOf('CONVEYOR', 'standard'), version: 1 })
|
|
473
|
-
const tenant = await repo.save({ domain: child, type: 'CONVEYOR', name: '테넌트', state: 'draft', source: boxOf('CONVEYOR', 'tenant-wip'), version: 1 })
|
|
474
|
-
await historyRepo.save({
|
|
475
|
-
domain: child,
|
|
476
|
-
originalId: tenant.id,
|
|
477
|
-
type: 'CONVEYOR',
|
|
478
|
-
name: '테넌트 v1',
|
|
479
|
-
state: 'released',
|
|
480
|
-
version: 1,
|
|
481
|
-
source: boxOf('CONVEYOR', 'tenant-v1')
|
|
482
|
-
})
|
|
483
|
-
|
|
484
|
-
const result = await new FigureQuery().figureBlueprint('CONVEYOR', contextIn(child))
|
|
485
|
-
|
|
486
|
-
expect(result).not.toBeNull()
|
|
487
|
-
expect(partsOf(result)).toEqual(['tenant-v1'])
|
|
488
|
-
})
|
|
489
|
-
|
|
490
|
-
/*
|
|
491
|
-
The lookup consults the caller's domain and its parent, and stops there. A grandchild therefore
|
|
492
|
-
does not inherit, which is the current rule rather than an oversight — pinning it here means
|
|
493
|
-
the day someone needs deeper inheritance they change this test on purpose and take the ruling
|
|
494
|
-
with them, instead of finding the depth by accident in a scene that renders nothing.
|
|
495
|
-
*/
|
|
496
|
-
it('does not climb past the immediate parent', async () => {
|
|
497
|
-
const mid = await childOf(testDomain)
|
|
498
|
-
const leaf = await childOf(mid)
|
|
499
|
-
expect(leaf.parentId).toBe(mid.id)
|
|
500
|
-
|
|
501
|
-
const repo = dataSource!.getRepository(Figure)
|
|
502
|
-
await repo.save({ domain: testDomain, type: 'CONVEYOR', name: '표준', state: 'released', source: boxOf('CONVEYOR', 'standard'), version: 1 })
|
|
503
|
-
|
|
504
|
-
expect(await new FigureQuery().figureBlueprint('CONVEYOR', contextIn(leaf))).toBeNull()
|
|
505
|
-
})
|
|
506
|
-
})
|
|
507
|
-
|
|
508
|
-
/*
|
|
509
|
-
Every test above calls the resolver method directly, so none of them passes through the
|
|
510
|
-
`@privilege` directive — that is attached when the schema is assembled. They stay green
|
|
511
|
-
whether the declaration is there or not.
|
|
512
|
-
|
|
513
|
-
Without a declaration this field is open to callers who have not even signed in
|
|
514
|
-
(`auth-rebuild.md` §1), so that gap is the thing worth guarding. The check reads the source
|
|
515
|
-
rather than the compiled output because the declaration is authored there, and it pins the
|
|
516
|
-
category: `figure` is the authoring permission, and requiring it here would leave board and
|
|
517
|
-
twin users with an empty palette. Someone who hits that wall will be tempted to delete this
|
|
518
|
-
line; the failure message is for them.
|
|
519
|
-
*/
|
|
520
|
-
it('declares figure-published on the consumer door, not the authoring permission', () => {
|
|
521
|
-
const { readFileSync } = require('fs')
|
|
522
|
-
const { join } = require('path')
|
|
523
|
-
const source = readFileSync(join(__dirname, 'figure-query.ts'), 'utf-8')
|
|
524
|
-
|
|
525
|
-
const at = source.indexOf('async figureBlueprint')
|
|
526
|
-
expect(at).toBeGreaterThan(-1)
|
|
527
|
-
|
|
528
|
-
const preceding = source.slice(0, at)
|
|
529
|
-
const directive = preceding.lastIndexOf("@Directive('@privilege(")
|
|
530
|
-
const declaration = preceding.slice(directive, preceding.indexOf('\n', directive))
|
|
531
|
-
|
|
532
|
-
expect(declaration).toContain('category: "figure-published"')
|
|
533
|
-
expect(declaration).toContain('privilege: "query"')
|
|
534
|
-
expect(declaration).toContain('domainOwnerGranted: true')
|
|
535
|
-
})
|
|
536
|
-
})
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The catalogue fields -- type, category, tags -- live on the row, not in the source, so the source's compare-and-swap
|
|
3
|
-
* does not hold them. An update of them that says what the editor saw goes on only while the row still holds that
|
|
4
|
-
* (outside review 2026-11-09, :3300: two tabs set the category, the later one wrote over the first without a word).
|
|
5
|
-
*/
|
|
6
|
-
import type { DataSource } from 'typeorm'
|
|
7
|
-
|
|
8
|
-
const { DataSource: TypeOrmDataSource } = require('typeorm')
|
|
9
|
-
const shell = require('@things-factory/shell')
|
|
10
|
-
const authBase = require('@things-factory/auth-base')
|
|
11
|
-
const settingBase = require('@things-factory/setting-base')
|
|
12
|
-
const { createFigureAsset, addFigureBox, serializeFigureAsset, parseFigureAsset } = require('@hatiolab/figure-model')
|
|
13
|
-
|
|
14
|
-
let dataSource: DataSource | null = null
|
|
15
|
-
let Figure: any
|
|
16
|
-
let FigureMutation: any
|
|
17
|
-
let write: any
|
|
18
|
-
|
|
19
|
-
function loadCompiled(modulePath: string): any {
|
|
20
|
-
const { existsSync } = require('fs')
|
|
21
|
-
const { join } = require('path')
|
|
22
|
-
const resolved = join(__dirname, '..', '..', '..', 'dist-server', `${modulePath}.js`)
|
|
23
|
-
if (!existsSync(resolved))
|
|
24
|
-
throw new Error(`figure-service 산출물이 없다: ${resolved}\n먼저 빌드할 것:\n yarn workspace @things-factory/figure-service build:server`)
|
|
25
|
-
return require(resolved)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
beforeAll(async () => {
|
|
29
|
-
Figure = loadCompiled('service/figure/figure').Figure
|
|
30
|
-
const FigureHistory = loadCompiled('service/figure/figure-history').FigureHistory
|
|
31
|
-
const FigureNamespace = loadCompiled('service/figure/figure-namespace-entity').FigureNamespace
|
|
32
|
-
const Subscriber = loadCompiled('service/figure/event-subscriber').FigureHistoryEntitySubscriber
|
|
33
|
-
;({ FigureMutation } = loadCompiled('service/figure/figure-mutation'))
|
|
34
|
-
write = loadCompiled('service/figure/figure-write')
|
|
35
|
-
dataSource = new TypeOrmDataSource({
|
|
36
|
-
type: 'sqlite',
|
|
37
|
-
database: ':memory:',
|
|
38
|
-
synchronize: true,
|
|
39
|
-
dropSchema: true,
|
|
40
|
-
namingStrategy: new shell.NamingStrategy(),
|
|
41
|
-
entities: [...shell.entities, ...authBase.entities, ...settingBase.entities, Figure, FigureHistory, FigureNamespace],
|
|
42
|
-
subscribers: [Subscriber],
|
|
43
|
-
logging: false
|
|
44
|
-
})
|
|
45
|
-
await dataSource.initialize()
|
|
46
|
-
shell.addDataSource('default', dataSource)
|
|
47
|
-
shell.addDataSource('tx', dataSource)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
afterAll(async () => {
|
|
51
|
-
await dataSource?.destroy()
|
|
52
|
-
dataSource = null
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
const source = (name: string) =>
|
|
56
|
-
serializeFigureAsset(addFigureBox(createFigureAsset(name), { id: 'body', size: { x: 100, y: 100, z: 100 }, position: { x: 0, y: 50, z: 0 } }))
|
|
57
|
-
let seq = 0
|
|
58
|
-
async function figureIn() {
|
|
59
|
-
const name = `seen-${++seq}`
|
|
60
|
-
const domain = await dataSource!.getRepository(shell.Domain).save({ name, subdomain: name })
|
|
61
|
-
const ctx = { state: { domain, user: undefined, tx: dataSource!.manager } }
|
|
62
|
-
const figure = await new FigureMutation().saveFigure(source('Bin'), ctx, undefined, undefined, require('crypto').randomUUID(), undefined, `bin-${seq}`)
|
|
63
|
-
return { ctx, id: figure.id as string }
|
|
64
|
-
}
|
|
65
|
-
const update = (ctx: any, id: string, patch: object, seen?: object) => new FigureMutation().updateFigure(id, patch, ctx, seen)
|
|
66
|
-
const row = (id: string) => dataSource!.getRepository(Figure).findOneOrFail({ where: { id } })
|
|
67
|
-
|
|
68
|
-
describe('a catalogue field changed by another editor first', () => {
|
|
69
|
-
it('two editors saw no category: the first is written, the second refused with what the row holds now', async () => {
|
|
70
|
-
const { ctx, id } = await figureIn()
|
|
71
|
-
await update(ctx, id, { category: '검증-B' }, { category: null })
|
|
72
|
-
await expect(update(ctx, id, { category: '검증-A' }, { category: null })).rejects.toMatchObject({
|
|
73
|
-
extensions: { code: 'FIGURE_CATALOG_CONFLICT', fields: [{ field: 'category', now: '검증-B' }] }
|
|
74
|
-
})
|
|
75
|
-
expect((await row(id)).category).toBe('검증-B')
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('seen as the row holds it, it is written; an empty category is no category either way', async () => {
|
|
79
|
-
const { ctx, id } = await figureIn()
|
|
80
|
-
await update(ctx, id, { category: '' }, { category: null })
|
|
81
|
-
await update(ctx, id, { category: 'lines' }, { category: null })
|
|
82
|
-
await update(ctx, id, { category: 'cells' }, { category: 'lines' })
|
|
83
|
-
expect((await row(id)).category).toBe('cells')
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('tags are compared as a list: an empty list is none, another list is a conflict', async () => {
|
|
87
|
-
const { ctx, id } = await figureIn()
|
|
88
|
-
await update(ctx, id, { tags: ['a'] }, { tags: [] })
|
|
89
|
-
await expect(update(ctx, id, { tags: ['b'] }, { tags: null })).rejects.toMatchObject({
|
|
90
|
-
extensions: { code: 'FIGURE_CATALOG_CONFLICT', fields: [{ field: 'tags', now: ['a'] }] }
|
|
91
|
-
})
|
|
92
|
-
await update(ctx, id, { tags: ['a', 'b'] }, { tags: ['a'] })
|
|
93
|
-
expect((await row(id)).tags).toEqual(['a', 'b'])
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('refused, nothing of the update is written -- the source sent with it neither', async () => {
|
|
97
|
-
const { ctx, id } = await figureIn()
|
|
98
|
-
await update(ctx, id, { category: 'first' }, { category: null })
|
|
99
|
-
const before = await row(id)
|
|
100
|
-
const renamed = serializeFigureAsset({ ...parseFigureAsset(before.source), name: 'Renamed' })
|
|
101
|
-
await expect(update(ctx, id, { category: 'second', source: renamed }, { category: null })).rejects.toMatchObject({ extensions: { code: 'FIGURE_CATALOG_CONFLICT' } })
|
|
102
|
-
expect((await row(id)).source).toBe(before.source)
|
|
103
|
-
expect((await row(id)).category).toBe('first')
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('a change between the check and the write finds nothing to write: the same check is in the UPDATE', async () => {
|
|
107
|
-
const { id } = await figureIn()
|
|
108
|
-
const repository = dataSource!.getRepository(Figure)
|
|
109
|
-
await repository.update({ id }, { category: 'meanwhile', tags: ['x'] })
|
|
110
|
-
for (const seen of [{ category: null }, { category: 'before' }, { tags: null }, { tags: ['y'] }]) {
|
|
111
|
-
const result = await repository.update({ id, ...write.catalogCriteriaOf(seen) }, { description: 'not written' })
|
|
112
|
-
expect(result.affected).toBe(0)
|
|
113
|
-
}
|
|
114
|
-
for (const seen of [{ category: 'meanwhile' }, { tags: ['x'] }, { category: 'meanwhile', tags: ['x'] }]) {
|
|
115
|
-
const result = await repository.update({ id, ...write.catalogCriteriaOf(seen) }, { description: 'written' })
|
|
116
|
-
expect(result.affected).toBe(1)
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('a catalogue field changed without what was seen of it is refused: there is no unchecked way to write one', async () => {
|
|
121
|
-
const { ctx, id } = await figureIn()
|
|
122
|
-
await expect(update(ctx, id, { category: 'one' })).rejects.toMatchObject({ extensions: { code: 'FIGURE_CATALOG_SEEN_REQUIRED', fields: ['category'] } })
|
|
123
|
-
await expect(update(ctx, id, { category: 'one', tags: ['a'] }, { category: null })).rejects.toMatchObject({ extensions: { code: 'FIGURE_CATALOG_SEEN_REQUIRED', fields: ['tags'] } })
|
|
124
|
-
expect((await row(id)).category).toBeNull()
|
|
125
|
-
/* A patch that changes none of them needs none: a description, a picture. */
|
|
126
|
-
await update(ctx, id, { description: 'no catalogue field' })
|
|
127
|
-
expect((await row(id)).description).toBe('no catalogue field')
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
it('only the fields changed are compared: one changed elsewhere and not by this patch does not refuse it', async () => {
|
|
131
|
-
const { ctx, id } = await figureIn()
|
|
132
|
-
await update(ctx, id, { tags: ['elsewhere'] }, { tags: null })
|
|
133
|
-
await update(ctx, id, { category: 'mine' }, { category: null })
|
|
134
|
-
expect(await row(id)).toMatchObject({ category: 'mine', tags: ['elsewhere'] })
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
it('tag order is part of the value: the same tags in another order are a change, and a conflict', async () => {
|
|
138
|
-
const { ctx, id } = await figureIn()
|
|
139
|
-
await update(ctx, id, { tags: ['a', 'b'] }, { tags: null })
|
|
140
|
-
await expect(update(ctx, id, { tags: ['c'] }, { tags: ['b', 'a'] })).rejects.toMatchObject({ extensions: { code: 'FIGURE_CATALOG_CONFLICT' } })
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
it('after a conflict, a save expecting what the row held then is refused again if it changed once more', async () => {
|
|
144
|
-
const { ctx, id } = await figureIn()
|
|
145
|
-
await update(ctx, id, { category: 'B' }, { category: null })
|
|
146
|
-
const refused = await update(ctx, id, { category: 'A' }, { category: null }).catch((e: any) => e)
|
|
147
|
-
const now = refused.extensions.fields[0].now
|
|
148
|
-
expect(now).toBe('B')
|
|
149
|
-
await update(ctx, id, { category: 'C' }, { category: 'B' })
|
|
150
|
-
await expect(update(ctx, id, { category: 'A' }, { category: now })).rejects.toMatchObject({ extensions: { code: 'FIGURE_CATALOG_CONFLICT', fields: [{ field: 'category', now: 'C' }] } })
|
|
151
|
-
expect((await row(id)).category).toBe('C')
|
|
152
|
-
})
|
|
153
|
-
})
|