mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
stricter subj name checking on question add, should log test fix
This commit is contained in:
parent
537f4c413e
commit
d962abfbc2
5 changed files with 144 additions and 51 deletions
|
@ -1,5 +1,11 @@
|
|||
import { addQuestion, createQuestion } from '../utils/classes'
|
||||
import {
|
||||
addQuestion,
|
||||
createQuestion,
|
||||
getSubjNameWithoutYear,
|
||||
} from '../utils/classes'
|
||||
import { Subject, Question } from '../types/basicTypes'
|
||||
import fs from 'fs'
|
||||
import { RecievedData } from '../utils/actions'
|
||||
|
||||
const question: Question = createQuestion('asd', 'asd', { type: 'simple' })
|
||||
|
||||
|
@ -46,3 +52,83 @@ test('Adds new subjects, multiple new questions', () => {
|
|||
addQuestion(db, 'aaaaaaaa', question)
|
||||
expect(db.length).toBe(4)
|
||||
})
|
||||
|
||||
test("New subject names shouldn't be empty", () => {
|
||||
const data: RecievedData = JSON.parse(
|
||||
fs.readFileSync(
|
||||
__dirname + '/../../devel/tests/testData/ROS.json',
|
||||
'utf8'
|
||||
)
|
||||
)
|
||||
|
||||
const db: Subject[] = [
|
||||
{
|
||||
Name: 'test subject',
|
||||
Questions: [question],
|
||||
},
|
||||
]
|
||||
|
||||
data.quiz.forEach((question) => {
|
||||
const subjName = getSubjNameWithoutYear(data.subj)
|
||||
addQuestion(db, subjName, question)
|
||||
})
|
||||
db.forEach((subj) => {
|
||||
expect(subj.Name).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
test('New questions shouldnt be added to accidental empty named subjects', () => {
|
||||
const data: RecievedData = JSON.parse(
|
||||
fs.readFileSync(
|
||||
__dirname + '/../../devel/tests/testData/ROS.json',
|
||||
'utf8'
|
||||
)
|
||||
)
|
||||
|
||||
const db: Subject[] = [
|
||||
{
|
||||
Name: '',
|
||||
Questions: [question],
|
||||
},
|
||||
]
|
||||
|
||||
data.quiz.forEach((question) => {
|
||||
const subjName = getSubjNameWithoutYear(data.subj)
|
||||
addQuestion(db, subjName, question)
|
||||
})
|
||||
expect(db[0].Questions.length).toBe(1)
|
||||
expect(db.length).toBe(2)
|
||||
})
|
||||
|
||||
test('Question gets added to the correct subject', () => {
|
||||
const data: RecievedData = JSON.parse(
|
||||
fs.readFileSync(
|
||||
__dirname + '/../../devel/tests/testData/ROS.json',
|
||||
'utf8'
|
||||
)
|
||||
)
|
||||
|
||||
const subjName = getSubjNameWithoutYear(data.subj)
|
||||
const db: Subject[] = [
|
||||
{
|
||||
Name: subjName,
|
||||
Questions: [question],
|
||||
},
|
||||
{
|
||||
Name: data.subj, // subj name with course date in it (2022/23/2 -)
|
||||
Questions: [question],
|
||||
},
|
||||
]
|
||||
|
||||
data.quiz.forEach((question) => {
|
||||
addQuestion(db, subjName, question)
|
||||
})
|
||||
data.quiz.forEach((question) => {
|
||||
addQuestion(db, 'some other subject name', question)
|
||||
})
|
||||
|
||||
expect(db[0].Questions.length).toBe(9)
|
||||
expect(db[1].Questions.length).toBe(1)
|
||||
expect(db[2].Questions.length).toBe(8)
|
||||
expect(db.length).toBe(3)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue