Skip to content

Commit 6a2ae77

Browse files
committed
add !location tests
1 parent 141a7d5 commit 6a2ae77

File tree

4 files changed

+151
-3
lines changed

4 files changed

+151
-3
lines changed

test/mocks/FakeDiscord.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Discord {
2-
constructor(controller, config, log, mustache) {
2+
constructor(controller, config, log, mustache, translator) {
33
this.lastReact = ''
44
this.lastMessage = ''
55
this.config = config
@@ -8,6 +8,8 @@ class Discord {
88
this.mustache = mustache
99
this.emojiStrip = require('emoji-strip')
1010
this.query = controller
11+
this.translator = translator
12+
this.re = require('../../src/util/regex')(translator)
1113
}
1214

1315
setDefaults() {

test/mocks/discordMessageValidator.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const Ajv = require('ajv')
22

33
const { botMessageSchema, webhookMessageSchema } = require(`${__dirname}/discordSchema`)
44

5-
module.exports = (msg, type = 'bot') => {
5+
module.exports = (initMsg, type = 'bot') => {
6+
const msg = typeof initMsg === 'string' ? { content: initMsg } : initMsg
67
const ajv = new Ajv()
78
switch (type) {
89
case 'bot': {

test/testData/commandMessages.js

+143
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,149 @@ module.exports = (client) => {
3131
name: 'Incorrect Channel',
3232
}
3333
}
34+
},
35+
location: {
36+
humans: [{
37+
id: '123456789',
38+
type: 'webhook',
39+
name: 'registeredwebhook',
40+
enabled: 1,
41+
area: '[]',
42+
latitude: 0,
43+
longitude: 0,
44+
fails: 0,
45+
last_checked: new Date().toUTCString(),
46+
},
47+
{
48+
id: '222',
49+
type: 'discord:user',
50+
name: 'happyAuthorsUsername',
51+
enabled: 1,
52+
area: '[]',
53+
latitude: 0,
54+
longitude: 0,
55+
fails: 0,
56+
last_checked: new Date().toUTCString(),
57+
},
58+
{
59+
id: '333',
60+
type: 'discord:channel',
61+
name: 'testingChannel',
62+
enabled: 1,
63+
area: '[]',
64+
latitude: 0,
65+
longitude: 0,
66+
fails: 0,
67+
last_checked: new Date().toUTCString(),
68+
}],
69+
happy: {
70+
reply: (msg) => client.setMessage(msg),
71+
react: (e) => client.setReact(e),
72+
author: {
73+
tag: 'registeredUserInTallinn',
74+
username: 'happyAuthorsUsername',
75+
id: '222',
76+
send: (content) => {
77+
client.setMessage(content)
78+
},
79+
},
80+
channel: {
81+
id: 'UsersDMChannel',
82+
name: 'channelName',
83+
type: 'dm',
84+
},
85+
content: '.location tallinn',
86+
},
87+
happyAdmin: {
88+
reply: (msg) => client.setMessage(msg),
89+
react: (e) => client.setReact(e),
90+
author: {
91+
tag: 'AdminRegistersChannelLocation',
92+
username: 'happyAuthorsUsername',
93+
id: '222742859059560458',
94+
send: (content) => {
95+
client.setMessage(content)
96+
},
97+
},
98+
channel: {
99+
id: '333',
100+
name: 'adminSetLocationInThisChannel',
101+
type: 'text',
102+
},
103+
content: '.location tallinn',
104+
},
105+
sadAdmin: {
106+
reply: (msg) => client.setMessage(msg),
107+
react: (e) => client.setReact(e),
108+
author: {
109+
tag: 'AdminRegistersChannelLocation',
110+
username: 'happyAuthorsUsername',
111+
id: '222742859059560458',
112+
send: (content) => {
113+
client.setMessage(content)
114+
},
115+
},
116+
channel: {
117+
id: '3333',
118+
name: 'channelUnregistered',
119+
type: 'text',
120+
},
121+
content: '.location tallinn',
122+
},
123+
happyAdminWebhook: {
124+
reply: (msg) => client.setMessage(msg),
125+
react: (e) => client.setReact(e),
126+
author: {
127+
tag: 'registeredUserInTallinn',
128+
username: 'happyAuthorsUsername',
129+
id: '222742859059560458',
130+
send: (content) => {
131+
client.setMessage(content)
132+
},
133+
},
134+
channel: {
135+
id: '533927791096233984',
136+
name: 'channelName',
137+
type: 'dm',
138+
},
139+
content: '.location nameregisteredwebhook tallinn',
140+
},
141+
sadAdminWebhook: {
142+
reply: (msg) => client.setMessage(msg),
143+
react: (e) => client.setReact(e),
144+
author: {
145+
tag: 'registeredUserInTallinn',
146+
username: 'happyAuthorsUsername',
147+
id: '222742859059560458',
148+
send: (content) => {
149+
client.setMessage(content)
150+
},
151+
},
152+
channel: {
153+
id: '533927791096233984',
154+
name: 'channelName',
155+
type: 'dm',
156+
},
157+
content: '.location nameregisteredwebhookthatdoesntexist tallinn',
158+
},
159+
sad: {
160+
reply: (msg) => client.setMessage(msg),
161+
react: (e) => client.setReact(e),
162+
author: {
163+
tag: 'registeredUserInTallinn',
164+
username: 'happyAuthorsUsername',
165+
id: '15867',
166+
send: (content) => {
167+
client.setMessage(content)
168+
},
169+
},
170+
channel: {
171+
id: '533927791096233984',
172+
name: 'channelName',
173+
type: 'dm',
174+
},
175+
content: '.location tallinn',
176+
},
34177
}
35178
}
36179
}

test/tests/sqlite/commands/poracle.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const discordMessaveValidator = require('../../../mocks/discordMessageValidator'
66
const mustache = require('./../../../../src/lib/handlebars')()
77
const { getKnex } = require('./../../../../src/lib/configFetcher')
88
const Controller = require('./../../../../src/controllers/controller')
9+
const Translator = require('../../../../src/util/translate')
910

11+
const translator = new Translator(config.general.locale)
1012
const knex = getKnex(
1113
{
1214
database: {
@@ -17,7 +19,7 @@ const knex = getKnex(
1719
const controller = new Controller(knex, config)
1820
const poracle = require('../../../../src/lib/discord/commando/commands/poracle')
1921

20-
const client = new Discord(controller, config, log, mustache)
22+
const client = new Discord(controller, config, log, mustache, translator)
2123

2224
const testMessages = require('../../../testData/commandMessages')(client)
2325

0 commit comments

Comments
 (0)