-
Notifications
You must be signed in to change notification settings - Fork 2
/
buy_coffee.html
62 lines (58 loc) · 1.97 KB
/
buy_coffee.html
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
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.4.js"></script>
<script src="../hateoas-client.js"></script>
</head>
<body>
Please see your browsers console.log for output!
</body>
<script>
var assertEquals = function(a, b, message) {
if(a === b) {
console.log('[OK]', a, '===', b);
} else {
console.error('[ ]', a, '!==', b, message || '');
}
}
console.log('Testing functionality ...');
/*
* Working api usage, with filter-object
*/
var a = new HttpAgent('api.json');
a.navigate(['coffee', {
'name' : 'Small'
}, "buy"]);
a.post(function(response) {
assertEquals(response.isOk(), true, 'It was not possible to navigate!');
assertEquals(response.getValue().status, 'pending', 'Cannot find status after navigation');
});
/*
* Working api usage, without anything
*/
var a = new HttpAgent('api.json');
a.navigate(['coffee']);
a.get(function(response) {
assertEquals(response.getValue()[0].name, 'Small', 'Cannot find name of first coffee');
});
/*
* Working api usage, with filter-function
*/
var a = new HttpAgent('api.json');
a.navigate(['coffee',
function(value) {
return value.name === 'Small';
}, "buy"]);
a.post(function(response) {
assertEquals(response.getValue().status, 'pending', 'Cannot find status after navigation');
});
/*
* Broken api usage, because "invalid_link" cannot be found!
*/
var a = new HttpAgent('api.json');
a.navigate(['coffee', "invalid_link", "buy"]);
a.post(function(response) {
assertEquals(response.isOk(), false, 'It was possible to navigate!');
});
</script>
</html>