20 lines
960 B
TypeScript
20 lines
960 B
TypeScript
import { When, Then } from '@cucumber/cucumber'
|
|
import { strict as assert } from 'assert'
|
|
import type { PerausetWorld } from '../support/world.js'
|
|
|
|
When('I send a POST request to {string} with body:', async function (this: PerausetWorld, path: string, body: string) {
|
|
await this.post(path, JSON.parse(body))
|
|
})
|
|
|
|
Then('I store the response field {string} as {string}', function (this: PerausetWorld, field: string, key: string) {
|
|
assert.ok(this.lastBody, 'No response body')
|
|
const value = this.lastBody[field]
|
|
assert.ok(value !== undefined && value !== null, `Response body field "${field}" is missing. Body: ${JSON.stringify(this.lastBody)}`)
|
|
;(this as any)[key] = value
|
|
})
|
|
|
|
Then('the response body field {string} should be truthy', function (this: PerausetWorld, field: string) {
|
|
assert.ok(this.lastBody, 'No response body')
|
|
assert.ok(this.lastBody[field], `Expected body.${field} to be truthy, got: ${JSON.stringify(this.lastBody[field])}`)
|
|
})
|