1 | import ava from 'ava'
|
2 | import fs from 'fs'
|
3 | import vau from 'valid-url'
|
4 | import mk from 'mkdirp'
|
5 | import rm from 'rimraf'
|
6 | import path from 'path'
|
7 | import _ from 'underscore'
|
8 |
|
9 | import cfg from './lib/config'
|
10 | import core from './core'
|
11 | import ads from './lib/wowaads'
|
12 | import api from './source'
|
13 |
|
14 | const log = console.log
|
15 |
|
16 | let ccc = 1
|
17 | function nme(x) {
|
18 | return ccc++ + '-' + x
|
19 | }
|
20 |
|
21 | ava.serial.before.cb('path', t => {
|
22 | let tmpdir = cfg.getPath('tmp')
|
23 |
|
24 |
|
25 | rm(tmpdir, err => {
|
26 | t.assert(!err)
|
27 | mk(path.join(tmpdir, '.test', '_retail_', 'Interface', 'Addons'), err => {
|
28 | t.assert(!err)
|
29 | mk(path.join(tmpdir, '.test', '_retail_', 'WTF'), err => {
|
30 | t.assert(!err)
|
31 | mk(path.join(tmpdir, '.test', '_classic_', 'WTF'), err => {
|
32 | t.assert(!err)
|
33 | mk(
|
34 | path.join(tmpdir, '.test', '_classic_', 'Interface', 'Addons'),
|
35 | err => {
|
36 | t.assert(!err)
|
37 | ads.load()
|
38 | t.end()
|
39 | }
|
40 | )
|
41 | })
|
42 | })
|
43 | })
|
44 | })
|
45 | })
|
46 |
|
47 | ava.serial.cb(nme('appetizer'), t => {
|
48 | t.end()
|
49 | })
|
50 |
|
51 | function commonTests(aa) {
|
52 | ava.serial.cb(nme('install'), t => {
|
53 | core.add(aa.map(a => a[0]), res => {
|
54 | let p = cfg.getPath('addon')
|
55 | t.assert(res.count === aa.length)
|
56 | t.assert(res.update === 0)
|
57 |
|
58 | aa.forEach(a => {
|
59 | t.assert(_.find(fs.readdirSync(p), d => d.match(a[1])))
|
60 | })
|
61 |
|
62 | ads.load()
|
63 |
|
64 | t.assert(_.keys(ads.data).length === aa.length)
|
65 | t.assert(!_.find(ads.data, d => !d.sub.length))
|
66 | t.end()
|
67 | })
|
68 | })
|
69 |
|
70 | ava.serial.cb(nme('update-none'), t => {
|
71 | core.update(null, {}, res => {
|
72 | let p = cfg.getPath('addon')
|
73 | t.assert(res.count === 0)
|
74 | t.assert(res.update === 1)
|
75 | t.assert(res.ud === 0)
|
76 |
|
77 | aa.forEach(a => {
|
78 | t.assert(_.find(fs.readdirSync(p), d => d.match(a[1])))
|
79 | })
|
80 |
|
81 | ads.load()
|
82 |
|
83 | t.assert(_.keys(ads.data).length === aa.length)
|
84 | t.assert(!_.find(ads.data, d => !d.sub.length))
|
85 | t.end()
|
86 | })
|
87 | })
|
88 |
|
89 | ava.serial.cb(nme('update-1'), t => {
|
90 | ads.data['classicon'].update = 0
|
91 |
|
92 | core.update(null, {}, res => {
|
93 | let p = cfg.getPath('addon')
|
94 | t.assert(res.count === 1)
|
95 | t.assert(res.update === 1)
|
96 | t.assert(res.ud === 1)
|
97 |
|
98 | aa.forEach(a => {
|
99 | t.assert(_.find(fs.readdirSync(p), d => d.match(a[1])))
|
100 | })
|
101 |
|
102 | ads.load()
|
103 |
|
104 | t.assert(ads.data['classicon'].update > 0)
|
105 | t.assert(_.keys(ads.data).length === aa.length)
|
106 | t.assert(!_.find(ads.data, d => !d.sub.length))
|
107 | t.end()
|
108 | })
|
109 | })
|
110 |
|
111 | ava.serial.cb(nme('rm-1'), t => {
|
112 | core.rm(['classicon'], res => {
|
113 | let p = cfg.getPath('addon')
|
114 |
|
115 | t.assert(!_.find(fs.readdirSync(p), d => d.match(/^Class/)))
|
116 |
|
117 | ads.load()
|
118 |
|
119 | t.assert(!ads.data['classicon'])
|
120 | t.assert(_.keys(ads.data).length === aa.length - 1)
|
121 |
|
122 | core.add(['classicon'], () => {
|
123 | t.end()
|
124 | })
|
125 | })
|
126 | })
|
127 |
|
128 | ava.serial.cb(nme('search-none'), t => {
|
129 | core.search('abcdef', info => {
|
130 | t.assert(!info)
|
131 | t.end()
|
132 | })
|
133 | })
|
134 |
|
135 | ava.serial.cb(nme('search-curse'), t => {
|
136 | core.search('dbm', info => {
|
137 | t.assert(info.data.length > 0)
|
138 | let v = info.data[0]
|
139 |
|
140 |
|
141 | t.assert(v.name.match(/Deadly Boss Mods/))
|
142 | t.assert(v.key.match(/deadly-boss-mods/))
|
143 |
|
144 | t.assert(vau.isUri(v.page))
|
145 | t.assert(v.download > 200000000)
|
146 | t.assert(v.update > 1561424000)
|
147 |
|
148 | t.end()
|
149 | })
|
150 | })
|
151 |
|
152 | ava.serial.cb(nme('search-mmoui'), t => {
|
153 | core.search('mmoui:dbm', info => {
|
154 | t.assert(info.data.length > 0)
|
155 | let v = info.data[0]
|
156 |
|
157 |
|
158 | t.assert(v.name.match(/Deadly Boss Mods/))
|
159 |
|
160 | if (cfg.getMode() === '_classic_') t.assert(v.key.match(/24921-/))
|
161 | else t.assert(v.key.match(/8814-DeadlyBossMods/))
|
162 |
|
163 | t.assert(vau.isUri(v.page))
|
164 | t.assert(v.download > 100)
|
165 | t.assert(v.update > 1561424000)
|
166 |
|
167 | t.end()
|
168 | })
|
169 | })
|
170 |
|
171 | ava.serial.cb(nme('search-tukui'), t => {
|
172 | core.search('tukui:elv', info => {
|
173 | t.assert(info.data.length > 0)
|
174 | let v = info.data[0]
|
175 |
|
176 |
|
177 | t.assert(v.name.match(/ElvUI/))
|
178 |
|
179 | if (cfg.getMode() === '_classic_') t.assert(v.key.match(/2-/))
|
180 | else t.assert(v.key.match(/0-/))
|
181 |
|
182 | t.assert(vau.isUri(v.page))
|
183 | t.assert(v.download > 100)
|
184 | t.assert(v.update > 1561424000)
|
185 |
|
186 | t.end()
|
187 | })
|
188 | })
|
189 |
|
190 | ava.serial.cb(nme('ls'), t => {
|
191 | let ls = core.ls({ long: 1 })
|
192 |
|
193 |
|
194 | t.assert(ls.search('sellableitemdrops') > 0)
|
195 | t.assert(ls.search('classicon') > 0)
|
196 |
|
197 | ls = core.ls({})
|
198 |
|
199 |
|
200 | t.assert(ls.search('sellableitemdrops') > 0)
|
201 | t.assert(ls.search('classicon') > 0)
|
202 |
|
203 | t.end()
|
204 | })
|
205 |
|
206 | ava.serial.cb(nme('info-none'), t => {
|
207 | core.info('abcdef', res => {
|
208 | t.assert(!res)
|
209 | t.end()
|
210 | })
|
211 | })
|
212 |
|
213 | ava.serial.cb(nme('info-curse'), t => {
|
214 | core.info('deadly-boss-mods', res => {
|
215 | t.assert(res.match(/Deadly Boss Mods/))
|
216 | t.assert(res.match(/MysticalOS/))
|
217 | t.assert(res.match(/curse/))
|
218 |
|
219 | t.end()
|
220 | })
|
221 | })
|
222 |
|
223 | ava.serial.cb(nme('info-mmoui'), t => {
|
224 | core.info('8814-xx', res => {
|
225 | t.assert(res.match(/Deadly Boss Mods/))
|
226 | t.assert(res.match(/mmoui/))
|
227 | t.end()
|
228 | })
|
229 | })
|
230 |
|
231 | ava.serial.cb(nme('import'), t => {
|
232 | ads.data = {}
|
233 | ads.save()
|
234 |
|
235 | core.pickup(res => {
|
236 | ads.load()
|
237 |
|
238 | t.assert(_.keys(ads.data).length === _.filter(aa, a => a[2]).length)
|
239 | aa.forEach(a => {
|
240 | if (a[2])
|
241 | t.assert(_.find(_.keys(ads.data), k => k.split('-')[0] === a[2]))
|
242 | })
|
243 |
|
244 | t.end()
|
245 | })
|
246 | })
|
247 | }
|
248 |
|
249 | commonTests([
|
250 | ['deadlybossmods/deadlybossmods', /^DBM/, '8814'],
|
251 | ['classicon', /^Class/, '18267'],
|
252 | ['mmoui:11190-Bartender4', /^Bart/, '11190'],
|
253 | ['tukui:46-ElvUIDatatextBars2', /^ElvUI/],
|
254 | ['sellableitemdrops', /^Sella/]
|
255 | ])
|
256 |
|
257 | ava.serial.cb(nme('info-tukui-retail'), t => {
|
258 | core.info('0-elvui', res => {
|
259 | t.assert(res.match(/[0-9]+\/[0-9]+\/[0-9]+/))
|
260 | t.assert(res.match(/[0-9]+\.[0-9]+/g).length === 3)
|
261 | t.assert(res.match(/\.zip/))
|
262 | t.end()
|
263 | })
|
264 | })
|
265 |
|
266 | ava.serial.cb(nme('switch-to-classic'), t => {
|
267 | core.switch()
|
268 | t.end()
|
269 | })
|
270 |
|
271 | commonTests([
|
272 | ['deadlybossmods/deadlybossmods', /^DBM/, '24921'],
|
273 | ['bigwigsmods/bigwigs/classic', /^BigWigs/],
|
274 | ['classicon', /^Class/],
|
275 | ['mmoui:11190-Bartender4', /^Bart/],
|
276 | ['tukui:6-RedtuzkUIClassic', /^ElvUI/],
|
277 | ['sellableitemdrops', /^Sella/]
|
278 | ])
|
279 |
|
280 | ava.serial.cb(nme('wowa update'), t => {
|
281 | core.checkUpdate(res => {
|
282 | t.assert(res.name === 'wowa')
|
283 |
|
284 | core.checkUpdate(res => {
|
285 | t.assert(res.name === 'wowa')
|
286 |
|
287 | t.end()
|
288 | })
|
289 | })
|
290 | })
|
291 |
|
292 | ava.serial.cb(nme('name parser'), t => {
|
293 | let names = {
|
294 | 'curse:molinari': { key: 'molinari', source: 'curse' },
|
295 | 'https://www.curseforge.com/wow/addons/molinari': {
|
296 | key: 'molinari',
|
297 | source: 'curse'
|
298 | },
|
299 | 'https://wow.curseforge.com/projects/molinari': {
|
300 | key: 'molinari',
|
301 | source: 'curse'
|
302 | },
|
303 | 'wowi:13188': { key: '13188', source: 'mmoui' },
|
304 | 'https://www.wowinterface.com/downloads/info13188-Molinari.html': {
|
305 | key: '13188-Molinari',
|
306 | source: 'mmoui'
|
307 | },
|
308 | 'deadly-boss-mods': { key: 'deadly-boss-mods', source: null },
|
309 | 'curse:deadly-boss-mods': { key: 'deadly-boss-mods', source: 'curse' },
|
310 | 'mmoui:8814-DeadlyBossMods': {
|
311 | key: '8814-DeadlyBossMods',
|
312 | source: 'mmoui'
|
313 | },
|
314 | '8814-DeadlyBossMods': { key: '8814-DeadlyBossMods', source: null },
|
315 | 'deadlybossmods/deadlybossmods': {
|
316 | key: 'deadlybossmods/deadlybossmods',
|
317 | source: 'github'
|
318 | },
|
319 | 'bigwigsmods/bigwigs/classic': {
|
320 | key: 'bigwigsmods/bigwigs/classic',
|
321 | source: 'github'
|
322 | },
|
323 | 'antiwinter/dlt': { key: 'antiwinter/dlt', source: 'github' },
|
324 | 'https://github.com/BigWigsMods/BigWigs/tree/master': {
|
325 | source: 'github',
|
326 | key: 'BigWigsMods/BigWigs/tree/master'
|
327 | },
|
328 | 'https://github.com/BigWigsMods/BigWigs/tree': {
|
329 | source: 'github',
|
330 | key: 'BigWigsMods/BigWigs/tree'
|
331 | },
|
332 | 'https://github.com/BigWigsMods/BigWigs': {
|
333 | source: 'github',
|
334 | key: 'BigWigsMods/BigWigs'
|
335 | },
|
336 | 'https://www.tukui.org/classic-addons.php?id=6': {
|
337 | source: 'tukui',
|
338 | key: '6'
|
339 | }
|
340 | }
|
341 |
|
342 | for (let k in names) {
|
343 | let d = api.parseName(k)
|
344 |
|
345 | let r = names[k]
|
346 |
|
347 | for (let k2 in r) {
|
348 | if (r[k2]) t.assert(r[k2] === d[k2])
|
349 | t.assert(!r[k2] === !d[k2])
|
350 | }
|
351 | }
|
352 |
|
353 | t.end()
|
354 | })
|