Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for min max age check #200

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions backend/src/api-tests/locality/contradictory_loc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { beforeEach, describe, it, expect } from '@jest/globals'
import { LocalityDetailsType } from '../../../../frontend/src/backendTypes'
import { editedLocality, newLocalityBasis } from './data'
import { login, send } from '../utils'

describe('Min and max age checks work', () => {
beforeEach(async () => {
await login()
})

it('Creating a locality with contradictory min and max ages does not work', async () => {
const locality = newLocalityBasis
locality.min_age = 10
locality.max_age = 9
const { status: putReqStatus } = await send<{ id: number }>('locality', 'PUT', {
locality: locality,
})

expect(putReqStatus).toEqual(400)

const { body: getReqBody, status: getReqStatus } = await send<LocalityDetailsType>(`locality/all`, 'GET')
expect(getReqStatus).toEqual(200)
expect(getReqBody).not.toContain(newLocalityBasis)
})

it('Editing a locality with contradictory min and max ages does not work', async () => {
const locality = editedLocality
// @ts-expect-error: min age property is not implied to exist in locality
locality.min_age = 10
// @ts-expect-error: max age property is not implied to exist in locality
locality.max_age = 9
const writeResult = await send<{ id: number }>('locality', 'PUT', { locality: locality })

expect(writeResult.status).toEqual(400)
expect(writeResult.body).toEqual({})
})
})