-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassessments.gs
63 lines (56 loc) · 2.28 KB
/
assessments.gs
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
/**
* Sentiment
* A tool to collect formative feedback
* https://github.com/ashenm/sentiment
*
* Ashen Gunaratne
*
*/
/**
* @function assess
* @summary Sentiment unit tests
* @description Executes the unit tests for sentiment
*/
function assess () {
// GET requests
assertRoughlyEquals(debugGet({ parameter: { institute: 'debug' } }), { error: {} });
// POST requests
assertRoughlyEquals(debugPost({ postData: { contents: JSON.stringify({}) } }), { error: {} });
assertRoughlyEquals(debugPost({ postData: { contents: JSON.stringify({ course: 'debug' }) } }), { error: {} });
assertRoughlyEquals(debugPost({ postData: { contents: JSON.stringify({ course: 'debug', sentiment: 'debug' }) } }), { feedback: {} });
assertRoughlyEquals(debugPost({ postData: { contents: JSON.stringify({ course: 'debug', sentiment: 'debug', origin: 'example.com' }) } }), { feedback: {} });
assertRoughlyEquals(debugPost({ postData: { contents: JSON.stringify({ course: 'bedug', sentiment: 'debug' }) } }), { error: {} });
assertRoughlyEquals(debugPost({ postData: {} }), { error: {} });
assertRoughlyEquals(debugPost({}), { error: {} });
}
/**
* @function debugGet
* @summary Trigger GET request handler
* @param {Event} event - the Apps Script event parameter
* @description Triggers the WebApp HTTP GET request handler with the parameterised event object
*/
function debugGet (event) {
return JSON.parse(doGet(event).getContent());
}
/**
* @function debugPost
* @summary Trigger POST request handler
* @param {Event} event - the Apps Script event parameter
* @description Triggers the WebApp HTTP POST request handler with the parameterised event object
*/
function debugPost (event) {
return JSON.parse(doPost(event).getContent());
}
/**
* @function assertRoughlyEquals
* @summary Compare two objects approximately
* @param {Object} collect - the received object
* @param {Object} conjecture - the expected object
* @description Logs the collect and the conjecture in the event of being approximately different
*/
function assertRoughlyEquals (collect, conjecture, callback) {
if (!Object.keys(conjecture).every(function (key, index, keys) {
return collect.hasOwnProperty(key);
})) Logger.log('expected %s got %s', JSON.stringify(conjecture), JSON.stringify(collect));
}