(mess) Stuffing commit.
This commit is contained in:
@@ -523,11 +523,35 @@ test('evaluate: returns error for missing previous context', () => {
|
||||
assert.strictEqual(result.success, false)
|
||||
assert.ok((result as { success: false; error: string }).error.includes('No previous context'))
|
||||
})
|
||||
test('evaluate: returns error for non-array in quantified expression', () => {
|
||||
test('evaluate: returns false for non-array in quantified expression', () => {
|
||||
const ast = parse('for x in response_code(this): x == 1')
|
||||
const result = evaluate(ast.ast, makeContext())
|
||||
assert.strictEqual(result.success, false)
|
||||
assert.ok((result as { success: false; error: string }).error.includes('array collection'))
|
||||
assert.strictEqual(result.success, true)
|
||||
assert.strictEqual((result as { success: true; value: unknown }).value, false)
|
||||
})
|
||||
test('evaluate: returns false for undefined collection in quantified expression', () => {
|
||||
const ast = parse('for x in response_body(this): x == 1')
|
||||
const result = evaluate(ast.ast, makeContext({ response: { body: undefined, headers: {}, statusCode: 200, responseTime: 0 } }))
|
||||
assert.strictEqual(result.success, true)
|
||||
assert.strictEqual((result as { success: true; value: unknown }).value, false)
|
||||
})
|
||||
test('evaluate: returns false for error object collection in quantified expression', () => {
|
||||
const ast = parse('for x in response_body(this): x == 1')
|
||||
const result = evaluate(ast.ast, makeContext({ response: { body: { error: 'Chaos error: forced 503' }, headers: {}, statusCode: 200, responseTime: 0 } }))
|
||||
assert.strictEqual(result.success, true)
|
||||
assert.strictEqual((result as { success: true; value: unknown }).value, false)
|
||||
})
|
||||
test('evaluate: quantified nested in conditional handles undefined gracefully', () => {
|
||||
const ast = parse('if status:503 then for x in response_body(this): x == 1 else true')
|
||||
const result = evaluate(ast.ast, makeContext({ response: { statusCode: 503, body: undefined, headers: {}, responseTime: 0 } }))
|
||||
assert.strictEqual(result.success, true)
|
||||
assert.strictEqual((result as { success: true; value: unknown }).value, false)
|
||||
})
|
||||
test('evaluate: exists returns false for non-array collection', () => {
|
||||
const ast = parse('exists x in response_body(this): x == 1')
|
||||
const result = evaluate(ast.ast, makeContext({ response: { body: { error: 'fail' }, headers: {}, statusCode: 200, responseTime: 0 } }))
|
||||
assert.strictEqual(result.success, true)
|
||||
assert.strictEqual((result as { success: true; value: unknown }).value, false)
|
||||
})
|
||||
// ============================================================================
|
||||
// Unit Tests: Substitutor
|
||||
|
||||
Reference in New Issue
Block a user