-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
326 lines (264 loc) · 7.29 KB
/
test.ts
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/**
* to run the tests first
* execute PA -> Install -> Install sheets
* and PA -> Install ->
*/
/**
* uncomment the following lines to enable testing for development.
*
* The lines are commented to allow menu installation easily for users.
*/
// if ((typeof GasTap)==='undefined') { // GasT Initialization. (only if not initialized yet.)
// eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/huan/gast/master/src/gas-tap-lib.js').getContentText())
// } // Class GasTap is ready for use now!
// var test = new GasTap();
/**
* IMPORTANT:
*
* SET TO TRUE for executing e2e tests
* REMEMBER to reset to false afterwards!!
*
* In test mode the app send MOCK emails instead of using the GmailApp
*/
let testMode: boolean = false;
/**
*
*
*
*/
function gastTestRunner() {
testMode = true;
deleteAllTriggers();
testgetProjects();
testGetGroup();
testIsProjectkey();
testGetProjectKeys();
testGetStudents();
testGetStudent();
testCalculateGrade();
testNotVerifiedStudents();
testFillWithUnderScore();
testState();
// testGetPaProjects();
testOpenPA();
testGetQuestions();
testGetSettings();
// test.finish();
testMode = false;
}
let testStudents: Student[] = [
{
fname: 'Dimitris',
lname: 'Dranidis',
email: 'dranidis@gmail.com',
projectkey: 'PROJ123',
personalkey: 'aaaaa',
verified: true,
submittedpa: {}
},
{
fname: 'DD',
lname: 'Tomail',
email: 'ddtomail@gmail.com',
projectkey: 'PROJ456',
personalkey: '',
verified: false,
submittedpa: {}
},
{
fname: 'Dimi',
lname: 'Dran',
email: 'dranidis@citycollege.sheffield.eu',
projectkey: 'PROJ123',
personalkey: '',
verified: false,
submittedpa: {}
}
];
let testProjects: Project[] = [
{
name: 'Project1',
key: 'PROJ123',
},
{
name: 'Project2',
key: 'PROJ456',
},
{
name: 'Project3',
key: 'PROJ789',
}
];
let testPAs: PeerAssessment[] = [
{
name: "Peer Assessment 1",
id: "PA1",
deadline: new Date((new Date()).getTime() + 15 * my_MILLIS_PER_MINUTE),
state: PaState.INACTIVE
}
]
function preSetupPA() {
let ss = SpreadsheetApp.getActive().getSheetByName(PAS.sheet);
ss.getDataRange().offset(1, 0).clearContent();
for (let i = 0; i < testPAs.length; i++)
addPa(testPAs[i]);
}
function preSetupStudents_() {
let ss = SpreadsheetApp.getActive().getSheetByName(STUDENTS.sheet);
ss.getDataRange().offset(1, 0).clearContent();
for (let i = 0; i < testStudents.length; i++)
addStudent(testStudents[i]);
}
function preSetupProjects_() {
let ss = SpreadsheetApp.getActive().getSheetByName(PROJECTS.sheet);
ss.getDataRange().offset(1, 0).clearContent();
for (let project of testProjects)
addProject(project);
}
function testgetProjects() {
preSetupProjects_();
test('getProjects', function (t) {
let act = getProjects();
t.equal(act.length, testProjects.length, 'number is right')
for (let i = 0; i < act.length; i++) {
t.equal(act[i].data.name, testProjects[i].name, 'getProjects name' + i);
t.equal(act[i].data.key, testProjects[i].key, 'getProjects key' + i);
}
});
}
function testGetProjectKeys() {
preSetupProjects_();
test('testGetProjectKeys', function (t) {
let act = getProjectKeys();
t.equal(act.length, testProjects.length, 'length');
for (let i = 0; i < act.length; i++) {
t.equal(act[i], testProjects[i].key, 'key' + i);
}
});
}
function testIsProjectkey() {
preSetupProjects_();
test('isProjectkey', function (t) {
let isKey = isProjectkey(testProjects[0].key);
t.ok(isKey, 'isProjectkey')
});
test('isProjectkey', function (t) {
let isKey = isProjectkey("projX");
t.notOk(isKey, 'not isProjectkey')
});
}
function testGetGroup() {
preSetupStudents_();
test('getGroup', function (t) {
let group = getGroup(testStudents[0].email);
t.equal(group, testStudents[0].projectkey, 'getGroup first row')
});
test('getGroup', function (t) {
let group = getGroup("whos@citycollege.sheffield.eu");
t.equal(group, null, 'getGroup not existing')
});
}
function testGetStudents() {
preSetupStudents_();
test('getStudents', function (t) {
let act = getStudents(testStudents[0].projectkey);
t.equal(act[0].email, testStudents[0].email, 'getStudents 0')
t.equal(act[1].email, testStudents[2].email, 'getStudents 2')
});
}
function testGetStudent() {
preSetupStudents_();
test('getStudent', function (t) {
let act = getStudent(testStudents[2].email);
t.equal(act.data.email, testStudents[2].email, 'getStudent');
});
test('getStudent', function (t) {
let act = getStudent("some@gmail.com");
t.equal(act, null, 'getStudent null');
});
}
function testCalculateGrade() {
test('calculateGrade', function (t) {
let grade = calculateGrade(80, 0.41, .5, .1)
t.equal(grade, 50.76, 'calculateGrade a');
grade = calculateGrade(70, 1.05, .7, .2)
t.equal(grade, 57.96, 'calculateGrade b');
});
}
function testFillWithUnderScore() {
test('fillWithUnderScore', function (t) {
let filled = fillWithUnderScore('name', 10);
t.equal(filled, 'name______', 'filled with 6 _');
filled = fillWithUnderScore('name', 4);
t.equal(filled, 'name', 'filled with 0 _');
filled = fillWithUnderScore('name', 3);
t.equal(filled, 'name', 'filled with 0 _');
});
}
function testState() {
test('state enum', function (t) {
t.equal(PaState.OPEN, 'OPEN', 'OPEN');
});
}
function testNotVerifiedStudents() {
preSetupProjects_();
preSetupStudents_();
let projs = getProjects();
let notVstuds = notVerifiedStudents();
test('allProjects', function (t) {
t.equal(projs.length, 3, '3 projects');
t.equal(projs[0].data.name, 'Project1');
t.equal(projs[1].data.name, 'Project2');
t.equal(projs[2].data.name, 'Project3');
});
test('notVerifiedStudents', function (t) {
t.equal(notVstuds.length, 2, '2 not verified');
t.equal(notVstuds[0].lname, 'Dran');
t.equal(notVstuds[1].lname, 'Tomail');
});
}
function testGetQuestions() {
let questions = getQuestions();
test('getQuestions', function (t) {
t.equal(questions.length, 12, '12 questions');
});
}
function testGetSettings() {
let settings = getSettings();
test('getSettings', function (t) {
t.equal(settings.weight, 0.6);
t.equal(settings.penalty, 0.2);
t.equal(settings.self, false);
t.equal(settings.reminder1, 24);
t.equal(settings.reminder2, 6);
t.equal(settings.timeunit, 'hour');
t.equal(settings.mailpa, true);
t.equal(settings.mailgrade, true);
t.equal(settings.domain, true);
});
}
/**
* e2e test
*/
function testOpenPA() {
preSetupProjects_();
preSetupStudents_();
preSetupPA();
deletePASheets();
let pas = getPAs();
openPA(pas[0]);
let updatedPa = getPA(pas[0].id);
test('peer assesment', function (t) {
t.equal(updatedPa.state, PaState.OPEN, 'is opened');
});
testGetPaProjects();
}
function testGetPaProjects() {
let paProjects = getPaProjects();
test('pa projects', function (t) {
t.equal(paProjects.length, 1, ' on pa project');
t.equal(paProjects[0].data.pakey, getPAs()[0].id, 'pa key is correct');
t.equal(paProjects[0].data.projectkey, testProjects[0].key, 'project key is correct');
t.ok(paProjects[0].data.formId, 'there is a form id');
})
}