aboutsummaryrefslogtreecommitdiff
path: root/js/mock.js
blob: e4aca53d2da6008068d95c845d9bef6ab4f8283f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { Graduation, GraduationChange } from "./graduation-common.js";
import { Student } from "./student-common.js";
import { buildGroups } from "./group.js";

const students = [
	new Student(1, 'foo bar', ['test']),
	new Student(2, 'maxi mustermensch', ['test']),
	new Student(3, 'b b b', ['5a'])
];

// Build the groups from our mock students
buildGroups(students);

function fetchStudentsMock() {
	return new Promise((resolve) => { resolve(students); });
}

function fetchSubjectsMock() {
	return new Promise((resolve) => {
		resolve(['Mathe', 'Deutsch', 'Englisch']);
	});
}

function fetchProgressMock(subject) {
	return new Promise((resolve) => {
		if (subject === "Mathe") {
			resolve([40, 10, 3]);
		} else if (subject === "Deutsch") {
			resolve([10, 2, 0]);
		} else if (subject === "Englisch") {
			resolve([50, 25, 10]);
		} else {
			resolve([0, 0, 0]);
		}
	});
}

const graduationChanges = {};
for (const s of students) {
	switch (s.name) {
	case "foo bar":
		graduationChanges[s.name] = [
			GraduationChange.newGreenPointChange(s, "", "Florian Fischer"),
			GraduationChange.newOrangePointChange(s, "", "Florian Fischer"),
		];
		break;
	case "maxi mustermensch":
		graduationChanges[s.name] = [
			GraduationChange.newGreenPointChange(s, "", "Florian Fischer"),
			GraduationChange.newGreenPointChange(s, "", "Florian Fischer"),
			new GraduationChange(new Date(), s.id, s.name, "Änderung", "", "", '{"type": "ObservationStart"}'),
		];
		break;
	case "b b b":
		graduationChanges[s.name] = [
			GraduationChange.newRedPointChange(s, "", "Florian Fischer"),
		];
	}
	// Build the student's graduation
	Graduation.from(s, graduationChanges[s.name]);
}

function fetchGraduationMock(s) {
	return new Promise((resolve) => {
		const changes =  graduationChanges[s.name];
		if (!changes) {
			resolve(null);
		} else {
			resolve(Graduation.from(s, graduationChanges[s.name]));
		}
	});
}

function submitGraduationChangeMock(s, c) {
	if (s.graduation) {
		s.graduation.addChange(c);
	} else {
		s.graduation = Graduation.from(s, [c]);
	}
}

export {
	fetchStudentsMock,
	fetchSubjectsMock,
	fetchProgressMock,
	fetchGraduationMock,
	submitGraduationChangeMock,
};