test: class repository is getest
This commit is contained in:
		
							parent
							
								
									8f0a76f4e6
								
							
						
					
					
						commit
						127088ea00
					
				
					 2 changed files with 125 additions and 30 deletions
				
			
		
							
								
								
									
										34
									
								
								backend/tests/data/classes.test.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								backend/tests/data/classes.test.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,34 @@ | |||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { ClassRepository } from '../../src/data/classes/class-repository'; | ||||
| import { setupTestApp } from '../setup-tests'; | ||||
| import { getClassRepository } from '../../src/data/repositories'; | ||||
| 
 | ||||
| describe('ClassRepository', () => { | ||||
|     let ClassRepository: ClassRepository; | ||||
| 
 | ||||
|     beforeAll(async () => { | ||||
|         await setupTestApp(); | ||||
|         ClassRepository = getClassRepository(); | ||||
|     }); | ||||
| 
 | ||||
|     it('should return nothing because id does not exist', async () => { | ||||
|         const classVar = await ClassRepository.findById('id'); | ||||
| 
 | ||||
|         expect(classVar).toBeNull(); | ||||
|     }); | ||||
| 
 | ||||
|     it('should return requested class', async () => { | ||||
|         const classVar = await ClassRepository.findById('class_id01'); | ||||
| 
 | ||||
|         expect(classVar).toBeTruthy(); | ||||
|         expect(classVar?.displayName).toBe('class01'); | ||||
|     }); | ||||
| 
 | ||||
|     it('class should be gone after deletion', async () => { | ||||
|         await ClassRepository.deleteById('class_id01'); | ||||
| 
 | ||||
|         const classVar = await ClassRepository.findById('class_id01'); | ||||
| 
 | ||||
|         expect(classVar).toBeNull(); | ||||
|     }); | ||||
| }); | ||||
|  | @ -1,6 +1,15 @@ | |||
| import { Class } from '../src/entities/classes/class.entity.js'; | ||||
| import { Language } from '../src/entities/content/language.js'; | ||||
| import { ContentType, LearningObject, ReturnValue } from '../src/entities/content/learning-object.entity.js'; | ||||
| import { LearningPath, LearningPathNode, LearningPathTransition } from '../src/entities/content/learning-path.entity.js'; | ||||
| import { | ||||
|     ContentType, | ||||
|     LearningObject, | ||||
|     ReturnValue, | ||||
| } from '../src/entities/content/learning-object.entity.js'; | ||||
| import { | ||||
|     LearningPath, | ||||
|     LearningPathNode, | ||||
|     LearningPathTransition, | ||||
| } from '../src/entities/content/learning-path.entity.js'; | ||||
| import { Student } from '../src/entities/users/student.entity.js'; | ||||
| import { Teacher } from '../src/entities/users/teacher.entity.js'; | ||||
| import { forkEntityManager, initORM } from '../src/orm.js'; | ||||
|  | @ -12,23 +21,49 @@ export async function setupTestApp() { | |||
| 
 | ||||
|     const em = forkEntityManager(); | ||||
| 
 | ||||
|     const student01 = em.create(Student, {username: 'Noordkaap', firstName: 'Stijn', lastName: 'Meuris'}); | ||||
|     const student02 = em.create(Student, {username: 'DireStraits', firstName: 'Mark', lastName: 'Knopfler'}); | ||||
|     const student03 = em.create(Student, {username: 'SmashingPumpkins', firstName: 'Billy', lastName: 'Corgan'}); | ||||
|     const student01 = em.create(Student, { | ||||
|         username: 'Noordkaap', | ||||
|         firstName: 'Stijn', | ||||
|         lastName: 'Meuris', | ||||
|     }); | ||||
|     const student02 = em.create(Student, { | ||||
|         username: 'DireStraits', | ||||
|         firstName: 'Mark', | ||||
|         lastName: 'Knopfler', | ||||
|     }); | ||||
|     const student03 = em.create(Student, { | ||||
|         username: 'SmashingPumpkins', | ||||
|         firstName: 'Billy', | ||||
|         lastName: 'Corgan', | ||||
|     }); | ||||
| 
 | ||||
|     await em.persistAndFlush([student01, student02, student03]); | ||||
| 
 | ||||
|     const teacher01 = em.create(Teacher, {username: 'Tool', firstName: 'Maynard', lastName: 'Keenan'}); | ||||
|     const teacher02 = em.create(Teacher, { username: 'Staind', firstName: 'Aaron', lastName: 'Lewis'}); | ||||
|     const teacher03 = em.create(Teacher, { username: 'TheDoors', firstName: 'Jim', lastName: 'Morrison'}); | ||||
|     const teacher01 = em.create(Teacher, { | ||||
|         username: 'Tool', | ||||
|         firstName: 'Maynard', | ||||
|         lastName: 'Keenan', | ||||
|     }); | ||||
|     const teacher02 = em.create(Teacher, { | ||||
|         username: 'Staind', | ||||
|         firstName: 'Aaron', | ||||
|         lastName: 'Lewis', | ||||
|     }); | ||||
|     const teacher03 = em.create(Teacher, { | ||||
|         username: 'TheDoors', | ||||
|         firstName: 'Jim', | ||||
|         lastName: 'Morrison', | ||||
|     }); | ||||
| 
 | ||||
|     await em.persistAndFlush([teacher01, teacher02, teacher03]); | ||||
| 
 | ||||
|     const admins01 : Array<Teacher> = [teacher01]; | ||||
|     const returnValue : ReturnValue = new ReturnValue(); | ||||
|     const admins01: Array<Teacher> = [teacher01]; | ||||
|     const returnValue: ReturnValue = new ReturnValue(); | ||||
|     returnValue.callbackSchema = ''; | ||||
|     returnValue.callbackUrl = ''; | ||||
|     const buffer01 : Buffer = new Buffer("there's a shadow just behind me, shrouding every step i take, making every promise empty pointing every finger at me"); | ||||
|     const buffer01: Buffer = new Buffer( | ||||
|         "there's a shadow just behind me, shrouding every step i take, making every promise empty pointing every finger at me" | ||||
|     ); | ||||
|     const learningObject01 = em.create(LearningObject, { | ||||
|         hruid: 'hruid_object01', | ||||
|         language: Language.English, | ||||
|  | @ -48,10 +83,12 @@ export async function setupTestApp() { | |||
|         available: true, | ||||
|         contentLocation: '', | ||||
|         attachments: [], | ||||
|         content: buffer01 | ||||
|         content: buffer01, | ||||
|     }); | ||||
| 
 | ||||
|     const buffer02 = new Buffer("I've been crawling on my belly clearing out what could've been I've been wallowing in my own confused and insecure delusions"); | ||||
|     const buffer02 = new Buffer( | ||||
|         "I've been crawling on my belly clearing out what could've been I've been wallowing in my own confused and insecure delusions" | ||||
|     ); | ||||
|     const learningObject02 = em.create(LearningObject, { | ||||
|         hruid: 'hruid_object02', | ||||
|         language: Language.English, | ||||
|  | @ -71,11 +108,13 @@ export async function setupTestApp() { | |||
|         available: true, | ||||
|         contentLocation: '', | ||||
|         attachments: [], | ||||
|         content: buffer02 | ||||
|         content: buffer02, | ||||
|     }); | ||||
| 
 | ||||
|     const admins03 : Array<Teacher> = [teacher02]; | ||||
|     const buffer03 = new Buffer("cause it's always raining in my head, forget all the things I should have had said so I speak to you in riddles, because my words get in my way") | ||||
|     const admins03: Array<Teacher> = [teacher02]; | ||||
|     const buffer03 = new Buffer( | ||||
|         "cause it's always raining in my head, forget all the things I should have had said so I speak to you in riddles, because my words get in my way" | ||||
|     ); | ||||
|     const learningObject03 = em.create(LearningObject, { | ||||
|         hruid: 'hruid_object03', | ||||
|         language: Language.English, | ||||
|  | @ -84,7 +123,7 @@ export async function setupTestApp() { | |||
|         title: 'Break the cycle', | ||||
|         description: 'second album', | ||||
|         contentType: ContentType.Markdown, | ||||
|         keywords: ["music"], | ||||
|         keywords: ['music'], | ||||
|         teacherExclusive: false, | ||||
|         skosConcepts: [], | ||||
|         educationalGoals: [], | ||||
|  | @ -95,30 +134,34 @@ export async function setupTestApp() { | |||
|         available: true, | ||||
|         contentLocation: '', | ||||
|         attachments: [], | ||||
|         content: buffer03 | ||||
|         content: buffer03, | ||||
|     }); | ||||
| 
 | ||||
|     await em.persistAndFlush([learningObject01, learningObject02, learningObject03]); | ||||
|     await em.persistAndFlush([ | ||||
|         learningObject01, | ||||
|         learningObject02, | ||||
|         learningObject03, | ||||
|     ]); | ||||
| 
 | ||||
|     const learningPathNode01 : LearningPathNode = new LearningPathNode(); | ||||
|     const learningPathNode02 : LearningPathNode = new LearningPathNode(); | ||||
|     const learningPathNode01: LearningPathNode = new LearningPathNode(); | ||||
|     const learningPathNode02: LearningPathNode = new LearningPathNode(); | ||||
| 
 | ||||
|     const transitions01: LearningPathTransition = new LearningPathTransition(); | ||||
|     const transitions02: LearningPathTransition = new LearningPathTransition(); | ||||
| 
 | ||||
|     const transitions01 : LearningPathTransition = new LearningPathTransition(); | ||||
|     const transitions02 : LearningPathTransition = new LearningPathTransition(); | ||||
|      | ||||
|     transitions01.condition = 'true'; | ||||
|     transitions01.next = learningPathNode02; | ||||
|      | ||||
| 
 | ||||
|     transitions02.condition = 'true'; | ||||
|     transitions02.next = learningPathNode01; | ||||
|      | ||||
| 
 | ||||
|     learningPathNode01.instruction = ''; | ||||
|     learningPathNode01.language = Language.English; | ||||
|     learningPathNode01.learningObjectHruid = 'hruid_object01'; | ||||
|     learningPathNode01.startNode = true; | ||||
|     learningPathNode01.transitions = [transitions01]; | ||||
|     learningPathNode01.version = '1'; | ||||
|      | ||||
| 
 | ||||
|     learningPathNode02.instruction = ''; | ||||
|     learningPathNode02.language = Language.English; | ||||
|     learningPathNode02.learningObjectHruid = 'hruid_object02'; | ||||
|  | @ -126,8 +169,7 @@ export async function setupTestApp() { | |||
|     learningPathNode02.transitions = [transitions02]; | ||||
|     learningPathNode02.version = '1'; | ||||
| 
 | ||||
| 
 | ||||
|     const nodes : Array<LearningPathNode> = [] | ||||
|     const nodes: Array<LearningPathNode> = []; | ||||
|     const learningPath01 = em.create(LearningPath, { | ||||
|         hruid: 'hruid_path01', | ||||
|         language: Language.English, | ||||
|  | @ -135,8 +177,27 @@ export async function setupTestApp() { | |||
|         title: 'repertoire Tool', | ||||
|         description: 'all about Tool', | ||||
|         image: '', | ||||
|         nodes: nodes | ||||
|         nodes: nodes, | ||||
|     }); | ||||
| 
 | ||||
|     await em.persistAndFlush([learningPath01]); | ||||
| 
 | ||||
|     const students: Array<Student> = [student01, student02]; | ||||
| 
 | ||||
|     // gets deleted in test, do not use in other tests
 | ||||
|     const class01 = em.create(Class, { | ||||
|         classId: 'class_id01', | ||||
|         displayName: 'class01', | ||||
|         teachers: admins01, | ||||
|         students: students, | ||||
|     }); | ||||
| 
 | ||||
|     const class02 = em.create(Class, { | ||||
|         classId: 'class_id02', | ||||
|         displayName: 'class02', | ||||
|         teachers: admins01, | ||||
|         students: students, | ||||
|     }); | ||||
| 
 | ||||
|     await em.persistAndFlush([class01, class02]); | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Laure Jablonski
						Laure Jablonski