58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { When, Given } from '@cucumber/cucumber'
|
|
import type { PerausetWorld } from '../support/world.js'
|
|
import { openDb } from '../support/db.js'
|
|
|
|
When('I submit a stay request with type {string} from {string} to {string}', async function (this: PerausetWorld, requestType: string, startAt: string, endAt: string) {
|
|
await this.post('/stays/requests', {
|
|
requestType,
|
|
requestedStartAt: startAt,
|
|
requestedEndAt: endAt,
|
|
})
|
|
})
|
|
|
|
When('I approve the stay request', async function (this: PerausetWorld) {
|
|
const requestId = (this as any).requestId
|
|
await this.post(`/stays/requests/${requestId}/approve`, {
|
|
requestId,
|
|
})
|
|
})
|
|
|
|
When('I reject the stay request with reason {string}', async function (this: PerausetWorld, reason: string) {
|
|
const requestId = (this as any).requestId
|
|
await this.post(`/stays/requests/${requestId}/reject`, {
|
|
requestId,
|
|
reviewNotes: reason,
|
|
})
|
|
})
|
|
|
|
When('I create a stay from the approved request', async function (this: PerausetWorld) {
|
|
const requestId = (this as any).requestId
|
|
await this.post('/stays', {
|
|
requestId,
|
|
})
|
|
})
|
|
|
|
Given('the stay is confirmed in the database', async function (this: PerausetWorld) {
|
|
const stayId = (this as any).stayId
|
|
const db = openDb()
|
|
try {
|
|
db.prepare(`UPDATE stay SET status = 'confirmed' WHERE stay_id = ?`).run(stayId)
|
|
} finally {
|
|
db.close()
|
|
}
|
|
})
|
|
|
|
When('I check in the stay', async function (this: PerausetWorld) {
|
|
const stayId = (this as any).stayId
|
|
await this.post(`/stays/${stayId}/check-in`, {
|
|
stayId,
|
|
})
|
|
})
|
|
|
|
When('I check out the stay', async function (this: PerausetWorld) {
|
|
const stayId = (this as any).stayId
|
|
await this.post(`/stays/${stayId}/check-out`, {
|
|
stayId,
|
|
})
|
|
})
|