lol-api-client
Version:
A Node client for interfacing with the League of Legends API
49 lines (41 loc) • 1.21 kB
JavaScript
const Summoners = require('../lib/summoners')
require('dotenv').config({ silent: true })
const summoners = new Summoners(process.env['RIOT_API_KEY'], 'na')
const names = ['Dyrus', 'Voyboy']
// Store summoner ids for use in our getById tests
let id1
let id2
exports.getByName = function (test) {
summoners.getByName(names[0])
.then((summoner) => {
// Imagine this is just 'Object.values(summoner)[0].id'...
id1 = Object.keys(summoner).map((key) => summoner[key])[0].id
test.ok(summoner)
test.done()
})
}
exports.getByNames = function (test) {
summoners.getByName(names)
.then((data) => {
// Riot alphabetizes their responses, so this is still the first element
// we want to pull here
id2 = Object.keys(data).map((key) => data[key])[0].id
test.equal(Object.keys(data).length, 2)
test.done()
})
}
exports.getById = function (test) {
summoners.getById(id1)
.then((summoner) => {
test.equal(names[0], summoner[id1].name)
test.done()
})
}
exports.getByIds = function (test) {
summoners.getById([id1, id2])
.then((data) => {
test.equal(Object.keys(data).length, 2)
test.done()
})
}