Skip to content

Commit a24b401

Browse files
authored
fix(integrations): validate ashby (#10167)
* fix(integrations): validate ashby * fix(integrations): type the ashby test helpers against the tool's own params * fix(integrations): send ashby get_job's flag only when it is a boolean and shrink the test-types baseline
1 parent 4fdef1e commit a24b401

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

‎apps/sim/tools/ashby/ashby.test.ts‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { changeApplicationStageTool } from '@/tools/ashby/change_application_sta
66
import { deleteApplicationTool } from '@/tools/ashby/delete_application'
77
import { getApplicationTool } from '@/tools/ashby/get_application'
88
import { getCandidateTool } from '@/tools/ashby/get_candidate'
9+
import { getJobTool } from '@/tools/ashby/get_job'
910
import { getJobPostingTool } from '@/tools/ashby/get_job_posting'
1011
import { listApplicationsTool } from '@/tools/ashby/list_applications'
1112
import { listCandidatesTool } from '@/tools/ashby/list_candidates'
@@ -21,16 +22,18 @@ import { setCustomFieldValuesTool } from '@/tools/ashby/set_custom_field_values'
2122
import { transferApplicationTool } from '@/tools/ashby/transfer_application'
2223
import { updateCandidateTool } from '@/tools/ashby/update_candidate'
2324
import { ashbyAuthHeaders } from '@/tools/ashby/utils'
24-
import type { ToolConfig } from '@/tools/types'
2525

2626
const respond = (body: unknown) => new Response(JSON.stringify(body), { status: 200 })
2727

28-
function requestBody(tool: ToolConfig<never, never>, params: unknown): Record<string, unknown> {
28+
function requestBody(
29+
tool: { request?: { body?: unknown } },
30+
params: unknown
31+
): Record<string, unknown> {
2932
const build = tool.request?.body as (p: unknown) => Record<string, unknown>
3033
return build(params)
3134
}
3235

33-
async function transform(tool: ToolConfig<never, never>, body: unknown) {
36+
async function transform(tool: { transformResponse?: unknown }, body: unknown) {
3437
const run = tool.transformResponse as (r: Response) => Promise<{ output: Record<string, never> }>
3538
return run(respond(body))
3639
}
@@ -263,6 +266,27 @@ describe('ashby request bodies', () => {
263266
expect(body).not.toHaveProperty('includeUnpublishedJobPostingsIds')
264267
})
265268

269+
it('get_job sends the job.info spelling of the unpublished posting IDs flag', () => {
270+
// job.info rejects unknown keys (additionalProperties: false), so the
271+
// singular `includeUnpublishedJobPostingIds` never reached Ashby as intended.
272+
const body = requestBody(getJobTool, {
273+
apiKey: 'k',
274+
jobId: ' j ',
275+
includeUnpublishedJobPostingIds: true,
276+
})
277+
expect(body).toMatchObject({ id: 'j', includeUnpublishedJobPostingsIds: true })
278+
expect(body).not.toHaveProperty('includeUnpublishedJobPostingIds')
279+
for (const untouched of [null, '']) {
280+
expect(
281+
requestBody(getJobTool, {
282+
apiKey: 'k',
283+
jobId: 'j',
284+
includeUnpublishedJobPostingIds: untouched,
285+
})
286+
).toEqual({ id: 'j', expand: ['openings', 'location', 'compensation'] })
287+
}
288+
})
289+
266290
it('change_application_source sends sourceId when one is provided', () => {
267291
// Ashby requires the key to be present; omitting it is a 400 rather than
268292
// the intended write.

‎apps/sim/tools/ashby/get_job.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export const getJobTool: ToolConfig<AshbyGetJobParams, AshbyGetJobResponse> = {
3838
body: (params) => ({
3939
id: params.jobId.trim(),
4040
expand: ['openings', 'location', 'compensation'],
41-
...(params.includeUnpublishedJobPostingIds !== undefined
42-
? { includeUnpublishedJobPostingIds: params.includeUnpublishedJobPostingIds }
41+
...(typeof params.includeUnpublishedJobPostingIds === 'boolean'
42+
? { includeUnpublishedJobPostingsIds: params.includeUnpublishedJobPostingIds }
4343
: {}),
4444
}),
4545
},

‎scripts/check-test-types.baseline.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,8 +2574,7 @@
25742574
"TS2345": 25
25752575
},
25762576
"apps/sim/tools/ashby/ashby.test.ts": {
2577-
"TS2339": 3,
2578-
"TS2345": 50
2577+
"TS2339": 3
25792578
},
25802579
"apps/sim/tools/assistant-execution.test.ts": {
25812580
"TS2554": 2

0 commit comments

Comments
 (0)