feat: update tests
This commit is contained in:
@@ -1,14 +1,51 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { describe, it } from "@std/testing/bdd";
|
||||
import "./mocks/server.ts";
|
||||
|
||||
import { assertEquals, assertObjectMatch } from "@std/assert";
|
||||
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd";
|
||||
|
||||
import { relay } from "./mocks/relay.ts";
|
||||
import { api, users } from "./mocks/server.ts";
|
||||
|
||||
describe("Relay", () => {
|
||||
it("should create a new user", async () => {
|
||||
let server: Deno.HttpServer<Deno.NetAddr>;
|
||||
|
||||
beforeAll(() => {
|
||||
server = Deno.serve(
|
||||
{
|
||||
port: 36573,
|
||||
hostname: "localhost",
|
||||
onListen({ port, hostname }) {
|
||||
console.log(`Listening at http://${hostname}:${port}`);
|
||||
},
|
||||
},
|
||||
async (request) => api.handle(request),
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await server.shutdown();
|
||||
});
|
||||
|
||||
it("should successfully relay users", async () => {
|
||||
const userId = await relay.post("/users", { name: "John Doe", email: "john.doe@fixture.none" });
|
||||
|
||||
console.log({ userId });
|
||||
|
||||
assertEquals(typeof userId, "string");
|
||||
assertEquals(users.length, 1);
|
||||
|
||||
const user = await relay.get("/users/:userId", { userId });
|
||||
|
||||
assertEquals(user.createdAt instanceof Date, true);
|
||||
|
||||
await relay.put("/users/:userId", { userId }, { name: "Jane Doe", email: "jane.doe@fixture.none" });
|
||||
|
||||
assertEquals(users.length, 1);
|
||||
assertObjectMatch(users[0], {
|
||||
name: "Jane Doe",
|
||||
email: "jane.doe@fixture.none",
|
||||
});
|
||||
|
||||
await relay.delete("/users/:userId", { userId });
|
||||
|
||||
assertEquals(users.length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user