mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Add species update tests, fix some types
This commit is contained in:
@@ -8,7 +8,7 @@ import { login, send, testLogRows } from '../utils'
|
||||
|
||||
let createdSpecies: SpeciesDetailsType | null = null
|
||||
|
||||
describe.only('Creating new species works', () => {
|
||||
describe('Creating new species works', () => {
|
||||
before(async () => {
|
||||
await login()
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EditDataType, SpeciesDetailsType } from '../../../../frontend/src/backendTypes'
|
||||
import { EditDataType, EditMetaData, Reference, SpeciesDetailsType } from '../../../../frontend/src/backendTypes'
|
||||
|
||||
export const newSpeciesBasis: EditDataType<SpeciesDetailsType> = {
|
||||
class_name: 'Mammalia',
|
||||
@@ -105,3 +105,14 @@ export const newSpeciesBasis: EditDataType<SpeciesDetailsType> = {
|
||||
now_sau: [],
|
||||
com_taxa_synonym: [],
|
||||
}
|
||||
|
||||
export const editedSpecies: EditDataType<SpeciesDetailsType & EditMetaData> = {
|
||||
species_id: 21426,
|
||||
sp_comment: 'Test comment',
|
||||
species_name: 'Test species name',
|
||||
now_ls: [{ rowState: 'new', lid: 20920 }],
|
||||
com_taxa_synonym: [],
|
||||
now_sau: [],
|
||||
comment: 'species edit test',
|
||||
references: [{ rid: 24188 } as Reference],
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
import assert from 'node:assert/strict'
|
||||
import { before, describe, it } from 'node:test'
|
||||
import { LocalityDetailsType } from '../../../../frontend/src/backendTypes'
|
||||
import { LogRow } from '../../services/writeOperations/types'
|
||||
import { editedLocality } from '../locality/data'
|
||||
import { login, send, testLogRows } from '../utils'
|
||||
|
||||
let resultLocality: LocalityDetailsType | null = null
|
||||
|
||||
describe('Locality write works', () => {
|
||||
before(async () => {
|
||||
await login()
|
||||
})
|
||||
|
||||
it('Edits name, synonyms and locality species correctly', async () => {
|
||||
const writeResult = await send<{ id: number }>('locality', 'PUT', { locality: editedLocality })
|
||||
|
||||
assert(writeResult.body.id === editedLocality.lid, `Invalid result returned on write: ${writeResult.body.id}`)
|
||||
|
||||
const { body } = await send<LocalityDetailsType>(`locality/${editedLocality.lid}`, 'GET')
|
||||
resultLocality = body
|
||||
})
|
||||
|
||||
it('Name changed correctly', () => {
|
||||
assert(resultLocality!.loc_name === editedLocality.loc_name, 'Name was not changed correctly')
|
||||
})
|
||||
|
||||
it('Added locality species is found', () => {
|
||||
assert(
|
||||
resultLocality!.now_ls.find(ls => ls.species_id === 21052 && ls.lid === 21050),
|
||||
'Added locality species not found'
|
||||
)
|
||||
})
|
||||
|
||||
it('Locality species include exactly two entries', () => {
|
||||
assert(resultLocality!.now_ls.length === 2, `Unexpected now_ls length: ${resultLocality!.now_ls.length}`)
|
||||
})
|
||||
|
||||
it('Changes were logged correctly', () => {
|
||||
const update = resultLocality!.now_lau
|
||||
const lastUpdate = update[update.length - 1]
|
||||
|
||||
assert(lastUpdate.lau_comment === editedLocality.comment, 'Comment wrong')
|
||||
assert(lastUpdate.now_lr[lastUpdate.now_lr.length - 1].rid === editedLocality.references[0].rid)
|
||||
|
||||
const logRows = lastUpdate.updates
|
||||
|
||||
const expectedLogRows: Partial<LogRow>[] = [
|
||||
{
|
||||
oldValue: 'Dmanisi',
|
||||
value: editedLocality.loc_name,
|
||||
type: 'update',
|
||||
column: 'loc_name',
|
||||
table: 'now_loc',
|
||||
},
|
||||
{
|
||||
oldValue: '21050',
|
||||
value: null,
|
||||
type: 'delete',
|
||||
column: 'lid',
|
||||
table: 'now_ls',
|
||||
},
|
||||
{
|
||||
oldValue: '85729',
|
||||
value: null,
|
||||
type: 'delete',
|
||||
column: 'species_id',
|
||||
table: 'now_ls',
|
||||
},
|
||||
]
|
||||
testLogRows(logRows, expectedLogRows, 5)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,69 @@
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
import assert from 'node:assert/strict'
|
||||
import { before, describe, it } from 'node:test'
|
||||
import { EditMetaData, SpeciesDetailsType } from '../../../../frontend/src/backendTypes'
|
||||
import { LogRow } from '../../services/writeOperations/types'
|
||||
import { login, send, testLogRows } from '../utils'
|
||||
import { editedSpecies } from './data'
|
||||
import { editedLocality } from '../locality/data'
|
||||
|
||||
let editedSpeciesResult: (SpeciesDetailsType & EditMetaData) | null = null
|
||||
|
||||
describe('Updating species works', () => {
|
||||
before(async () => {
|
||||
await login()
|
||||
})
|
||||
|
||||
it('Edits name, comment and locality-species correctly', async () => {
|
||||
const writeResult = await send<{ id: number }>('species', 'PUT', { species: editedSpecies })
|
||||
assert(writeResult.status === 200, 'Response status was OK')
|
||||
assert(writeResult.body.id === editedSpecies.species_id, `Invalid result returned on write: ${writeResult.body.id}`)
|
||||
|
||||
const { body, status } = await send<SpeciesDetailsType>(`species/${writeResult.body.id}`, 'GET')
|
||||
assert(status === 200, 'Status on response to GET added species request was OK')
|
||||
editedSpeciesResult = body
|
||||
})
|
||||
|
||||
it('Name changed correctly', () => {
|
||||
assert(editedSpeciesResult!.species_name === editedSpecies.species_name, 'Name was not changed correctly')
|
||||
})
|
||||
|
||||
it('Added locality species is found', () => {
|
||||
assert(
|
||||
editedSpeciesResult!.now_ls.find(ls => ls.species_id === editedSpecies.species_id && ls.lid === 20920),
|
||||
'Added locality species not found'
|
||||
)
|
||||
})
|
||||
|
||||
it('Locality species include correct amount of entries', () => {
|
||||
assert(editedSpeciesResult!.now_ls.length === 2, `Unexpected now_ls length: ${editedSpeciesResult!.now_ls.length}`)
|
||||
})
|
||||
|
||||
it('Changes were logged correctly', () => {
|
||||
const update = editedSpeciesResult!.now_sau
|
||||
const lastUpdate = update[update.length - 1]
|
||||
|
||||
assert(lastUpdate.sau_comment === editedSpecies.comment, 'Comment wrong')
|
||||
assert(lastUpdate.now_sr[lastUpdate.now_sr.length - 1].rid === editedSpecies.references![0].rid)
|
||||
|
||||
const logRows = lastUpdate.updates
|
||||
|
||||
const expectedLogRows: Partial<LogRow>[] = [
|
||||
{
|
||||
table: 'com_species',
|
||||
column: 'sp_comment',
|
||||
value: editedSpecies.sp_comment,
|
||||
oldValue: null,
|
||||
type: 'update',
|
||||
},
|
||||
{
|
||||
table: 'now_ls',
|
||||
column: 'species_id',
|
||||
value: editedSpecies.species_id!.toString(),
|
||||
oldValue: null,
|
||||
type: 'add',
|
||||
},
|
||||
]
|
||||
testLogRows(logRows, expectedLogRows, 4)
|
||||
})
|
||||
})
|
||||
Vendored
+2
-1
@@ -46,7 +46,7 @@ export type LocalitySpecies = FixBigInt<Prisma.now_ls> & { com_species: SpeciesT
|
||||
export type LocalitySpeciesDetailsType = FixBigInt<Prisma.now_ls> & { com_species: SpeciesDetailsType }
|
||||
export type SpeciesLocality = FixBigInt<Prisma.now_ls> & { now_loc: Prisma.now_loc }
|
||||
export type LocalityUpdate = Prisma.now_lau & { now_lr: LocalityReference[] } & { updates: UpdateLog[] }
|
||||
export type SpeciesUpdate = Prisma.now_sau & { now_sr: Prisma.now_sr } & { updates: UpdateLog[] }
|
||||
export type SpeciesUpdate = Prisma.now_sau & { now_sr: SpeciesReference[] } & { updates: UpdateLog[] }
|
||||
export type Museum = Prisma.com_mlist
|
||||
export type PersonDetailsType = Prisma.com_people & { user: Omit<Prisma.com_users, 'password, newpassword'> | null }
|
||||
export type ProjectPeople = Prisma.now_proj_people
|
||||
@@ -173,3 +173,4 @@ export type ReferenceOfUpdate = Prisma.ref_ref & {
|
||||
}
|
||||
|
||||
export type LocalityReference = Prisma.now_lr & ReferenceOfUpdate
|
||||
export type SpeciesReference = Prisma.now_sr & ReferenceOfUpdate
|
||||
|
||||
Reference in New Issue
Block a user