Merge pull request #286 from nowcommunity/tests-for-time-bound

Tests for time bound
This commit is contained in:
Eero Antikainen
2024-09-27 12:21:07 +03:00
committed by GitHub
+53 -2
View File
@@ -1,5 +1,56 @@
import { describe, it } from '@jest/globals'
import { describe, it, beforeAll, beforeEach, expect } from '@jest/globals'
import { editedTimeBound, newTimeBoundBasis } from './data'
import { send, resetDatabase, login } from '../utils'
import { TimeBoundDetailsType } from '../../../../frontend/src/backendTypes'
const existingTimeBound = { ...newTimeBoundBasis, bid: 11 }
describe('Time bound updating', () => {
it('TESTS NOT IMPLEMENTED', () => {})
beforeAll(async () => {
await resetDatabase()
})
beforeEach(async () => {
await login()
})
it('Update request with valid timebound succeeds and returns valid number id', async () => {
const { body: resultBody } = await send<{ id: number }>('time-bound', 'PUT', {
timeBound: editedTimeBound,
})
const { id: existingId } = resultBody
expect(typeof existingId).toEqual('number')
expect(existingId).toEqual(11)
const { body } = await send<TimeBoundDetailsType>(`time-bound/${existingId}`, 'GET')
expect(body.bid).toEqual(existingTimeBound.bid)
expect(body.b_name).toEqual(editedTimeBound.b_name)
expect(body.age).toEqual(editedTimeBound.age)
})
it('Update request that does not change anything works', async () => {
const { body: resultBody } = await send<{ id: number }>('time-bound', 'PUT', {
timeBound: existingTimeBound,
})
const { id: existingId } = resultBody
expect(typeof existingId).toEqual('number')
expect(existingId).toEqual(11)
const { body } = await send<TimeBoundDetailsType>(`time-bound/${existingId}`, 'GET')
expect(body.bid).toEqual(existingTimeBound.bid)
expect(body.b_name).toEqual(existingTimeBound.b_name)
expect(body.age).toEqual(existingTimeBound.age)
})
it('Update request with invalid timebound age fails', async () => {
const invalidAgeTimeBound = { ...existingTimeBound, age: null }
const { body: resultBody } = await send<{ id: number }>('time-bound', 'PUT', {
timeBound: { ...invalidAgeTimeBound },
})
const { id: existingId } = resultBody
expect(typeof existingId).toEqual('undefined')
const { body } = await send<TimeBoundDetailsType>(`time-bound/${existingTimeBound.bid}`, 'GET')
expect(body.bid).toEqual(existingTimeBound.bid)
expect(body.b_name).toEqual(existingTimeBound.b_name)
expect(body.age).toEqual(existingTimeBound.age)
})
})