Files
perauset-e2e-mrfzptpr/e2e/tests/steps/roles.steps.ts
2026-07-11 08:35:17 +02:00

23 lines
1.0 KiB
TypeScript

import { When, Then } from '@cucumber/cucumber'
import { strict as assert } from 'assert'
import type { PerausetWorld } from '../support/world.js'
import { getUserId } from '../support/db.js'
When('I set roles {string} for user {string}', async function (this: PerausetWorld, roles: string, email: string) {
// Look up userId from DB if not already cached
let userId = this.createdUsers[email]
if (!userId) {
userId = getUserId(email)
this.createdUsers[email] = userId
}
const rolesArray = roles.split(',').map((r) => r.trim())
await this.put(`/users/${userId}/roles`, { memberRoles: rolesArray })
})
Then('the response body field {string} should contain {string}', function (this: PerausetWorld, field: string, value: string) {
assert.ok(this.lastBody, 'No response body')
const arr = this.lastBody[field]
assert.ok(Array.isArray(arr), `Expected body.${field} to be an array, got: ${JSON.stringify(arr)}`)
assert.ok(arr.includes(value), `Expected body.${field} to contain "${value}", got: ${JSON.stringify(arr)}`)
})