951c9c1fea
Check Deno code / Check Deno code (pull_request) Has been cancelled
Tests / Unit tests (pull_request) Has been cancelled
Tests / Integration tests (pull_request) Has been cancelled
Check Deno code / Check Deno code (push) Has been cancelled
Tests / Unit tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import { assertEquals, assertExists } from "@std/assert";
|
|
import {
|
|
closeTestPool,
|
|
seedRoles,
|
|
seedUsers,
|
|
testDb,
|
|
truncateAll,
|
|
} from "../helpers/db_integration.ts";
|
|
import { users } from "$root/databases/schema.ts";
|
|
|
|
Deno.test({
|
|
name: "integration: GET /users - DB round trip",
|
|
async fn() {
|
|
await truncateAll();
|
|
|
|
const [role] = await seedRoles([{ nom: "employee" }]);
|
|
await seedUsers([
|
|
{ id: "dupont.jean", nom: "Dupont", prenom: "Jean", idRole: role.id },
|
|
{ id: "martin.alice", nom: "Martin", prenom: "Alice", idRole: role.id },
|
|
]);
|
|
|
|
const rows = await testDb.select().from(users);
|
|
assertEquals(rows.length, 2);
|
|
assertExists(rows.find((u) => u.id === "dupont.jean"));
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "integration: INSERT user and retrieve by id",
|
|
async fn() {
|
|
await truncateAll();
|
|
|
|
const [role] = await seedRoles([{ nom: "admin" }]);
|
|
const [created] = await testDb.insert(users).values({
|
|
id: "durand.claire",
|
|
nom: "Durand",
|
|
prenom: "Claire",
|
|
idRole: role.id,
|
|
}).returning();
|
|
|
|
assertExists(created);
|
|
assertEquals(created.id, "durand.claire");
|
|
assertEquals(created.nom, "Durand");
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "integration: cleanup - close pool",
|
|
async fn() {
|
|
await closeTestPool();
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|