|
|
@@ -1,13 +1,28 @@
|
|
1
|
1
|
'use strict'
|
|
2
|
2
|
|
|
3
|
3
|
const test = require('ava')
|
|
4
|
|
-const { stub } = require('sinon')
|
|
|
4
|
+const { stub, mock } = require('sinon')
|
|
5
|
5
|
const Hapi = require('@hapi/hapi')
|
|
6
|
6
|
|
|
7
|
7
|
const plugin = require('../lib/plugins/profile')
|
|
8
|
8
|
|
|
9
|
9
|
const MatchQueue = require('../lib/models/matchqueue')
|
|
10
|
|
-
|
|
|
10
|
+/**
|
|
|
11
|
+ * Route parameters
|
|
|
12
|
+ */
|
|
|
13
|
+const params = {
|
|
|
14
|
+ profile_id: 1,
|
|
|
15
|
+ target_id: 2,
|
|
|
16
|
+ reinsert: true,
|
|
|
17
|
+ include_profile: false,
|
|
|
18
|
+}
|
|
|
19
|
+const mockReturn = {
|
|
|
20
|
+ queue: [
|
|
|
21
|
+ { mocked_profile_id: 1, target_id: 2, is_deleted: false },
|
|
|
22
|
+ { mocked_profile_id: 2, target_id: 3, is_deleted: false },
|
|
|
23
|
+ { mocked_profile_id: 3, target_id: 1, is_deleted: false },
|
|
|
24
|
+ ],
|
|
|
25
|
+}
|
|
11
|
26
|
test('path / should return ok on GET', async t => {
|
|
12
|
27
|
/**
|
|
13
|
28
|
* Create a new server and register services,
|
|
|
@@ -18,17 +33,17 @@ test('path / should return ok on GET', async t => {
|
|
18
|
33
|
* Schwifty at runtime.
|
|
19
|
34
|
*/
|
|
20
|
35
|
const server = Hapi.server()
|
|
|
36
|
+ /**
|
|
|
37
|
+ * Overload so we don't register any models
|
|
|
38
|
+ * using the plugin call (see plugins/profile.js)
|
|
|
39
|
+ * and Manually load the model we need for the test
|
|
|
40
|
+ */
|
|
21
|
41
|
server.registerModel = () => {}
|
|
22
|
42
|
server.models = () => ({ MatchQueue })
|
|
23
|
|
- await plugin.register(server)
|
|
24
|
|
-
|
|
25
|
43
|
/**
|
|
26
|
|
- * Route parameters
|
|
|
44
|
+ * Register Routes and Services as usual
|
|
27
|
45
|
*/
|
|
28
|
|
- const profile_id = 1
|
|
29
|
|
- const target_id = 2
|
|
30
|
|
- const reinsert = true
|
|
31
|
|
-
|
|
|
46
|
+ await plugin.register(server)
|
|
32
|
47
|
/**
|
|
33
|
48
|
* Replace Objection model methods with our own custom functions
|
|
34
|
49
|
* !: Kinda janky - might be better to temp knex sqlite instance
|
|
|
@@ -43,19 +58,13 @@ test('path / should return ok on GET', async t => {
|
|
43
|
58
|
}),
|
|
44
|
59
|
}),
|
|
45
|
60
|
insert: queueRecord => {
|
|
46
|
|
- t.is(queueRecord.profile_id, profile_id)
|
|
47
|
|
- t.is(queueRecord.target_id, target_id)
|
|
48
|
|
- t.is(queueRecord.is_deleted, !reinsert)
|
|
|
61
|
+ t.is(queueRecord.profile_id, params.profile_id)
|
|
|
62
|
+ t.is(queueRecord.target_id, params.target_id)
|
|
|
63
|
+ t.is(queueRecord.is_deleted, !params.reinsert)
|
|
49
|
64
|
},
|
|
50
|
65
|
// Mocked for getQueue()
|
|
51
|
66
|
where: () => ({
|
|
52
|
|
- andWhere: (cmd, val) => {
|
|
53
|
|
- return [
|
|
54
|
|
- { mocked_profile_id: 1, is_deleted: val },
|
|
55
|
|
- { mocked_profile_id: 2, is_deleted: val },
|
|
56
|
|
- { mocked_profile_id: 3, is_deleted: val },
|
|
57
|
|
- ]
|
|
58
|
|
- },
|
|
|
67
|
+ andWhere: (cmd, val) => mockReturn.queue,
|
|
59
|
68
|
}),
|
|
60
|
69
|
})
|
|
61
|
70
|
|
|
|
@@ -64,13 +73,12 @@ test('path / should return ok on GET', async t => {
|
|
64
|
73
|
*/
|
|
65
|
74
|
const { payload } = await server.inject({
|
|
66
|
75
|
method: 'PATCH',
|
|
67
|
|
- url: `/${profile_id}/queue/${target_id}/delete?reinsert=${reinsert}`,
|
|
|
76
|
+ url: `/${params.profile_id}/queue/${params.target_id}/delete?include_profile=${params.include_profile}&reinsert=${params.reinsert}`,
|
|
68
|
77
|
})
|
|
69
|
78
|
const res = JSON.parse(payload)
|
|
70
|
|
-
|
|
71
|
|
- t.deepEqual(res, [
|
|
72
|
|
- { mocked_profile_id: 1, is_deleted: false },
|
|
73
|
|
- { mocked_profile_id: 2, is_deleted: false },
|
|
74
|
|
- { mocked_profile_id: 3, is_deleted: false },
|
|
75
|
|
- ])
|
|
|
79
|
+ t.deepEqual(res.ok, true)
|
|
|
80
|
+ t.deepEqual(
|
|
|
81
|
+ res.data,
|
|
|
82
|
+ mockReturn.queue.map(entry => entry.target_id),
|
|
|
83
|
+ )
|
|
76
|
84
|
})
|