all files / lib/Endpoints/ TournamentStubEndpointV4.js

57.89% Statements 11/19
0% Branches 0/2
20% Functions 1/5
61.11% Lines 11/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118                                                                                                                                                                                                                      
import Endpoint from 'Endpoint'
import Request from 'RequestClient/Request'
import METHOD_NAMES from 'Enums/method-names'
 
class TournamentStubEndpointV4 extends Endpoint {
    constructor(config, limiter) {
        super()
 
        this.config = config
 
        this.create = this.createTournamentCode.bind(this)
        this.register = this.register.bind(this)
        this.registerProviderData = this.registerProviderData.bind(this)
        this.lobbyEvents = this.lobbyEvents.bind(this)
 
        this.serviceName = 'tournament-stub'
 
        this.limiter = limiter
    }
 
    /**
     * Create a mock tournament code for the given tournament.
     *
     * Implements POST `/lol/tournament-stub/v4/codes`.
     *
     * @param {number} tournamentID - The ID of the tournament from /lol/tournament-stub/v4/tournaments.
     * @param {object} body - The optional POST body to pass in. See official docs.
     */
    createTournamentCode(tournamentID, body) {
        return new Request(
            this.config,
            this.serviceName,
            'codes',
            METHOD_NAMES.TOURNAMENT_STUB.CREATE_TOURNAMENT_CODE_V4,
            'POST',
            this.limiter,
            body,
            true,
            4,
        ).query({ tournamentId: tournamentID })
    }
 
    /**
     * Creates a mock tournament and returns its ID.
     *
     * Implements POST `/lol/tournament-stub/v4/tournaments`.
     *
     * @param {number} providerID - The ID of the provider from /lol/tournament-stub/v4/providers.
     * @param {string} name - An optional name to pass in. It'll only be used if the length is > 0.
     */
    register(providerID, name = '') {
        const body = {
            providerId: providerID,
        }
        if (name.length > 0) body.name = name
        return new Request(
            this.config,
            this.serviceName,
            'tournaments',
            METHOD_NAMES.TOURNAMENT_STUB.REGISTER_TOURNAMENT_V4,
            'POST',
            this.limiter,
            body,
            true,
            4,
        )
    }
 
    /**
     * Creates a mock tournament provider and return its ID.
     *
     * Implements POST `/lol/tournament-stub/v4/providers`.
     *
     * @param {string} region - A region string ('na'/'euw'). Just use kayn's REGIONS dictionary.
     * @param {url} url - The provider's callback URL to which tournament game results in this region should be posted. See official docs.
     */
    registerProviderData(region = this.config.region.toUpperCase(), url) {
        const body = {
            region: region.toUpperCase(),
            url,
        }
        return new Request(
            this.config,
            this.serviceName,
            'providers',
            METHOD_NAMES.TOURNAMENT_STUB.REGISTER_PROVIDER_DATA_V4,
            'POST',
            this.limiter,
            body,
            true,
            4,
        )
    }
 
    /**
     * Gets a mock list of lobby events by tournament code.
     *
     * Implements GET `/lol/tournament-stub/v4/lobby-events/by-code/{tournamentCode}`.
     *
     * @param {string} tournamentCode - The short code to look up lobby events for.
     */
    lobbyEvents(tournamentCode) {
        return new Request(
            this.config,
            this.serviceName,
            `lobby-events/by-code/${tournamentCode}`,
            METHOD_NAMES.TOURNAMENT_STUB.GET_LOBBY_EVENTS_BY_CODE_V4,
            'GET',
            this.limiter,
            null,
            true,
            4,
        )
    }
}
 
export default TournamentStubEndpointV4