Skip to content

Commit

Permalink
feat: get ladder in league object
Browse files Browse the repository at this point in the history
  • Loading branch information
klayveR committed Mar 23, 2021
1 parent 4691590 commit 4de5eb2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/poe/apis/leagues/League.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "reflect-metadata";
import "mocha";

import { expect } from "chai";
import { League } from "./League";

describe("Path of Exile - Leagues - League", function () {
describe("#getLadder()", () => {
let mockLeague: League;

before(() => {
mockLeague = new League();
mockLeague.id = "Standard";
});

it("should fetch the ladder and store it", async () => {
const ladder = await mockLeague.getLadder();
expect(ladder).to.not.be.null;
});

it("should have stored the ladder in the league", () => {
expect(mockLeague.ladder).to.not.be.undefined;
});
});
});
22 changes: 21 additions & 1 deletion src/poe/apis/leagues/League.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Type } from "class-transformer";

import { Transformable } from "../../../common/classes";
import { Realm } from "../../shared/models";
import { Ladder } from "../ladders";
import { Ladder, Options } from "../ladders";
import { Rule } from "./Rule";
import * as API from "../ladders/API";

export class League extends Transformable {
id!: string;
Expand All @@ -29,4 +30,23 @@ export class League extends Transformable {

@Type(/* istanbul ignore next */ () => Ladder)
ladder?: Ladder;

/**
* @remarks
* If `store` is set to true and [[ladder]] had a ladder already, it will be overwritten.
*
* @param options
* @param store If set to `true`, the ladder will be saved in the [[ladder]] property
* @returns The ladder for this league
* @throws [[APIError]]
*/
public async getLadder(options?: Options, store = true): Promise<Ladder> {
const ladder = await API.get(this.id, options);

if (store) {
this.ladder = ladder;
}

return ladder;
}
}

0 comments on commit 4de5eb2

Please sign in to comment.