migrated api timebound tests to jest

This commit is contained in:
Aaro Koivukangas
2024-09-12 13:36:26 +03:00
committed by Aaro Koivukangas
parent a92a17a1d7
commit 266018175d
@@ -1,6 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import assert from 'node:assert/strict'
import { before, describe, it } from 'node:test'
import { beforeEach, describe, it, expect } from '@jest/globals'
import { LogRow } from '../../services/write/writeOperations/types'
import { login, send, testLogRows } from '../utils'
import { newTimeBoundBasis } from './data'
@@ -9,7 +7,7 @@ import { TimeBoundDetailsType } from '../../../../frontend/src/backendTypes'
let createdTimeBound: TimeBoundDetailsType | null = null
describe.only('Creating new time bound works', () => {
before(async () => {
beforeEach(async () => {
await login()
})
@@ -20,7 +18,7 @@ describe.only('Creating new time bound works', () => {
const { id: createdId } = resultBody
assert(typeof createdId === 'number', `Invalid result returned on write: ${createdId}`)
expect(typeof createdId).toEqual('number') // `Invalid result returned on write: ${createdId}`
const { body } = await send<TimeBoundDetailsType>(`time-bound/${createdId}`, 'GET')
createdTimeBound = body
@@ -28,14 +26,14 @@ describe.only('Creating new time bound works', () => {
it('Contains correct data', () => {
const { b_name, b_comment, age } = createdTimeBound!
assert(b_name === newTimeBoundBasis.b_name, 'Name is different than expected')
assert(age === newTimeBoundBasis.age, 'Age differs')
assert(b_comment === newTimeBoundBasis.b_comment, 'Comment differs')
expect(b_name).toEqual(newTimeBoundBasis.b_name) // 'Name is different than expected')
expect(age).toEqual(newTimeBoundBasis.age) // 'Age differs'
expect(b_comment).toEqual(newTimeBoundBasis.b_comment) // 'Comment differs'
})
it('Update logs are correct', () => {
const lastUpdate = createdTimeBound!.now_bau[createdTimeBound!.now_bau.length - 1]
assert(lastUpdate.bau_comment === newTimeBoundBasis.comment, 'Comment is correct')
expect(lastUpdate.bau_comment).toEqual(newTimeBoundBasis.comment) // 'Comment is correct'
const logRows = lastUpdate.updates
const expectedLogRows: Partial<LogRow>[] = [
{