add question fix

This commit is contained in:
mrfry 2022-03-28 21:41:57 +02:00
parent 1a76ca2536
commit 347952c6da
2 changed files with 51 additions and 3 deletions

View file

@ -0,0 +1,48 @@
import { addQuestion, createQuestion } from '../utils/classes'
import { Subject, Question } from '../types/basicTypes'
const question: Question = createQuestion('asd', 'asd', { type: 'simple' })
test('Adds questions to empty db', () => {
const emptyDb: Subject[] = []
addQuestion(emptyDb, 'test subject', question)
expect(emptyDb.length).toBe(1)
})
test('Adds questions next to existing', () => {
const db: Subject[] = [
{
Name: 'test subject',
Questions: [question],
},
]
addQuestion(db, 'another something', question)
expect(db.length).toBe(2)
})
test('Does not add new subject, multiple new questions', () => {
const db: Subject[] = [
{
Name: 'test subject',
Questions: [question],
},
]
addQuestion(db, 'test subject', question)
addQuestion(db, 'test subject', question)
addQuestion(db, 'test subject', question)
addQuestion(db, 'test subject', question)
expect(db.length).toBe(1)
})
test('Adds new subjects, multiple new questions', () => {
const db: Subject[] = [
{
Name: 'test subject',
Questions: [question],
},
]
addQuestion(db, 'gfjdkglfd', question)
addQuestion(db, ' somrthing test ', question)
addQuestion(db, 'aaaaaaaa', question)
expect(db.length).toBe(4)
})

View file

@ -460,10 +460,10 @@ function addQuestion(
logger.DebugLog('Adding new question with subjName: ' + subj, 'qdb add', 1)
logger.DebugLog(question, 'qdb add', 3)
const i = data.findIndex((x) => {
return !subj
const i = data.findIndex((subject) => {
return subj
.toLowerCase()
.includes(getSubjNameWithoutYear(x.Name).toLowerCase())
.includes(getSubjNameWithoutYear(subject.Name).toLowerCase())
})
if (i !== -1) {