-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07ef2e6
commit 82128f2
Showing
14 changed files
with
129 additions
and
1,170 deletions.
There are no files selected for viewing
24 changes: 10 additions & 14 deletions
24
apps/api/app/config/init.spec.ts → apps/api/app/config/test-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
import assert from "assert"; | ||
import { Server } from "http"; | ||
import env from "./env"; | ||
import initDb from "./db"; | ||
import mongoose from "mongoose"; | ||
import { listen } from "../app"; | ||
import initDb from "./db"; | ||
import env from "./env"; | ||
|
||
let server: Server; | ||
assert(process.env.NODE_ENV === "test"); | ||
|
||
let server: Server; | ||
assert(env.database.bgs.name.endsWith("-test")); | ||
|
||
async function init() { | ||
assert(env.database.bgs.name.endsWith("-test")); | ||
env.listen.port.api = 50606; | ||
env.silent = true; | ||
|
||
export async function setupForTest() { | ||
await initDb(env.database.bgs.url, false); | ||
|
||
const users = await mongoose.connection.db.collection("users").countDocuments(); | ||
assert(users < 10, "This doesn't seem to be a test database"); | ||
await mongoose.connection.db.dropDatabase(); | ||
|
||
env.listen.port.api = 50606; | ||
env.silent = true; | ||
|
||
server = await listen(); | ||
|
||
run(); | ||
} | ||
|
||
init(); | ||
|
||
after(async () => { | ||
export async function teardownForTest() { | ||
server.close(); | ||
await mongoose.connection.db.dropDatabase(); | ||
await mongoose.connection.close(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import mongoose, { Types } from "mongoose"; | ||
import { defaultKarma, Game, GameNotification, GamePreferences, maxKarma, User } from "./index"; | ||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; | ||
|
||
const { ObjectId } = Types; | ||
|
||
|
@@ -11,7 +12,7 @@ describe("GameNotification", () => { | |
|
||
describe("processGameEnded", () => { | ||
describe("karma", () => { | ||
before(async () => { | ||
beforeAll(async () => { | ||
await mongoose.connection.db.dropDatabase(); | ||
|
||
await User.create({ _id: userId, account: { username: "test", email: "[email protected]" } }); | ||
|
@@ -28,7 +29,9 @@ describe("GameNotification", () => { | |
], | ||
}); | ||
}); | ||
after(() => mongoose.connection.db.dropDatabase()); | ||
afterAll(async () => { | ||
await mongoose.connection.db.dropDatabase(); | ||
}); | ||
|
||
it("should add karma to the active player and no karma to the dropped player", async () => { | ||
await GameNotification.create({ kind: "gameEnded", game: "test" }); | ||
|
@@ -74,7 +77,9 @@ describe("GameNotification", () => { | |
await GamePreferences.create({ game: "gaia-project", user: userId2, elo: { value: 110, games: 110 } }); | ||
await GamePreferences.create({ game: "gaia-project", user: userId3, elo: { value: 105, games: 5 } }); | ||
}); | ||
afterEach(() => mongoose.connection.db.dropDatabase()); | ||
afterEach(async () => { | ||
await mongoose.connection.db.dropDatabase(); | ||
}); | ||
|
||
it("should add elo to player and player2, and min elo 100 to player3, set elo 1 to beginner player4 ", async () => { | ||
await GameNotification.create({ kind: "gameEnded", game: "test" }); | ||
|
@@ -161,12 +166,14 @@ describe("GameNotification", () => { | |
}); | ||
|
||
describe("processPlayerDrop", () => { | ||
before(async () => { | ||
beforeAll(async () => { | ||
await User.create({ _id: userId, account: { username: "test", email: "[email protected]" } }); | ||
await User.create({ _id: userId2, account: { username: "test2", email: "[email protected]" } }); | ||
}); | ||
|
||
after(() => mongoose.connection.db.dropDatabase()); | ||
afterAll(async () => { | ||
await mongoose.connection.db.dropDatabase(); | ||
}); | ||
|
||
it("should drop 10 karma after dropping out", async () => { | ||
await GameNotification.create({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import mongoose, { Types } from "mongoose"; | ||
import env from "../../config/env"; | ||
import { Game, GameInfo, GamePreferences, JwtRefreshToken, User } from "../../models"; | ||
import { afterAll, beforeAll, describe, it } from "vitest"; | ||
import { expect } from "chai"; | ||
|
||
describe("Game API", () => { | ||
const userId = new Types.ObjectId(); | ||
let headers: Record<string, string>; | ||
|
||
before(async () => { | ||
beforeAll(async () => { | ||
await User.create({ | ||
_id: userId, | ||
account: { username: "test", email: "[email protected]" }, | ||
|
@@ -126,5 +128,7 @@ describe("Game API", () => { | |
expect(await Game.countDocuments({ _id: "test" })).to.equal(0, "Game should be deleted after creator unjoins"); | ||
}); | ||
|
||
after(() => mongoose.connection.db.dropDatabase()); | ||
afterAll(async () => { | ||
await mongoose.connection.db.dropDatabase(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.