test: submission data
This commit is contained in:
parent
d16584fb53
commit
5eaa93e18f
2 changed files with 40 additions and 38 deletions
|
@ -10,69 +10,62 @@ import {
|
|||
} from '../../../src/data/repositories';
|
||||
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { StudentRepository } from '../../../src/data/users/student-repository';
|
||||
import { GroupRepository } from '../../../src/data/assignments/group-repository';
|
||||
import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository';
|
||||
import { ClassRepository } from '../../../src/data/classes/class-repository';
|
||||
import { Submission } from '../../../src/entities/assignments/submission.entity';
|
||||
import { Class } from '../../../src/entities/classes/class.entity';
|
||||
import { Assignment } from '../../../src/entities/assignments/assignment.entity';
|
||||
import { testLearningObject01 } from '../../test_assets/content/learning-objects.testdata';
|
||||
import { testLearningObject01, testLearningObject03 } from '../../test_assets/content/learning-objects.testdata';
|
||||
import { getSubmission01, getSubmission02, getSubmission07, getSubmission08 } from '../../test_assets/assignments/submission.testdata';
|
||||
import { use } from 'marked';
|
||||
import { getAssignment01 } from '../../test_assets/assignments/assignments.testdata';
|
||||
import { getTestGroup02 } from '../../test_assets/assignments/groups.testdata';
|
||||
|
||||
describe('SubmissionRepository', () => {
|
||||
let submissionRepository: SubmissionRepository;
|
||||
let studentRepository: StudentRepository;
|
||||
let groupRepository: GroupRepository;
|
||||
let assignmentRepository: AssignmentRepository;
|
||||
let classRepository: ClassRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
submissionRepository = getSubmissionRepository();
|
||||
studentRepository = getStudentRepository();
|
||||
groupRepository = getGroupRepository();
|
||||
assignmentRepository = getAssignmentRepository();
|
||||
classRepository = getClassRepository();
|
||||
});
|
||||
|
||||
it('should find the requested submission', async () => {
|
||||
const id = new LearningObjectIdentifier('id03', Language.English, 1);
|
||||
const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(id, 1);
|
||||
const usedSubmission = getSubmission01();
|
||||
const id = new LearningObjectIdentifier(usedSubmission.learningObjectHruid, usedSubmission.learningObjectLanguage, usedSubmission.learningObjectVersion);
|
||||
const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(id, usedSubmission.submissionNumber!);
|
||||
|
||||
expect(submission).toBeTruthy();
|
||||
expect(submission?.content).toBe('sub1');
|
||||
expect(submission?.content).toBe(usedSubmission.content);
|
||||
expect(submission?.submissionNumber).toBe(usedSubmission.submissionNumber);
|
||||
expect(submission?.submitter.username).toBe(usedSubmission.submitter.username);
|
||||
});
|
||||
|
||||
it('should find the most recent submission for a student', async () => {
|
||||
const id = new LearningObjectIdentifier('id02', Language.English, 1);
|
||||
const student = await studentRepository.findByUsername('Noordkaap');
|
||||
const submission = await submissionRepository.findMostRecentSubmissionForStudent(id, student!);
|
||||
const usedSubmission = getSubmission02();
|
||||
const id = new LearningObjectIdentifier(usedSubmission.learningObjectHruid, usedSubmission.learningObjectLanguage, usedSubmission.learningObjectVersion);
|
||||
|
||||
const submission = await submissionRepository.findMostRecentSubmissionForStudent(id, usedSubmission.submitter!);
|
||||
|
||||
expect(submission).toBeTruthy();
|
||||
expect(submission?.submissionTime.getDate()).toBe(25);
|
||||
expect(submission?.submissionTime).toStrictEqual(usedSubmission.submissionTime);
|
||||
});
|
||||
|
||||
it('should find the most recent submission for a group', async () => {
|
||||
const id = new LearningObjectIdentifier('id03', Language.English, 1);
|
||||
const class_ = await classRepository.findById('8764b861-90a6-42e5-9732-c0d9eb2f55f9');
|
||||
const assignment = await assignmentRepository.findByClassAndId(class_!, 21000);
|
||||
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment!, 21001);
|
||||
const submission = await submissionRepository.findMostRecentSubmissionForGroup(id, group!);
|
||||
const usedSubmission = getSubmission02();
|
||||
const id = new LearningObjectIdentifier(usedSubmission.learningObjectHruid, usedSubmission.learningObjectLanguage, usedSubmission.learningObjectVersion);
|
||||
|
||||
const submission = await submissionRepository.findMostRecentSubmissionForGroup(id, usedSubmission.onBehalfOf);
|
||||
|
||||
expect(submission).toBeTruthy();
|
||||
expect(submission?.submissionTime.getDate()).toBe(25);
|
||||
expect(submission?.submissionTime).toStrictEqual(usedSubmission.submissionTime);
|
||||
});
|
||||
|
||||
let clazz: Class | null;
|
||||
let assignment: Assignment | null;
|
||||
let loId: LearningObjectIdentifier;
|
||||
it('should find all submissions for a certain learning object and assignment', async () => {
|
||||
clazz = await classRepository.findById('8764b861-90a6-42e5-9732-c0d9eb2f55f9');
|
||||
assignment = await assignmentRepository.findByClassAndId(clazz!, 21000);
|
||||
loId = {
|
||||
hruid: 'id02',
|
||||
language: Language.English,
|
||||
version: 1,
|
||||
const usedSubmission = getSubmission08();
|
||||
const assignment = getAssignment01();
|
||||
|
||||
const loId = {
|
||||
hruid: usedSubmission.learningObjectHruid,
|
||||
language: usedSubmission.learningObjectLanguage,
|
||||
version: usedSubmission.learningObjectVersion,
|
||||
};
|
||||
const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!);
|
||||
sortSubmissions(result);
|
||||
|
@ -93,7 +86,14 @@ describe('SubmissionRepository', () => {
|
|||
});
|
||||
|
||||
it('should find only the submissions for a certain learning object and assignment made for the given group', async () => {
|
||||
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment!, 21002);
|
||||
const group = getTestGroup02();
|
||||
const usedSubmission = getSubmission08();
|
||||
const loId = {
|
||||
hruid: usedSubmission.learningObjectHruid,
|
||||
language: usedSubmission.learningObjectLanguage,
|
||||
version: usedSubmission.learningObjectVersion,
|
||||
};
|
||||
|
||||
const result = await submissionRepository.findAllSubmissionsForLearningObjectAndGroup(loId, group!);
|
||||
|
||||
expect(result).toHaveLength(1);
|
||||
|
@ -107,10 +107,11 @@ describe('SubmissionRepository', () => {
|
|||
});
|
||||
|
||||
it('should not find a deleted submission', async () => {
|
||||
const usedSubmission = getSubmission07();
|
||||
const id = new LearningObjectIdentifier(testLearningObject01.hruid, testLearningObject01.language, testLearningObject01.version);
|
||||
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(id, 1);
|
||||
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(id, usedSubmission.submissionNumber!);
|
||||
|
||||
const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(id, 1);
|
||||
const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(id, usedSubmission.submissionNumber!);
|
||||
|
||||
expect(submission).toBeNull();
|
||||
});
|
||||
|
|
|
@ -71,6 +71,7 @@ export function makeTestSubmissions(em: EntityManager): Submission[] {
|
|||
content: '',
|
||||
});
|
||||
|
||||
// gets deleted
|
||||
submission07 = em.create(Submission, {
|
||||
learningObjectHruid: testLearningObject01.hruid,
|
||||
learningObjectLanguage: testLearningObject01.language,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue