From aba05133cfb7b41b0fab6bba0daf82af25af7bc8 Mon Sep 17 00:00:00 2001 From: Chau Date: Wed, 12 Jun 2019 11:45:54 -0700 Subject: [PATCH] feat (LeagueEntries): Add new LeagueEntries endpoint #68 #66 --- example.js | 7 ++ .../LeagueEndpoint/LeagueEntriesEndpointV4.js | 65 +++++++++++++++++ lib/Enums/method-names.js | 4 ++ lib/Kayn.js | 5 ++ .../LeagueEntriesEndpointV4.spec.js | 70 +++++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 lib/Endpoints/LeagueEndpoint/LeagueEntriesEndpointV4.js create mode 100644 test/unit/endpoints/LeagueEndpoint/LeagueEntriesEndpointV4.spec.js diff --git a/example.js b/example.js index eece89b6..a1434e24 100644 --- a/example.js +++ b/example.js @@ -36,7 +36,14 @@ const kayn = Kayn()({ import run from './examples/async.await/v4/get-last-10-ranked-matches-efficiently' const main = async () => { + /* console.log(await kayn.Summoner.by.name('Contractz')) + console.log( + await kayn.League.Entries.list('RANKED_SOLO_5x5', 'DIAMOND', 'I'), + ) + */ + const leagueId = 'c6fedb10-6e54-11e9-982e-c81f66cf2333' + console.log(await kayn.League.by.uuid(leagueId)) } main() diff --git a/lib/Endpoints/LeagueEndpoint/LeagueEntriesEndpointV4.js b/lib/Endpoints/LeagueEndpoint/LeagueEntriesEndpointV4.js new file mode 100644 index 00000000..db2312c9 --- /dev/null +++ b/lib/Endpoints/LeagueEndpoint/LeagueEntriesEndpointV4.js @@ -0,0 +1,65 @@ +import LeagueSuperclass from './LeagueSuperclass' +import Request from 'RequestClient/Request' +import METHOD_NAMES from 'Enums/method-names' + +class LeagueEntriesEndpointV4 extends LeagueSuperclass { + constructor(config, limiter) { + super() + + this.config = config + + this.by = { + summonerID: this.summonerID.bind(this), + } + + this.list = this.list.bind(this) + + this.limiter = limiter + } + + /** + * Get league entries in all queues for a given summoner ID. + * + * Implements GET `/lol/league/v4/entries/by-summoner/{encryptedSummonerId}`. + * + * @param {string} encryptedSummonerId - The encrypted id of the summoner. + */ + summonerID(summonerID) { + return new Request( + this.config, + this.serviceName, + `entries/by-summoner/${summonerID}`, + METHOD_NAMES.LEAGUE.GET_LEAGUE_ENTRIES_BY_SUMMONER_ID_V4, + 'GET', + this.limiter, + null, + false, + 4, + ) + } + + /** + * Get all the league entries. + * + * Implements GET `/lol/league/v4/entries/{queue}/{tier}/{division}`. + * + * @param {string} queue - The queue to search for. e.g. RANKED_SOLO_5x5 + * @param {string} tier - The tier to search for. e.g. DIAMOND + * @param {string} division - The division to search for. e.g. I + */ + list(queue, tier, division) { + return new Request( + this.config, + this.serviceName, + `entries/${queue}/${tier}/${division}`, + METHOD_NAMES.LEAGUE.GET_LEAGUE_ENTRIES_BY_QUEUE_TIER_DIVISION_V4, + 'GET', + this.limiter, + null, + false, + 4, + ) + } +} + +export default LeagueEntriesEndpointV4 diff --git a/lib/Enums/method-names.js b/lib/Enums/method-names.js index d4aac5a9..fd897557 100644 --- a/lib/Enums/method-names.js +++ b/lib/Enums/method-names.js @@ -59,6 +59,10 @@ const LEAGUE = { 'LEAGUE.GET_ALL_LEAGUE_POSITIONS_FOR_SUMMONER_V4', GET_ALL_POSITIONAL_LEAGUE_ENTRIES_V4: 'LEAGUE.GET_ALL_POSITIONAL_LEAGUE_ENTRIES_V4', + GET_LEAGUE_ENTRIES_BY_SUMMONER_ID_V4: + 'LEAGUE.GET_LEAGUE_ENTRIES_BY_SUMMONER_ID_V4', + GET_LEAGUE_ENTRIES_BY_QUEUE_TIER_DIVISION_V4: + 'LEAGUE.GET_LEAGUE_ENTRIES_BY_QUEUE_TIER_DIVISION_V4', } const LOL_STATUS = { diff --git a/lib/Kayn.js b/lib/Kayn.js index d8af8775..70023604 100644 --- a/lib/Kayn.js +++ b/lib/Kayn.js @@ -28,6 +28,7 @@ import CurrentGameEndpointV4 from './Endpoints/SpectatorEndpoint/CurrentGameEndp import FeaturedGamesEndpointV4 from './Endpoints/SpectatorEndpoint/FeaturedGamesEndpointV4' import GrandmasterEndpointV4 from './Endpoints/LeagueEndpoint/GrandmasterEndpointV4' import LeagueEndpointV4 from './Endpoints/LeagueEndpoint/LeagueEndpointV4' +import LeagueEntriesEndpointV4 from './Endpoints/LeagueEndpoint/LeagueEntriesEndpointV4' import LeaguePositionsEndpointV4 from './Endpoints/LeagueEndpoint/LeaguePositionsEndpointV4' import MasterEndpointV4 from './Endpoints/LeagueEndpoint/MasterEndpointV4' import MatchEndpointV4 from './Endpoints/MatchEndpoint/MatchEndpointV4' @@ -152,6 +153,10 @@ class Kayn { this.Grandmaster = this.GrandmasterV4 this.LeagueV4 = new LeagueEndpointV4(this.config, this.limiter) this.League = this.LeagueV4 + this.League.Entries = new LeagueEntriesEndpointV4( + this.config, + this.limiter, + ) this.LeaguePositionsV4 = new LeaguePositionsEndpointV4( this.config, this.limiter, diff --git a/test/unit/endpoints/LeagueEndpoint/LeagueEntriesEndpointV4.spec.js b/test/unit/endpoints/LeagueEndpoint/LeagueEntriesEndpointV4.spec.js new file mode 100644 index 00000000..a1dc5c62 --- /dev/null +++ b/test/unit/endpoints/LeagueEndpoint/LeagueEntriesEndpointV4.spec.js @@ -0,0 +1,70 @@ +import { expect, should, assert } from 'chai' + +import TestUtils from '../../../TestUtils' +const { kaynInstance, defaultConfig } = TestUtils + +const { kayn, REGIONS, METHOD_TYPES } = kaynInstance +import LeagueEntriesEndpointV4 from '../../../../lib/Endpoints/LeagueEndpoint/LeagueEntriesEndpointV4' +import mocks from '../../../mocks' + +describe('LeagueEntriesEndpointV4', function() { + this.timeout(0) + + beforeEach(function() { + this.LeagueEntries = new LeagueEntriesEndpointV4(defaultConfig) + }) + + describe('.by.summonerID', function() { + it('should have the correct payload #1', function() { + const { payload } = this.LeagueEntries.by.summonerID('abcdefgh') + expect(payload).to.deep.equal({ + method: 'GET', + serviceName: 'league', + endpoint: 'entries/by-summoner/abcdefgh', + query: [], + region: '', + isTournament: false, + version: 4, + }) + }) + + it('should have the correct method name', function() { + const { methodName } = this.LeagueEntries.by + .summonerID('abcdefgh') + .region('na') + expect(methodName).to.equal( + 'LEAGUE.GET_LEAGUE_ENTRIES_BY_SUMMONER_ID_V4', + ) + }) + }) + + describe('.list', function() { + it('should have the correct payload #1', function() { + const { payload } = this.LeagueEntries.list( + 'RANKED_SOLO_5x5', + 'DIAMOND', + 'I', + ).region('kr') + expect(payload).to.deep.equal({ + method: 'GET', + serviceName: 'league', + endpoint: 'entries/RANKED_SOLO_5x5/DIAMOND/I', + query: [], + region: 'kr', + isTournament: false, + version: 4, + }) + }) + + it('should have the correct method name', function() { + const { methodName } = this.LeagueEntries.list( + 'RANKED_SOLO_5x5', + 'DIAMOND', + 'I', + ).region('na') + expect(methodName).to.equal( + 'LEAGUE.GET_LEAGUE_ENTRIES_BY_QUEUE_TIER_DIVISION_V4', + ) + }) + }) +})