Skip to content

Commit 355251b

Browse files
Bill Leoutsakoswaleedlatif1
authored andcommitted
fix(windchill): align tool contracts and docs
1 parent 297cc44 commit 355251b

38 files changed

Lines changed: 2670 additions & 1070 deletions

apps/docs/content/docs/en/integrations/windchill.mdx

Lines changed: 488 additions & 310 deletions
Large diffs are not rendered by default.

apps/sim/app/api/tools/windchill/route.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,43 @@ describe('POST /api/tools/windchill', () => {
311311
})
312312
})
313313

314+
it('returns operation-specific single, bulk, and delete mutation shapes', async () => {
315+
const singleResponse = await POST(
316+
createMockRequest('POST', {
317+
...BASE_BODY,
318+
operation: 'windchill_update_document',
319+
documentOid: DOCUMENT_OID,
320+
attributes: { Title: 'Updated' },
321+
})
322+
)
323+
const singleOutput = (await singleResponse.json()).output
324+
expect(singleOutput.document).toMatchObject({ id: DOCUMENT_OID })
325+
expect(singleOutput).not.toHaveProperty('documents')
326+
327+
const bulkResponse = await POST(
328+
createMockRequest('POST', {
329+
...BASE_BODY,
330+
operation: 'windchill_update_documents',
331+
documents: [{ id: DOCUMENT_OID, attributes: { Title: 'Updated' } }],
332+
})
333+
)
334+
const bulkOutput = (await bulkResponse.json()).output
335+
expect(bulkOutput.documents).toEqual([expect.objectContaining({ id: DOCUMENT_OID })])
336+
expect(bulkOutput).not.toHaveProperty('document')
337+
338+
const deleteResponse = await POST(
339+
createMockRequest('POST', {
340+
...BASE_BODY,
341+
operation: 'windchill_delete_document',
342+
documentOid: DOCUMENT_OID,
343+
})
344+
)
345+
const deleteOutput = (await deleteResponse.json()).output
346+
expect(deleteOutput.affectedIds).toEqual([DOCUMENT_OID])
347+
expect(deleteOutput).not.toHaveProperty('document')
348+
expect(deleteOutput).not.toHaveProperty('documents')
349+
})
350+
314351
it('authorizes and reads a UserFile before starting the upload transaction', async () => {
315352
const response = await POST(
316353
createMockRequest('POST', {

apps/sim/app/api/tools/windchill/route.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ const logger = createLogger('WindchillAPI')
4545

4646
type WindchillRouteOutput = Extract<WindchillOperationResponse, { success: true }>['output']
4747

48+
const BULK_RESULT_OPERATIONS: ReadonlySet<WindchillRouteOutput['operation']> = new Set([
49+
'windchill_create_documents',
50+
'windchill_update_documents',
51+
'windchill_check_out_documents',
52+
'windchill_check_in_documents',
53+
'windchill_undo_check_out_documents',
54+
'windchill_revise_documents',
55+
'windchill_update_document_security_labels',
56+
])
57+
58+
const DELETE_OPERATIONS: ReadonlySet<WindchillRouteOutput['operation']> = new Set([
59+
'windchill_delete_document',
60+
'windchill_delete_documents',
61+
])
62+
4863
function successResponse(output: WindchillRouteOutput) {
4964
const body = { success: true, output } satisfies WindchillOperationResponse
5065
return NextResponse.json(body)
@@ -82,11 +97,18 @@ function mutationOutput(
8297
? [document.id, ...collectionIds]
8398
: collectionIds
8499
const affectedIds = returnedIds.length > 0 ? returnedIds : fallbackIds
100+
if (DELETE_OPERATIONS.has(operation)) return { operation, affectedIds: fallbackIds }
101+
if (BULK_RESULT_OPERATIONS.has(operation)) {
102+
return {
103+
operation,
104+
affectedIds,
105+
...(documents.length > 0 ? { documents } : {}),
106+
}
107+
}
85108
return {
86109
operation,
87110
affectedIds,
88111
...(document ? { document } : {}),
89-
...(documents.length > 0 ? { documents } : {}),
90112
}
91113
}
92114

0 commit comments

Comments
 (0)