Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
fixes a bug that search print nothing, all _retail_ tests passed
Browse files Browse the repository at this point in the history
  • Loading branch information
antiwinter committed Aug 22, 2019
1 parent 5f1c952 commit 0824f6d
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 102 deletions.
9 changes: 7 additions & 2 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ let core = {

api.search(api.parseName(text), info => {
if (!info) {
log('not found')
log('\nNothing is found\n')
if (done) done(info)
return
}

Expand Down Expand Up @@ -316,7 +317,11 @@ let core = {
ad = api.parseName(ad)
api.info(ad, info => {
log('\n' + cl.h(ad.key) + '\n')
if (!info) return log('not available\n')
if (!info) {
log('Not available\n')
if (done) done()
return
}

let kv = (k, v) => {
// log('adding', k, v)
Expand Down
33 changes: 17 additions & 16 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,28 @@ let src = {
search(ad, done) {
if (!src.$valid(ad)) return done()

async.eachOfLimit(src.$api, 1, (api, source, cb) => {
if (!api.search) return cb()
if (ad.source && source !== ad.source) return cb()
async.eachOfLimit(
src.$api,
1,
(api, source, cb) => {
if (!api.search) return cb()
if (ad.source && source !== ad.source) return cb()

// log('searching', source)
let res = null
// log('searching', source)
api.search(
ad.key,
data => {
// log('searching', source)
let res = null
// log('searching', source)
api.search(ad.key, data => {
if (data && data.length) {
res = { source, data }
done(res)
cb(false)
}
},
() => {
done()
}
)
})
} else cb()
})
},
() => {
done()
}
)
},

summary(done) {
Expand Down
231 changes: 147 additions & 84 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import ava from 'ava'
import fs from 'fs'
import g from 'got'
import ext from 'file-type'
import vau from 'valid-url'
import mk from 'mkdirp'
import rm from 'rimraf'
Expand All @@ -10,85 +8,13 @@ import _ from 'underscore'

import cfg from './lib/config'
import core from './core'
import api from './source'
import ads from './lib/wowaads'

const log = console.log

function checkZip(link, done) {
try {
let s = g
.stream(link, {
headers: {
'user-agent': require('ua-string')
}
})
.on('readable', () => {
try {
let chunk = s.read(ext.minimumBytes)
// if (typeof chunk === 'object') return
let ex = ext(chunk)
// log('got', ex, 'from', link)
s.destroy()

done(ex)
} catch (err) {
// log('inner', err)
// done()
}
})
.on('error', err => {
done(err)
})
} catch (err) {
done(err)
}
}

function testInfo(key, unzip) {
ava.cb('info::' + key, t => {
api.info(api.parseName(key), info => {
// log('gg', info)
t.assert(info.name.match(/deadly/i))
// t.is(info.owner, 'MysticalOS')
t.assert(info.update > 1561424000)
// t.assert(info.download > 100)
t.assert(info.version.length > 0)

info.version.forEach(x => {
// t.assert(x.game.match(/^[0-9\.]+$/))
t.assert(x.link.length > 10)
t.assert(x.name.length > 1)
})

if (unzip)
checkZip(info.version[0].link, res => {
t.assert(res && res.mime === 'application/zip')
t.end()
})
else t.end()
})
})
}

function testSearch(key) {
ava.cb('search::' + key, t => {
api.search(api.parseName(key), res => {
t.assert(res.source)
t.assert(res.data.length > 0)

res.data.forEach(x => {
t.assert(typeof x.name === 'string' && x.name.length > 1)
t.assert(typeof x.key === 'string' && x.key.length > 1)
t.assert(typeof x.download === 'number' && x.download > 1)
t.assert(typeof x.update === 'number' && x.update > 1)
// t.assert(typeof x.desc === 'string' && x.desc.length > 1)
t.assert(vau.isUri(x.page))
})

t.end()
})
})
let ccc = 1
function nme(x) {
return ccc++ + '-' + x
}

ava.serial.before.cb('path', t => {
Expand Down Expand Up @@ -121,12 +47,12 @@ ava.serial.before.cb('prepare', t => {
core.updateSummary(() => t.end())
})

ava.serial.cb('appetizer', t => {
ava.serial.cb(nme('appetizer'), t => {
t.end()
})

function commonTests(aa) {
ava.serial.cb('add addons', t => {
ava.serial.cb(nme('install'), t => {
core.add(aa.map(a => a[0]), res => {
let p = cfg.getPath('addon')
t.assert(res.count === aa.length)
Expand All @@ -143,6 +69,137 @@ function commonTests(aa) {
t.end()
})
})

// ava.serial.cb(nme('update-none'), t => {
// core.update(res => {
// let p = cfg.getPath('addon')
// t.assert(res.count === 0)
// t.assert(res.update === 1)
// t.assert(res.ud === 0)

// aa.forEach(a => {
// t.assert(_.find(fs.readdirSync(p), d => d.match(a[1])))
// })

// ads.load()

// t.assert(_.keys(ads.data).length === aa.length)
// t.assert(!_.find(ads.data, d => !d.sub.length))
// t.end()
// })
// })

// ava.serial.cb(nme('update-1'), t => {
// ads.data['classicon'].update = 0

// core.update(res => {
// let p = cfg.getPath('addon')
// t.assert(res.count === 1)
// t.assert(res.update === 1)
// t.assert(res.ud === 1)

// aa.forEach(a => {
// t.assert(_.find(fs.readdirSync(p), d => d.match(a[1])))
// })

// ads.load()

// t.assert(ads.data['classicon'].update > 0)
// t.assert(_.keys(ads.data).length === aa.length)
// t.assert(!_.find(ads.data, d => !d.sub.length))
// t.end()
// })
// })

ava.serial.cb(nme('rm-1'), t => {
core.rm('classicon', res => {
let p = cfg.getPath('addon')

t.assert(!_.find(fs.readdirSync(p), d => d.match(/^Class/)))

ads.load()

t.assert(!ads.data['classicon'])
t.assert(_.keys(ads.data).length === aa.length - 1)
t.end()
})
})

ava.serial.cb(nme('search-none'), t => {
core.search('abcdef', info => {
t.assert(!info)
t.end()
})
})

ava.serial.cb(nme('search-curse'), t => {
core.search('dbm', info => {
t.assert(info.data.length > 0)
let v = info.data[0]

// log('gg', info)
t.assert(v.name.match(/Deadly Boss Mods/))
t.assert(v.key.match(/deadly-boss-mods/))

t.assert(vau.isUri(v.page))
t.assert(v.download > 200000000)
t.assert(v.update > 1561424000)

t.end()
})
})

ava.serial.cb(nme('search-mmoui'), t => {
core.search('mmoui:dbm', info => {
t.assert(info.data.length > 0)
let v = info.data[0]

// log('gg', info)
t.assert(v.name.match(/Deadly Boss Mods/))
t.assert(v.key.match(/8814-DeadlyBossMods/))

t.assert(vau.isUri(v.page))
t.assert(v.download > 2339130)
t.assert(v.update > 1561424000)

t.end()
})
})

ava.serial.cb(nme('ls'), t => {
let ls = core.ls()

// t.assert(ls.search(cfg.getMode()) > 0)
t.assert(ls.search('sellableitemdrops') > 0)
t.assert(ls.search('classicon') < 0)

t.end()
})

ava.serial.cb(nme('info-none'), t => {
core.info('abcdef', res => {
t.assert(!res)
t.end()
})
})

ava.serial.cb(nme('info-curse'), t => {
core.info('deadly-boss-mods', res => {
t.assert(res.match(/Deadly Boss Mods/))
t.assert(res.match(/MysticalOS/))
t.assert(res.match(/curse/))
t.assert(res.search(cfg.getGameVersion()) > 0)
t.end()
})
})

ava.serial.cb(nme('info-mmoui'), t => {
core.info('8814-xx', res => {
t.assert(res.match(/Deadly Boss Mods/))
t.assert(res.match(/mmoui/))
t.end()
})
})
}

commonTests([
Expand All @@ -152,8 +209,14 @@ commonTests([
['sellableitemdrops', /^Sella/]
])

// testInfo('curse:deadly-boss-mods', 1)
// testInfo('wowinterface:8814-DeadlyBossMods', fetchMMOUI)
// testInfo('deadlybossmods/deadlybossmods', 1)
// testSearch('curse:deadly')
// testSearch('wowinterface:deadly')
ava.serial.cb(nme('switch-to-classic'), t => {
core.switch()
t.end()
})

// commonTests([
// // ['deadlybossmods/deadlybossmods', /^DBM/],
// ['classicon', /^Class/],
// // ['mmoui:11190-Bartender4', /^Bart/],
// ['sellableitemdrops', /^Sella/]
// ])

0 comments on commit 0824f6d

Please sign in to comment.