|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { AshbyBlock } from './ashby' |
| 6 | + |
| 7 | +describe('AshbyBlock', () => { |
| 8 | + const buildParams = (operation: string, extra: Record<string, unknown>) => ({ |
| 9 | + operation, |
| 10 | + ...extra, |
| 11 | + }) |
| 12 | + |
| 13 | + describe('alternateEmailAddresses parsing (create_candidate)', () => { |
| 14 | + it('parses a comma-separated string into an array', () => { |
| 15 | + const result = AshbyBlock.tools.config.params!( |
| 16 | + buildParams('create_candidate', { |
| 17 | + alternateEmailAddresses: 'a@x.com, b@x.com', |
| 18 | + }) |
| 19 | + ) |
| 20 | + expect(result.alternateEmailAddresses).toEqual(['a@x.com', 'b@x.com']) |
| 21 | + }) |
| 22 | + |
| 23 | + it('parses a JSON array string into an array', () => { |
| 24 | + const result = AshbyBlock.tools.config.params!( |
| 25 | + buildParams('create_candidate', { |
| 26 | + alternateEmailAddresses: '["a@x.com","b@x.com"]', |
| 27 | + }) |
| 28 | + ) |
| 29 | + expect(result.alternateEmailAddresses).toEqual(['a@x.com', 'b@x.com']) |
| 30 | + }) |
| 31 | + |
| 32 | + it('omits the field entirely when empty', () => { |
| 33 | + const result = AshbyBlock.tools.config.params!( |
| 34 | + buildParams('create_candidate', { alternateEmailAddresses: '' }) |
| 35 | + ) |
| 36 | + expect(result.alternateEmailAddresses).toBeUndefined() |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + describe('socialLinks parsing (update_candidate)', () => { |
| 41 | + it('parses a JSON array of link objects', () => { |
| 42 | + const result = AshbyBlock.tools.config.params!( |
| 43 | + buildParams('update_candidate', { |
| 44 | + socialLinks: '[{"type":"Twitter","url":"https://twitter.com/jane"}]', |
| 45 | + }) |
| 46 | + ) |
| 47 | + expect(result.socialLinks).toEqual([{ type: 'Twitter', url: 'https://twitter.com/jane' }]) |
| 48 | + }) |
| 49 | + |
| 50 | + it('throws instead of silently dropping the field when the JSON is malformed', () => { |
| 51 | + // A silent [] here would let the Ashby update proceed without applying |
| 52 | + // the requested links and with no error shown to the workflow author. |
| 53 | + expect(() => |
| 54 | + AshbyBlock.tools.config.params!( |
| 55 | + buildParams('update_candidate', { socialLinks: 'not json' }) |
| 56 | + ) |
| 57 | + ).toThrow(/Invalid JSON in Ashby social links/) |
| 58 | + }) |
| 59 | + |
| 60 | + it('throws when the parsed JSON is not an array', () => { |
| 61 | + expect(() => |
| 62 | + AshbyBlock.tools.config.params!( |
| 63 | + buildParams('update_candidate', { socialLinks: '{"type":"Twitter"}' }) |
| 64 | + ) |
| 65 | + ).toThrow(/expected a JSON array/) |
| 66 | + }) |
| 67 | + }) |
| 68 | + |
| 69 | + describe('wandConfig on array-shaped fields', () => { |
| 70 | + it('does not request object-wrapped output for alternateEmailAddresses or socialLinks', () => { |
| 71 | + // generationType 'json-object' makes the wand API append "the response |
| 72 | + // must start with { and end with }", which conflicts with these fields' |
| 73 | + // array-or-comma-separated parsers (parseStringListInput/parseSocialLinksInput). |
| 74 | + const alternateEmailAddresses = AshbyBlock.subBlocks.find( |
| 75 | + (s) => s.id === 'alternateEmailAddresses' |
| 76 | + ) |
| 77 | + const socialLinks = AshbyBlock.subBlocks.find((s) => s.id === 'socialLinks') |
| 78 | + expect(alternateEmailAddresses?.wandConfig?.generationType).not.toBe('json-object') |
| 79 | + expect(socialLinks?.wandConfig?.generationType).not.toBe('json-object') |
| 80 | + }) |
| 81 | + }) |
| 82 | + |
| 83 | + describe('list_applications candidateId filter', () => { |
| 84 | + it('has no filterCandidateId subBlock or wiring', () => { |
| 85 | + // Ashby's application.list endpoint silently ignores a candidateId |
| 86 | + // body field (confirmed live: passing a nonexistent candidate UUID |
| 87 | + // still returns unfiltered results) — the correct path for a |
| 88 | + // candidate's applications is ashby_get_candidate's applicationIds. |
| 89 | + expect(AshbyBlock.subBlocks.find((s) => s.id === 'filterCandidateId')).toBeUndefined() |
| 90 | + const result = AshbyBlock.tools.config.params!( |
| 91 | + buildParams('list_applications', { filterCandidateId: 'some-id' }) |
| 92 | + ) |
| 93 | + expect(result.candidateId).toBeUndefined() |
| 94 | + }) |
| 95 | + }) |
| 96 | +}) |
0 commit comments