Skip to content

Commit 9680fd8

Browse files
committed
feat(quick-260326-vn8): default type column to resourceConfig.typeUri in create method
- Add input['type'] = resourceConfig.typeUri after toHasuraInput in create() - toHasuraInput strips the type field from request body (short name) - Service layer now always sets the full canonical type URI for all resource types - Add tests documenting the default type assignment contract in request.test.ts
1 parent 7e0bf26 commit 9680fd8

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/mappers/__tests__/request.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,48 @@ describe('toHasuraInput - softwareversions resource (modelcatalog_software_versi
8888
expect(result).toEqual({ label: 'Version 1.0', description: 'Version description' });
8989
});
9090
});
91+
92+
// ============================================================================
93+
// Default type assignment: service layer uses resourceConfig.typeUri
94+
// ============================================================================
95+
// These tests document the contract: toHasuraInput strips the type field from
96+
// the request body, and the service.ts create() method is responsible for
97+
// setting input['type'] = resourceConfig.typeUri before the Hasura mutation.
98+
99+
describe('default type assignment via resourceConfig.typeUri', () => {
100+
it('resourceConfig for models has typeUri = https://w3id.org/okn/o/sdm#Model', () => {
101+
const config = getResourceConfig('models')!;
102+
expect(config.typeUri).toBe('https://w3id.org/okn/o/sdm#Model');
103+
});
104+
105+
it('resourceConfig for empiricalmodels has typeUri = https://w3id.org/okn/o/sdm#EmpiricalModel', () => {
106+
const config = getResourceConfig('empiricalmodels')!;
107+
expect(config.typeUri).toBe('https://w3id.org/okn/o/sdm#EmpiricalModel');
108+
});
109+
110+
it('resourceConfig for softwareversions has typeUri = https://w3id.org/okn/o/sd#SoftwareVersion', () => {
111+
const config = getResourceConfig('softwareversions')!;
112+
expect(config.typeUri).toBe('https://w3id.org/okn/o/sd#SoftwareVersion');
113+
});
114+
115+
it('toHasuraInput strips the type field so service layer can assign the canonical URI', () => {
116+
const config = getResourceConfig('models')!;
117+
// Body includes type as short name (API-level value)
118+
const input = toHasuraInput({ label: ['Test'], type: ['Model'] }, config);
119+
// toHasuraInput must not set type -- the service layer will assign it
120+
expect(input).not.toHaveProperty('type');
121+
// Simulating what service.ts create() does after toHasuraInput:
122+
input['type'] = config.typeUri;
123+
expect(input['type']).toBe('https://w3id.org/okn/o/sdm#Model');
124+
});
125+
126+
it('toHasuraInput on empty body produces no type; service layer assigns canonical URI', () => {
127+
const config = getResourceConfig('models')!;
128+
// Body has no type field at all
129+
const input = toHasuraInput({ label: ['Test'] }, config);
130+
expect(input).not.toHaveProperty('type');
131+
// Service layer sets it
132+
input['type'] = config.typeUri;
133+
expect(input['type']).toBe('https://w3id.org/okn/o/sdm#Model');
134+
});
135+
});

src/service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ class CatalogServiceImpl {
188188
const body = req.body || {}
189189
const input = toHasuraInput(body as Record<string, unknown>, resourceConfig)
190190

191+
// Always set the type column to the resource's canonical type URI.
192+
// toHasuraInput intentionally skips the `type` field from the request body
193+
// (short name like "Model"), so we set the full URI from the registry.
194+
input['type'] = resourceConfig.typeUri
195+
191196
// Generate a URI-based ID if not provided
192197
if (!input['id']) {
193198
input['id'] = `${ID_PREFIX}${randomUUID()}`

0 commit comments

Comments
 (0)