fix(backend): Fouten in isTransitionPossible en het opzetten van de testdata verbeterd.
This commit is contained in:
		
							parent
							
								
									b539c28d8c
								
							
						
					
					
						commit
						fc46e79d05
					
				
					 10 changed files with 249 additions and 68 deletions
				
			
		|  | @ -3,6 +3,7 @@ import { LearningObject } from '../../../../src/entities/content/learning-object | |||
| import { Language } from '../../../../src/entities/content/language'; | ||||
| import { loadTestAsset } from '../../../test-utils/load-test-asset'; | ||||
| import { DwengoContentType } from '../../../../src/services/learning-objects/processing/content-type'; | ||||
| import {EnvVars, getEnvVar} from "../../../../src/util/envvars"; | ||||
| 
 | ||||
| /** | ||||
|  * Create a dummy learning object to be used in tests where multiple learning objects are needed (for example for use | ||||
|  | @ -12,13 +13,17 @@ export function dummyLearningObject(hruid: string, language: Language, title: st | |||
|     return { | ||||
|         createLearningObject: () => { | ||||
|             const learningObject = new LearningObject(); | ||||
|             learningObject.hruid = hruid; | ||||
|             learningObject.hruid = getEnvVar(EnvVars.UserContentPrefix) + hruid; | ||||
|             learningObject.language = language; | ||||
|             learningObject.version = 1; | ||||
|             learningObject.title = title; | ||||
|             learningObject.description = 'Just a dummy learning object for testing purposes'; | ||||
|             learningObject.contentType = DwengoContentType.TEXT_PLAIN; | ||||
|             learningObject.content = Buffer.from('Dummy content'); | ||||
|             learningObject.returnValue = { | ||||
|                 callbackUrl: `/learningObject/${hruid}/submissions`, | ||||
|                 callbackSchema: "[]" | ||||
|             } | ||||
|             return learningObject; | ||||
|         }, | ||||
|         createAttachment: {}, | ||||
|  |  | |||
|  | @ -14,6 +14,10 @@ const example: LearningObjectExample = { | |||
|         learningObject.title = 'Essay question for testing'; | ||||
|         learningObject.description = 'This essay question was only created for testing purposes.'; | ||||
|         learningObject.contentType = DwengoContentType.GIFT; | ||||
|         learningObject.returnValue = { | ||||
|             callbackUrl: `/learningObject/${learningObject.hruid}/submissions`, | ||||
|             callbackSchema: '["antwoord vraag 1"]' | ||||
|         } | ||||
|         learningObject.content = loadTestAsset('learning-objects/test-essay/content.txt'); | ||||
|         return learningObject; | ||||
|     }, | ||||
|  |  | |||
|  | @ -14,6 +14,10 @@ const example: LearningObjectExample = { | |||
|         learningObject.title = 'Multiple choice question for testing'; | ||||
|         learningObject.description = 'This multiple choice question was only created for testing purposes.'; | ||||
|         learningObject.contentType = DwengoContentType.GIFT; | ||||
|         learningObject.returnValue = { | ||||
|             callbackUrl: `/learningObject/${learningObject.hruid}/submissions`, | ||||
|             callbackSchema: '["antwoord vraag 1"]' | ||||
|         } | ||||
|         learningObject.content = loadTestAsset('learning-objects/test-multiple-choice/content.txt'); | ||||
|         return learningObject; | ||||
|     }, | ||||
|  |  | |||
|  | @ -3,66 +3,84 @@ import { Language } from '../../../src/entities/content/language'; | |||
| import testMultipleChoiceExample from '../learning-objects/test-multiple-choice/test-multiple-choice-example'; | ||||
| import { dummyLearningObject } from '../learning-objects/dummy/dummy-learning-object-example'; | ||||
| import { createLearningPathNode, createLearningPathTransition } from './learning-path-utils'; | ||||
| import {LearningObject} from "../../../src/entities/content/learning-object.entity"; | ||||
| import {EnvVars, getEnvVar} from "../../../src/util/envvars"; | ||||
| 
 | ||||
| export type ConditionTestLearningPathAndLearningObjects = { | ||||
|     branchingObject: LearningObject, | ||||
|     extraExerciseObject: LearningObject, | ||||
|     finalObject: LearningObject, | ||||
|     learningPath: LearningPath | ||||
| }; | ||||
| 
 | ||||
| export function createConditionTestLearningPathAndLearningObjects(){ | ||||
|     const learningPath = new LearningPath(); | ||||
|     learningPath.hruid = `${getEnvVar(EnvVars.UserContentPrefix)}test_conditions`; | ||||
|     learningPath.language = Language.English; | ||||
|     learningPath.title = 'Example learning path with conditional transitions'; | ||||
|     learningPath.description = 'This learning path was made for the purpose of testing conditional transitions'; | ||||
| 
 | ||||
|     const branchingLearningObject = testMultipleChoiceExample.createLearningObject(); | ||||
|     const extraExerciseLearningObject = dummyLearningObject( | ||||
|         'test_extra_exercise', | ||||
|         Language.English, | ||||
|         'Extra exercise (for students with difficulties)' | ||||
|     ).createLearningObject(); | ||||
|     const finalLearningObject = dummyLearningObject( | ||||
|         'test_final_learning_object', | ||||
|         Language.English, | ||||
|         'Final exercise (for everyone)' | ||||
|     ).createLearningObject(); | ||||
| 
 | ||||
|     const branchingNode = createLearningPathNode( | ||||
|         learningPath, | ||||
|         0, | ||||
|         branchingLearningObject.hruid, | ||||
|         branchingLearningObject.version, | ||||
|         branchingLearningObject.language, | ||||
|         true | ||||
|     ); | ||||
|     const extraExerciseNode = createLearningPathNode( | ||||
|         learningPath, | ||||
|         1, | ||||
|         extraExerciseLearningObject.hruid, | ||||
|         extraExerciseLearningObject.version, | ||||
|         extraExerciseLearningObject.language, | ||||
|         false | ||||
|     ); | ||||
|     const finalNode = createLearningPathNode( | ||||
|         learningPath, | ||||
|         2, | ||||
|         finalLearningObject.hruid, | ||||
|         finalLearningObject.version, | ||||
|         finalLearningObject.language, | ||||
|         false | ||||
|     ); | ||||
| 
 | ||||
|     const transitionToExtraExercise = createLearningPathTransition( | ||||
|         branchingNode, | ||||
|         0, | ||||
|         '$[?(@[0] == 0)]', // The answer to the first question was the first one, which says that it is difficult for the student to follow along.
 | ||||
|         extraExerciseNode | ||||
|     ); | ||||
|     const directTransitionToFinal = createLearningPathTransition(branchingNode, 1, '$[?(@[0] == 1)]', finalNode); | ||||
|     const transitionExtraExerciseToFinal = createLearningPathTransition(extraExerciseNode, 0, 'true', finalNode); | ||||
| 
 | ||||
|     branchingNode.transitions = [transitionToExtraExercise, directTransitionToFinal]; | ||||
|     extraExerciseNode.transitions = [transitionExtraExerciseToFinal]; | ||||
| 
 | ||||
|     learningPath.nodes = [branchingNode, extraExerciseNode, finalNode]; | ||||
| 
 | ||||
|     return { | ||||
|         branchingObject: branchingLearningObject, | ||||
|         finalObject: finalLearningObject, | ||||
|         extraExerciseObject: extraExerciseLearningObject, | ||||
|         learningPath: learningPath, | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| const example: LearningPathExample = { | ||||
|     createLearningPath: () => { | ||||
|         const learningPath = new LearningPath(); | ||||
|         learningPath.hruid = 'test_conditions'; | ||||
|         learningPath.language = Language.English; | ||||
|         learningPath.title = 'Example learning path with conditional transitions'; | ||||
|         learningPath.description = 'This learning path was made for the purpose of testing conditional transitions'; | ||||
| 
 | ||||
|         const branchingLearningObject = testMultipleChoiceExample.createLearningObject(); | ||||
|         const extraExerciseLearningObject = dummyLearningObject( | ||||
|             'test_extra_exercise', | ||||
|             Language.English, | ||||
|             'Extra exercise (for students with difficulties)' | ||||
|         ).createLearningObject(); | ||||
|         const finalLearningObject = dummyLearningObject( | ||||
|             'test_final_learning_object', | ||||
|             Language.English, | ||||
|             'Final exercise (for everyone)' | ||||
|         ).createLearningObject(); | ||||
| 
 | ||||
|         const branchingNode = createLearningPathNode( | ||||
|             learningPath, | ||||
|             0, | ||||
|             branchingLearningObject.hruid, | ||||
|             branchingLearningObject.version, | ||||
|             branchingLearningObject.language, | ||||
|             true | ||||
|         ); | ||||
|         const extraExerciseNode = createLearningPathNode( | ||||
|             learningPath, | ||||
|             1, | ||||
|             extraExerciseLearningObject.hruid, | ||||
|             extraExerciseLearningObject.version, | ||||
|             extraExerciseLearningObject.language, | ||||
|             false | ||||
|         ); | ||||
|         const finalNode = createLearningPathNode( | ||||
|             learningPath, | ||||
|             2, | ||||
|             finalLearningObject.hruid, | ||||
|             finalLearningObject.version, | ||||
|             finalLearningObject.language, | ||||
|             false | ||||
|         ); | ||||
| 
 | ||||
|         const transitionToExtraExercise = createLearningPathTransition( | ||||
|             branchingNode, | ||||
|             0, | ||||
|             '$[?(@[0] == 0)]', // The answer to the first question was the first one, which says that it is difficult for the student to follow along.
 | ||||
|             extraExerciseNode | ||||
|         ); | ||||
|         const directTransitionToFinal = createLearningPathTransition(branchingNode, 1, '$[?(@[0] == 1)]', finalNode); | ||||
|         const transitionExtraExerciseToFinal = createLearningPathTransition(extraExerciseNode, 0, 'true', finalNode); | ||||
| 
 | ||||
|         branchingNode.transitions = [transitionToExtraExercise, directTransitionToFinal]; | ||||
|         extraExerciseNode.transitions = [transitionExtraExerciseToFinal]; | ||||
| 
 | ||||
|         learningPath.nodes = [branchingNode, extraExerciseNode, finalNode]; | ||||
| 
 | ||||
|         return learningPath; | ||||
|         return createConditionTestLearningPathAndLearningObjects().learningPath; | ||||
|     }, | ||||
| }; | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger