feat(skeleton) : remove skeleton JSON field references — use structure API field directly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-12 18:11:07 +01:00
parent 4a3bceffa1
commit 9fef009610
4 changed files with 31 additions and 91 deletions

View File

@@ -50,60 +50,55 @@ beforeEach(() => {
// normalizeModelType (tested via getModelType which calls .then(normalizeModelType))
// ---------------------------------------------------------------------------
describe('normalizeModelType (via getModelType)', () => {
it('maps componentSkeleton to structure for COMPONENT', async () => {
const skeleton = { customFields: [{ name: 'Weight' }] }
it('returns structure as-is for COMPONENT', async () => {
const structure = { customFields: [{ name: 'Weight' }] }
mockFetch.mockResolvedValue(fakeModelType({
category: 'COMPONENT',
structure: null,
componentSkeleton: skeleton as any,
structure: structure as any,
}))
const result = await getModelType('mt-1')
expect(result.structure).toEqual(skeleton)
expect(result.structure).toEqual(structure)
})
it('maps pieceSkeleton to structure for PIECE', async () => {
const skeleton = { customFields: [{ name: 'Size' }] }
it('returns structure as-is for PIECE', async () => {
const structure = { customFields: [{ name: 'Size' }] }
mockFetch.mockResolvedValue(fakeModelType({
category: 'PIECE',
structure: null,
pieceSkeleton: skeleton as any,
structure: structure as any,
}))
const result = await getModelType('mt-1')
expect(result.structure).toEqual(skeleton)
expect(result.structure).toEqual(structure)
})
it('maps productSkeleton to structure for PRODUCT', async () => {
const skeleton = { customFields: [{ name: 'Brand' }] }
it('returns structure as-is for PRODUCT', async () => {
const structure = { customFields: [{ name: 'Brand' }] }
mockFetch.mockResolvedValue(fakeModelType({
category: 'PRODUCT',
structure: null,
productSkeleton: skeleton as any,
structure: structure as any,
}))
const result = await getModelType('mt-1')
expect(result.structure).toEqual(skeleton)
expect(result.structure).toEqual(structure)
})
it('does not override existing structure', async () => {
const existing = { customFields: [{ name: 'Existing' }] }
it('preserves null structure', async () => {
mockFetch.mockResolvedValue(fakeModelType({
category: 'COMPONENT',
structure: existing as any,
componentSkeleton: { customFields: [{ name: 'Skeleton' }] } as any,
structure: null,
}))
const result = await getModelType('mt-1')
expect(result.structure).toEqual(existing)
expect(result.structure).toBeNull()
})
})
// ---------------------------------------------------------------------------
// createModelType — maps structure to skeleton
// createModelType — sends structure directly
// ---------------------------------------------------------------------------
describe('createModelType', () => {
it('sends POST with componentSkeleton for COMPONENT', async () => {
it('sends POST with structure for COMPONENT', async () => {
const structure = { customFields: [] }
mockFetch.mockResolvedValue(fakeModelType())
@@ -120,11 +115,10 @@ describe('createModelType', () => {
const [endpoint, options] = mockFetch.mock.calls[0]
expect(endpoint).toBe('/model_types')
expect(options.method).toBe('POST')
expect(options.body.componentSkeleton).toEqual(structure)
expect(options.body.structure).toBeUndefined()
expect(options.body.structure).toEqual(structure)
})
it('sends POST with pieceSkeleton for PIECE', async () => {
it('sends POST with structure for PIECE', async () => {
const structure = { customFields: [], products: [] }
mockFetch.mockResolvedValue(fakeModelType({ category: 'PIECE' }))
@@ -136,11 +130,10 @@ describe('createModelType', () => {
})
const [, options] = mockFetch.mock.calls[0]
expect(options.body.pieceSkeleton).toEqual(structure)
expect(options.body.structure).toBeUndefined()
expect(options.body.structure).toEqual(structure)
})
it('sends POST with productSkeleton for PRODUCT', async () => {
it('sends POST with structure for PRODUCT', async () => {
const structure = { customFields: [] }
mockFetch.mockResolvedValue(fakeModelType({ category: 'PRODUCT' }))
@@ -152,15 +145,15 @@ describe('createModelType', () => {
})
const [, options] = mockFetch.mock.calls[0]
expect(options.body.productSkeleton).toEqual(structure)
expect(options.body.structure).toEqual(structure)
})
})
// ---------------------------------------------------------------------------
// updateModelType — maps structure to skeleton
// updateModelType — sends structure directly
// ---------------------------------------------------------------------------
describe('updateModelType', () => {
it('sends PATCH with correct endpoint and skeleton', async () => {
it('sends PATCH with correct endpoint and structure', async () => {
const structure = { customFields: [{ name: 'Updated' }] }
mockFetch.mockResolvedValue(fakeModelType())
@@ -176,10 +169,10 @@ describe('updateModelType', () => {
expect(endpoint).toBe('/model_types/mt-1')
expect(options.method).toBe('PATCH')
expect(options.headers['Content-Type']).toBe('application/merge-patch+json')
expect(options.body.componentSkeleton).toEqual(structure)
expect(options.body.structure).toEqual(structure)
})
it('sends payload without skeleton when no structure', async () => {
it('sends payload without structure when not provided', async () => {
mockFetch.mockResolvedValue(fakeModelType())
await updateModelType('mt-1', {
@@ -189,7 +182,7 @@ describe('updateModelType', () => {
})
const [, options] = mockFetch.mock.calls[0]
expect(options.body.componentSkeleton).toBeUndefined()
expect(options.body.structure).toBeUndefined()
expect(options.body.name).toBe('Just Name')
})
})