|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { SQSBlock } from '@/blocks/blocks/sqs' |
| 6 | + |
| 7 | +const mapParams = SQSBlock.tools.config?.params |
| 8 | +if (!mapParams) { |
| 9 | + throw new Error('SQS block must define tools.config.params') |
| 10 | +} |
| 11 | + |
| 12 | +const CONNECTION = { |
| 13 | + region: 'us-east-1', |
| 14 | + accessKeyId: 'AKIAIOSFODNN7EXAMPLE', |
| 15 | + secretAccessKey: 'secret', |
| 16 | +} |
| 17 | + |
| 18 | +const QUEUE_URL = 'https://sqs.us-east-1.amazonaws.com/123456789012/test-queue' |
| 19 | + |
| 20 | +/** Fields whose Wand output the prompt and the contract both describe as an array. */ |
| 21 | +const BATCH_ENTRY_FIELDS = ['sendEntries', 'deleteEntries', 'visibilityEntries'] as const |
| 22 | + |
| 23 | +describe('SQS block integer parsing', () => { |
| 24 | + it('rejects a fractional value instead of truncating it', () => { |
| 25 | + expect(() => |
| 26 | + mapParams({ ...CONNECTION, operation: 'send', queueUrl: QUEUE_URL, delaySeconds: '1.5' }) |
| 27 | + ).toThrow('delaySeconds must be a whole number') |
| 28 | + }) |
| 29 | + |
| 30 | + it('rejects a value with a trailing suffix instead of forwarding the digits', () => { |
| 31 | + expect(() => |
| 32 | + mapParams({ |
| 33 | + ...CONNECTION, |
| 34 | + operation: 'receive_message', |
| 35 | + queueUrl: QUEUE_URL, |
| 36 | + maxNumberOfMessages: '10abc', |
| 37 | + }) |
| 38 | + ).toThrow('maxNumberOfMessages must be a whole number') |
| 39 | + }) |
| 40 | + |
| 41 | + it('forwards a whole number unchanged', () => { |
| 42 | + expect( |
| 43 | + mapParams({ ...CONNECTION, operation: 'send', queueUrl: QUEUE_URL, delaySeconds: '30' }) |
| 44 | + ).toMatchObject({ delaySeconds: 30 }) |
| 45 | + }) |
| 46 | + |
| 47 | + it('treats a blank or whitespace-only field as unset', () => { |
| 48 | + for (const delaySeconds of ['', ' ']) { |
| 49 | + expect( |
| 50 | + mapParams({ ...CONNECTION, operation: 'send', queueUrl: QUEUE_URL, delaySeconds }) |
| 51 | + ).not.toHaveProperty('delaySeconds') |
| 52 | + } |
| 53 | + }) |
| 54 | +}) |
| 55 | + |
| 56 | +describe('SQS block wand generation types', () => { |
| 57 | + it.each(BATCH_ENTRY_FIELDS)('generates a JSON array for %s', (fieldId) => { |
| 58 | + const subBlock = SQSBlock.subBlocks.find((candidate) => candidate.id === fieldId) |
| 59 | + |
| 60 | + expect(subBlock?.wandConfig?.generationType).toBe('json-array') |
| 61 | + }) |
| 62 | +}) |
0 commit comments