Skip to content

Commit

Permalink
playerList + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jul 28, 2024
1 parent 362f5b4 commit a0c3273
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/OAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export class OAPIV3 {
static discord = async (...objs: DiscordReqObject[]): Promise<DiscordResObject[]> =>
await townyData('/discord', 'v3', { query: objs })

static players = async (...ids: string[]): Promise<OAPIResident> =>
static playerList = async (): Promise<{ name: string, uuid: string }[]> =>
await townyData('/players', 'v3')

static players = async (...ids: string[]): Promise<OAPIResident[]> =>
await townyData('/players', 'v3', { query: ids })
}

Expand Down
16 changes: 16 additions & 0 deletions tests/oapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ describe('[v3] OfficialAPI', async () => {
expect(info.stats.numTowns).toBeGreaterThanOrEqual(1000)
expect(info.stats.numNations).toBeGreaterThanOrEqual(100)
}, 10000)

it('can get player list', async () => {
const playerList = await OfficialAPI.V3.playerList()

expect(playerList).toBeDefined()
assertType<{ name: string, uuid: string }[]>(playerList)
}, 10000)

it('can get valid player info', async () => {
const players = await OfficialAPI.V3.players("af77d9b5-ab5d-4714-b92e-3b191c895ee7")

console.log(players)

expect(players).toBeDefined()
assertType<OAPIResident[]>(players)
}, 10000)
})

describe('[v2] OfficialAPI', async () => {
Expand Down

0 comments on commit a0c3273

Please sign in to comment.