mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-09 07:01:27 -07:00
[leaderboard] stub 2 endpoints
This commit is contained in:
@@ -33,13 +33,53 @@ it('answers GetRanks with an empty row list', async () => {
|
||||
expect(await res.json()).toEqual({ Rows: [] })
|
||||
})
|
||||
|
||||
it('answers GetPlayerRank with the unranked sentinel and the caller’s own id', async () => {
|
||||
const res = await SELF.fetch('https://example.com/leaderboard/GetPlayerRank', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
PlayerId: 205,
|
||||
StatChannel: 2,
|
||||
RoomId: 14,
|
||||
FilterType: 0,
|
||||
SortAscending: false,
|
||||
}),
|
||||
})
|
||||
expect(res.status).toBe(200)
|
||||
// Three fields, no board selectors: the client pairs the answer with its own question.
|
||||
// Rank is 1-based, so the sentinel has to be a big number rather than 0 — which would
|
||||
// render the unranked caller as first place.
|
||||
expect(await res.json()).toEqual({ PlayerId: 205, Score: 0, Rank: 99999 })
|
||||
})
|
||||
|
||||
it('answers GetPlayerRank even when the body is unreadable', async () => {
|
||||
const res = await SELF.fetch('https://example.com/leaderboard/GetPlayerRank', {
|
||||
method: 'POST',
|
||||
body: 'not json',
|
||||
})
|
||||
// A board that fails to draw is worse than one that draws the player as unranked.
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toEqual({ PlayerId: 0, Score: 0, Rank: 99999 })
|
||||
})
|
||||
|
||||
it('answers CheckAndSetStat with a bare 0', async () => {
|
||||
const res = await SELF.fetch('https://example.com/leaderboard/CheckAndSetStat', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ StatChannel: 2, RoomId: 14, StatValue: 1, CurrentStatValue: null }),
|
||||
})
|
||||
expect(res.status).toBe(200)
|
||||
// The whole body is the number — not an envelope, not `{ value: 0 }`.
|
||||
expect(await res.text()).toBe('0')
|
||||
})
|
||||
|
||||
it('serves an openapi spec with no dangling refs', async () => {
|
||||
const res = await SELF.fetch('https://example.com/openapi.json')
|
||||
expect(res.status).toBe(200)
|
||||
const spec = (await res.json()) as Record<string, unknown>
|
||||
expect(Object.keys(spec.paths as object).sort()).toEqual([
|
||||
'/',
|
||||
'/leaderboard/CheckAndSetStat',
|
||||
'/leaderboard/GetNearbyScores',
|
||||
'/leaderboard/GetPlayerRank',
|
||||
'/leaderboard/GetRanks',
|
||||
])
|
||||
expect(JSON.stringify(spec).match(/\$ref/g)).toBeNull()
|
||||
|
||||
Reference in New Issue
Block a user