Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 0 additions & 148 deletions apps/backend/src/http/routes/game.routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,154 +163,6 @@ describe("game routes", () => {
})
}

//---- invites ----------------

it("sends an invite and shows it to both sides", async () => {
const sender = await signUp("caller")
const recipient = await signUp("callee")

const { response, body } = await call<{ invite: Invite }>(
"POST",
"/invites",
sender.token,
{
username: recipient.username,
setupType: "belgian_daisy",
side: "white",
},
)

expect(response.status).toBe(201)
expect(body.data?.invite).toMatchObject({
setupType: "belgian_daisy",
side: "white",
status: "pending",
from: { name: sender.username },
to: { name: recipient.username },
})

const theirs = await call<{ invites: Invite[] }>(
"GET",
"/invites",
recipient.token,
)
expect(theirs.body.data?.invites).toHaveLength(1)
})

it("finds a player whatever case the handle was typed in", async () => {
const sender = await signUp("typist")
const recipient = await signUp("target")

const { response } = await call("POST", "/invites", sender.token, {
username: recipient.username.toUpperCase(),
setupType: "standard",
side: "random",
})

expect(response.status).toBe(201)
})

it("refuses an invite to a handle nobody holds", async () => {
const sender = await signUp("lonely")

const { response, body } = await call(
"POST",
"/invites",
sender.token,
{
username: "nobody-at-all",
setupType: "standard",
side: "black",
},
)

expect(response.status).toBe(404)
expect(body.error_code).toBe("player_not_found")
})

it("refuses an invite to yourself", async () => {
const solo = await signUp("solo")

const { response, body } = await call("POST", "/invites", solo.token, {
username: solo.username,
setupType: "standard",
side: "black",
})

expect(response.status).toBe(400)
expect(body.error_code).toBe("invite_self")
})

it("refuses a second invite to the same player", async () => {
const sender = await signUp("keen")
const recipient = await signUp("popular")
await invite(sender.token, recipient.username)

const { response, body } = await call(
"POST",
"/invites",
sender.token,
{
username: recipient.username,
setupType: "standard",
side: "black",
},
)

expect(response.status).toBe(409)
expect(body.error_code).toBe("invite_exists")
})

it("lets the sender ask again after a decline", async () => {
const sender = await signUp("persistent")
const recipient = await signUp("reluctant")
const sent = await invite(sender.token, recipient.username)

const declined = await call<{ invite: Invite }>(
"PATCH",
`/invites/${sent.id}`,
recipient.token,
{ status: "declined" },
)
expect(declined.body.data?.invite.status).toBe("declined")

const again = await call<{ invite: Invite }>(
"POST",
"/invites",
sender.token,
{
username: recipient.username,
setupType: "the_wall",
side: "white",
},
)
expect(again.response.status).toBe(201)
expect(again.body.data?.invite).toMatchObject({
status: "pending",
setupType: "the_wall",
})
})

it("lets the sender take an invite back", async () => {
const sender = await signUp("changed")
const recipient = await signUp("waiting")
const sent = await invite(sender.token, recipient.username)

const { response } = await call(
"DELETE",
`/invites/${sent.id}`,
sender.token,
)
expect(response.status).toBe(200)

const theirs = await call<{ invites: Invite[] }>(
"GET",
"/invites",
recipient.token,
)
expect(theirs.body.data?.invites).toHaveLength(0)
})

//---- opening a game ----------------

it("opens a game on the invite's terms and clears the invite", async () => {
Expand Down
Loading
Loading