kindred-api
Advanced tools
Comparing version 2.0.37 to 2.0.38
{ | ||
"name": "kindred-api", | ||
"version": "2.0.37", | ||
"version": "2.0.38", | ||
"description": "Node.js League of Legends v3 API wrapper with built-in rate-limiting (enforced per region), caching (in-memory, Redis), and parameter checking.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,66 +14,49 @@ require('./core.specs.js') | ||
describe('Core Utils', function() { | ||
it('it throws on invalid region thru init', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const debug = true | ||
const garbageRegion = 'foo' | ||
describe('setRegion ', () => { | ||
describe('through init', () => { | ||
it('should throw on invalid region', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const debug = true | ||
const garbageRegion = 'foo' | ||
assert.throws(() => api.QuickStart(process.env.KEY, garbageRegion, true), Error) | ||
}) | ||
assert.throws(() => api.QuickStart(process.env.KEY, garbageRegion, true), Error) | ||
}) | ||
it('it does not throw on valid region thru init', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const debug = true | ||
const region = api.REGIONS.NORTH_AMERICA | ||
it('should not throw on valid region', () => { | ||
assert.doesNotThrow(() => init(), Error) | ||
}) | ||
}) | ||
assert.doesNotThrow(() => api.QuickStart(process.env.KEY, region, true), Error) | ||
}) | ||
describe('through manual set', () => { | ||
it('should throw on invalid region', () => { | ||
const garbageRegion = 'north_amurica' // jokez! | ||
assert.throws(() => init().setRegion(garbageRegion), Error) | ||
}) | ||
it('it throws on invalid region thru setRegion', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const { REGIONS } = api | ||
const debug = true | ||
it('should not throw on valid region', () => { | ||
const k = init() | ||
const nonGarbageRegion = require('../../dist/kindred-api.min').REGIONS.KOREA | ||
const garbageRegion = 'north_amurica' // jokez! | ||
const k = api.QuickStart(process.env.KEY, REGIONS.KOREA, true) | ||
assert.throws(() => k.setRegion(garbageRegion), Error) | ||
assert.doesNotThrow(() => k.setRegion(nonGarbageRegion), Error) | ||
}) | ||
}) | ||
}) | ||
it('it does not throw on valid region thru setRegion', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const { REGIONS } = api | ||
const debug = true | ||
describe('validName', () => { | ||
it('should throw on invalid name', () => { | ||
// name parameters -> valid name -> sanitize name -> throw | ||
const garbageName = 'foo%' | ||
assert.throws(() => init().Summoner.get(garbageName), Error) | ||
}) | ||
const nonGarbageRegion = REGIONS.KOREA | ||
it('should not throw on valid name 1', () => { | ||
// name parameters -> valid name -> sanitize name -> no throw | ||
assert.throws(() => init().Summoner.get('chauisthebest'), Error) | ||
}) | ||
const k = api.QuickStart(process.env.KEY, REGIONS.NORTH_AMERICA, true) | ||
assert.doesNotThrow(() => k.setRegion(nonGarbageRegion), Error) | ||
it('should not throw on valid name 2', () => { | ||
// name parameters -> valid name -> sanitize name -> no throw | ||
assert.throws(() => init().Summoner.get('chau.isthebest'), Error) | ||
}) | ||
}) | ||
it('it throws on invalid name', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const REGIONS = api.REGIONS | ||
const debug = true | ||
const k = api.QuickStart(process.env.KEY, debug) | ||
// name parameters -> valid name -> sanitize name -> throw | ||
assert.throws(() => k.Summoner.get('foo%'), Error) | ||
}) | ||
it('it throws on invalid name', () => { | ||
// name parameters -> valid name -> sanitize name -> throw | ||
const garbageName = 'foo%' | ||
assert.throws(() => init().Summoner.get(garbageName), Error) | ||
}) | ||
it('it does not throw on valid name 1', () => { | ||
// name parameters -> valid name -> sanitize name -> no throw | ||
assert.throws(() => init().Summoner.get('chauisthebest'), Error) | ||
}) | ||
it('it does not throw on valid name 2', () => { | ||
// name parameters -> valid name -> sanitize name -> no throw | ||
assert.throws(() => init().Summoner.get('chau.isthebest'), Error) | ||
}) | ||
}) |
@@ -16,71 +16,81 @@ var chai = require('chai') | ||
it('it should not init thru standard init w/o api key (0 args)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
describe('Standard Initialization', () => { | ||
it('should not init w/o api key', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const { REGIONS } = api | ||
const debug = true | ||
const { REGIONS } = api | ||
const debug = true | ||
assert.throws(() => new api.Kindred(), Error) | ||
}) | ||
assert.throws(() => new api.Kindred(), Error) | ||
assert.throws(() => new api.Kindred({ region: REGIONS.NORTH_AMERICA }), Error) | ||
assert.throws(() => new api.Kindred({ debug }), Error) | ||
assert.throws(() => new api.Kindred({ region: REGIONS.NORTH_AMERICA, debug }), Error) | ||
}) | ||
it('it should init thru standard init (3 args: key, region, debug)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
it('should init with key & region & debug (3 args)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const region = api.REGIONS.NORTH_AMERICA | ||
const debug = true | ||
const region = api.REGIONS.NORTH_AMERICA | ||
const debug = true | ||
const k = new api.Kindred({ | ||
key: process.env.KEY, region, debug | ||
const k = new api.Kindred({ | ||
key: process.env.KEY, region, debug | ||
}) | ||
expect(k).is.not.undefined | ||
}) | ||
expect(k).is.not.undefined | ||
}) | ||
it('should init with key (1 arg)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
it('it should init thru standard init (1 arg: key)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const k = new api.Kindred({ | ||
key: process.env.KEY | ||
}) | ||
const k = new api.Kindred({ | ||
key: process.env.KEY | ||
expect(k).is.not.undefined | ||
}) | ||
expect(k).is.not.undefined | ||
}) | ||
it('should init with key & debug (2 args)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
it('it should init thru standard init (2 args: key, debug)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const debug = true | ||
const debug = true | ||
const k = new api.Kindred({ | ||
key: process.env.KEY, debug | ||
}) | ||
const k = new api.Kindred({ | ||
key: process.env.KEY, debug | ||
expect(k).is.not.undefined | ||
}) | ||
expect(k).is.not.undefined | ||
}) | ||
it('it can init thru quickstart (3 args)', () => { | ||
expect(init()).is.not.undefined | ||
}) | ||
describe('QuickStart Initialization', () => { | ||
it('should init with key & region & debug (3 args)', () => { | ||
expect(init()).is.not.undefined | ||
}) | ||
it('it can init thru quickstart (2 args: key, region)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const { REGIONS } = api | ||
it('should init with key & region (2 args)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const { REGIONS } = api | ||
const k = api.QuickStart(process.env.KEY, REGIONS.NORTH_AMERICA) | ||
const k = api.QuickStart(process.env.KEY, REGIONS.NORTH_AMERICA) | ||
expect(k).is.not.undefined | ||
}) | ||
expect(k).is.not.undefined | ||
}) | ||
it('it can init thru quickstart (2 args: key, debug)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const { REGIONS } = api | ||
it('should init with key & debug (2 args)', () => { | ||
const api = require('../../dist/kindred-api.min') | ||
const { REGIONS } = api | ||
const k = api.QuickStart(process.env.KEY, true) | ||
const k = api.QuickStart(process.env.KEY, true) | ||
expect(k).is.not.undefined | ||
expect(k).is.not.undefined | ||
}) | ||
}) | ||
it('it returns a promise', () => { | ||
assert.instanceOf(init().Summoner.get({ id: 32932398 }), Promise, 'this is a promise') | ||
describe('Requests', () => { | ||
it('should return a promise', () => { | ||
assert.instanceOf(init().Summoner.get({ id: 32932398 }), Promise, 'this is a promise') | ||
}) | ||
}) | ||
}) |
@@ -14,17 +14,31 @@ require('../in-memory-cache.specs.js') | ||
describe('Masteries', function() { | ||
it('(object-param) get fails on empty', () => { | ||
assert.throws(() => init().Masteries.get(), Error) | ||
}) | ||
describe('get', () => { | ||
describe('object param', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Masteries.get(), Error) | ||
}) | ||
}) | ||
it('(standard-param) by.id fails on empty', () => { | ||
assert.throws(() => init().Masteries.by.id(), Error) | ||
}) | ||
describe('standard params', () => { | ||
describe('by', () => { | ||
describe('id', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Masteries.by.id(), Error) | ||
}) | ||
}) | ||
it('(standard-param) by.name fails on empty', () => { | ||
assert.throws(() => init().Masteries.by.name(), Error) | ||
}) | ||
describe('name', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Masteries.by.name(), Error) | ||
}) | ||
}) | ||
it('(standard-param) by.account fails on empty', () => { | ||
assert.throws(() => init().Masteries.by.account(), Error) | ||
describe('account', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Masteries.by.account(), Error) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -14,17 +14,31 @@ require('../in-memory-cache.specs.js') | ||
describe('Runes', function() { | ||
it('(object-param) get fails on empty', () => { | ||
assert.throws(() => init().Runes.get(), Error) | ||
}) | ||
describe('get', () => { | ||
describe('object param', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Runes.get(), Error) | ||
}) | ||
}) | ||
it('(standard-param) by.id fails on empty', () => { | ||
assert.throws(() => init().Runes.by.id(), Error) | ||
}) | ||
describe('standard params', () => { | ||
describe('by', () => { | ||
describe('id', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Runes.by.id(), Error) | ||
}) | ||
}) | ||
it('(standard-param) by.name fails on empty', () => { | ||
assert.throws(() => init().Runes.by.name(), Error) | ||
}) | ||
describe('name', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Runes.by.name(), Error) | ||
}) | ||
}) | ||
it('(standard-param) by.account fails on empty', () => { | ||
assert.throws(() => init().Runes.by.account(), Error) | ||
describe('account', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Runes.by.account(), Error) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -14,17 +14,31 @@ require('../in-memory-cache.specs.js') | ||
describe('Summoner', function() { | ||
it('(object-param) get fails on empty', () => { | ||
assert.throws(() => init().Summoner.get(), Error) | ||
}) | ||
describe('get', () => { | ||
describe('object param', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Summoner.get(), Error) | ||
}) | ||
}) | ||
it('(standard-param) by.id fails on empty', () => { | ||
assert.throws(() => init().Summoner.by.id(), Error) | ||
}) | ||
describe('standard params', () => { | ||
describe('by', () => { | ||
describe('id', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Summoner.by.id(), Error) | ||
}) | ||
}) | ||
it('(standard-param) by.name fails on empty', () => { | ||
assert.throws(() => init().Summoner.by.name(), Error) | ||
}) | ||
describe('name', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Summoner.by.name(), Error) | ||
}) | ||
}) | ||
it('(standard-param) by.account fails on empty', () => { | ||
assert.throws(() => init().Summoner.by.account(), Error) | ||
describe('account', () => { | ||
it('should fail on empty', () => { | ||
assert.throws(() => init().Summoner.by.account(), Error) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -14,46 +14,50 @@ require('./core-utils.specs.js') | ||
describe('In-memory (JS) Cache', function() { | ||
it('set/get data exists', () => { | ||
const k = init() | ||
describe('set/get', () => { | ||
it('should yield cached data', () => { | ||
const k = init() | ||
k.cache.set({ key: 'http://abc.com', ttl: 3 }, { foo: 'bar' }) | ||
k.cache.set({ key: 'http://abc.com', ttl: 3 }, { foo: 'bar' }) | ||
k.cache.get({ key: 'http://abc.com' }, (err, data) => { | ||
expect(err).is.null // errors return as null with my cbs | ||
expect(data).is.not.undefined | ||
k.cache.get({ key: 'http://abc.com' }, (err, data) => { | ||
expect(err).is.null // errors return as null with my cbs | ||
expect(data).is.not.undefined | ||
}) | ||
}) | ||
}) | ||
it('set/get data does not exist with nonexistent cache key', () => { | ||
const k = init() | ||
it('should not yield data with nonexistent cache key', () => { | ||
const k = init() | ||
k.cache.get({ key: 'http://nonexistent.com' }, (err, data) => { | ||
expect(err).is.not.undefined | ||
expect(data).is.undefined | ||
k.cache.get({ key: 'http://nonexistent.com' }, (err, data) => { | ||
expect(err).is.not.undefined | ||
expect(data).is.undefined | ||
}) | ||
}) | ||
}) | ||
it('set/get data does not exist with expired cache key', () => { | ||
// this is the same as being nonexistent, but I want | ||
// to simulate expired keys! | ||
const k = init() | ||
it('should not yield data with expired cache key', () => { | ||
// this is the same as being nonexistent, but I want | ||
// to simulate expired keys! | ||
const k = init() | ||
k.cache.set({ key: 'http://abc.com', ttl: 0 }, { foo: 'bar' }) | ||
k.cache.set({ key: 'http://abc.com', ttl: 0 }, { foo: 'bar' }) | ||
k.cache.get({ key: 'http://abc.com' }, (err, data) => { | ||
expect(err).is.not.undefined | ||
expect(data).is.undefined | ||
k.cache.get({ key: 'http://abc.com' }, (err, data) => { | ||
expect(err).is.not.undefined | ||
expect(data).is.undefined | ||
}) | ||
}) | ||
}) | ||
it('set time accurate', () => { | ||
const k = init() | ||
describe('set expiration time', () => { | ||
it('should be accurate', () => { | ||
const k = init() | ||
const ttl = 10 | ||
const convertToMilliseconds = 1000 | ||
const ttl = 10 | ||
const convertToMilliseconds = 1000 | ||
const d = Date.now() | ||
const exp = k.cache.setExp(d, ttl) | ||
const d = Date.now() | ||
const exp = k.cache.setExp(d, ttl) | ||
assert(exp - d === ttl * convertToMilliseconds, 'date + 10*1000 = exp') | ||
assert(exp - d === ttl * convertToMilliseconds, 'date + 10*1000 = exp') | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
406387
5500
11