test: learning object repository is getest
This commit is contained in:
		
							parent
							
								
									714a3dab10
								
							
						
					
					
						commit
						6338ad249a
					
				
					 2 changed files with 88 additions and 0 deletions
				
			
		
							
								
								
									
										32
									
								
								backend/tests/data/learning-objects.test.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								backend/tests/data/learning-objects.test.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,32 @@ | ||||||
|  | import { beforeAll, describe, expect, it } from "vitest"; | ||||||
|  | import { LearningObjectRepository } from "../../src/data/content/learning-object-repository"; | ||||||
|  | import { getLearningObjectRepository } from "../../src/data/repositories"; | ||||||
|  | import { setupTestApp } from "../setup-tests"; | ||||||
|  | import { LearningObjectIdentifier } from "../../src/entities/content/learning-object-identifier"; | ||||||
|  | import { Language } from "../../src/entities/content/language"; | ||||||
|  | 
 | ||||||
|  | describe('LearningObjectRepository', () => { | ||||||
|  |     let LearningObjectRepository: LearningObjectRepository; | ||||||
|  | 
 | ||||||
|  |     beforeAll(async () => { | ||||||
|  |         await setupTestApp(); | ||||||
|  |         LearningObjectRepository = getLearningObjectRepository(); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     const id01 = new LearningObjectIdentifier('hruid_object01', Language.English, '1'); | ||||||
|  |     const id02 = new LearningObjectIdentifier('hruid_object06', Language.English, '1'); | ||||||
|  | 
 | ||||||
|  |     it('should return the learning object that matches identifier 1', async() => { | ||||||
|  |         const learningObject = await LearningObjectRepository.findByIdentifier(id01); | ||||||
|  | 
 | ||||||
|  |         expect(learningObject).toBeTruthy(); | ||||||
|  |         expect(learningObject?.title).toBe('Undertow'); | ||||||
|  |         expect(learningObject?.description).toBe('debute'); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it('should return nothing because the identifier does not exist in the database', async() => { | ||||||
|  |         const learningObject = await LearningObjectRepository.findByIdentifier(id02); | ||||||
|  | 
 | ||||||
|  |         expect(learningObject).toBeNull(); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|  | @ -1,3 +1,5 @@ | ||||||
|  | import { Language } from '../src/entities/content/language.js'; | ||||||
|  | import { ContentType, LearningObject, ReturnValue } from '../src/entities/content/learning-object.entity.js'; | ||||||
| import { Student } from '../src/entities/users/student.entity.js'; | import { Student } from '../src/entities/users/student.entity.js'; | ||||||
| import { Teacher } from '../src/entities/users/teacher.entity.js'; | import { Teacher } from '../src/entities/users/teacher.entity.js'; | ||||||
| import { forkEntityManager, initORM } from '../src/orm.js'; | import { forkEntityManager, initORM } from '../src/orm.js'; | ||||||
|  | @ -20,4 +22,58 @@ export async function setupTestApp() { | ||||||
|     const teacher03 = em.create(Teacher, { username: 'TheDoors', firstName: 'Jim', lastName: 'Morrison'}); |     const teacher03 = em.create(Teacher, { username: 'TheDoors', firstName: 'Jim', lastName: 'Morrison'}); | ||||||
| 
 | 
 | ||||||
|     await em.persistAndFlush([teacher01, teacher02, teacher03]); |     await em.persistAndFlush([teacher01, teacher02, teacher03]); | ||||||
|  | 
 | ||||||
|  |     const admins01 = [teacher01]; | ||||||
|  |     const returnValue = new ReturnValue(); | ||||||
|  |     returnValue.callbackSchema = ''; | ||||||
|  |     returnValue.callbackUrl = ''; | ||||||
|  |     const buffer01 = 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, | ||||||
|  |         version: '1', | ||||||
|  |         admins: admins01, | ||||||
|  |         title: 'Undertow', | ||||||
|  |         description: 'debute', | ||||||
|  |         contentType: ContentType.Markdown, | ||||||
|  |         keywords: [], | ||||||
|  |         teacherExclusive: false, | ||||||
|  |         skosConcepts: [], | ||||||
|  |         educationalGoals: [], | ||||||
|  |         copyright: '', | ||||||
|  |         license: '', | ||||||
|  |         estimatedTime: 45, | ||||||
|  |         returnValue: returnValue, | ||||||
|  |         available: true, | ||||||
|  |         contentLocation: '', | ||||||
|  |         attachments: [], | ||||||
|  |         content: buffer01 | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     const admins02 = [teacher02]; | ||||||
|  |     const buffer02 = 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 learningObject02 = em.create(LearningObject, { | ||||||
|  |         hruid: 'hruid_object02', | ||||||
|  |         language: Language.English, | ||||||
|  |         version: '1', | ||||||
|  |         admins: admins02, | ||||||
|  |         title: 'Break the cycle', | ||||||
|  |         description: 'second album', | ||||||
|  |         contentType: ContentType.Markdown, | ||||||
|  |         keywords: ["music"], | ||||||
|  |         teacherExclusive: false, | ||||||
|  |         skosConcepts: [], | ||||||
|  |         educationalGoals: [], | ||||||
|  |         copyright: '', | ||||||
|  |         license: '', | ||||||
|  |         estimatedTime: 55, | ||||||
|  |         returnValue: returnValue, | ||||||
|  |         available: true, | ||||||
|  |         contentLocation: '', | ||||||
|  |         attachments: [], | ||||||
|  |         content: buffer02 | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     await em.persistAndFlush([learningObject01, learningObject02]); | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Laure Jablonski
						Laure Jablonski