Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d1b8b65b9 | |||
| a1782527a6 | |||
| 204cce4227 | |||
| f5497536f0 | |||
| b0cf5aed6f | |||
| daa7f4951f | |||
| a95818e3bf | |||
| 26eedcc4f2 | |||
| ce4782580d | |||
| 91248370da | |||
| 6b8b5e6aa3 | |||
| d1c3b93755 | |||
| f42df29f06 | |||
| c8b808f509 | |||
| fdfdd74894 | |||
| 60dde4675c | |||
| fef9457795 | |||
| 6db04045f4 | |||
| cdd9c0bf06 | |||
| 980efcfbc3 |
@@ -6,9 +6,26 @@ on:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
check-code:
|
||||
name: "Check Deno code"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: denoland/setup-deno@v2
|
||||
with:
|
||||
deno-version: v2.x
|
||||
|
||||
- name: Check formatting
|
||||
run: deno fmt --check
|
||||
|
||||
- name: Check linting
|
||||
run: deno lint
|
||||
|
||||
deploy:
|
||||
name: "Build Docker image"
|
||||
runs-on: ubuntu-latest
|
||||
needs: check-code
|
||||
steps:
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
|
||||
@@ -4,6 +4,10 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
+3
-1
@@ -2,7 +2,9 @@ import { defineConfig } from "drizzle-kit";
|
||||
import process from "node:process";
|
||||
|
||||
const url = process.env.DATABASE_URL ??
|
||||
`postgresql://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASS}@${process.env.POSTGRES_HOST ?? "localhost"}:${process.env.POSTGRES_PORT ?? 5432}/${process.env.POSTGRES_DB}`;
|
||||
`postgresql://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASS}@${
|
||||
process.env.POSTGRES_HOST ?? "localhost"
|
||||
}:${process.env.POSTGRES_PORT ?? 5432}/${process.env.POSTGRES_DB}`;
|
||||
|
||||
export default defineConfig({
|
||||
dialect: "postgresql",
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// #115 - E2E tests for GET /permissions
|
||||
// Handler statique (pas de DB), test direct du handler
|
||||
|
||||
import { assertEquals, assertExists } from "@std/assert";
|
||||
import { makeEmployeeContext, makeGetRequest } from "../helpers/handler.ts";
|
||||
import { handler as permissionsHandler } from "$apps/admin/api/permissions.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "e2e permissions: GET /permissions returns all 9 permissions",
|
||||
fn() {
|
||||
const res = permissionsHandler.GET!(
|
||||
makeGetRequest("/permissions"),
|
||||
makeEmployeeContext(),
|
||||
);
|
||||
assertEquals(res.status, 200);
|
||||
return res.text().then((text) => {
|
||||
const data = JSON.parse(text);
|
||||
assertEquals(data.length, 9);
|
||||
assertExists(data.find((p: { id: string }) => p.id === "student_read"));
|
||||
assertExists(data.find((p: { id: string }) => p.id === "role_write"));
|
||||
});
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "e2e permissions: GET /permissions - all entries have id and nom",
|
||||
async fn() {
|
||||
const res = permissionsHandler.GET!(
|
||||
makeGetRequest("/permissions"),
|
||||
makeEmployeeContext(),
|
||||
);
|
||||
const data: { id: string; nom: string }[] = await res.json();
|
||||
for (const p of data) {
|
||||
assertEquals(typeof p.id, "string");
|
||||
assertEquals(typeof p.nom, "string");
|
||||
}
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
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,
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
// #115 - Unit tests for GET /permissions
|
||||
|
||||
import { assertEquals, assertExists } from "@std/assert";
|
||||
import { mockFetch, restoreFetch } from "../helpers/api_mock.ts";
|
||||
|
||||
interface Permission {
|
||||
id: string;
|
||||
nom: string;
|
||||
}
|
||||
|
||||
const EXPECTED_PERMISSIONS: Permission[] = [
|
||||
{ id: "student_read", nom: "Consulter les élèves" },
|
||||
{ id: "student_write", nom: "Gérer les élèves" },
|
||||
{ id: "note_read", nom: "Consulter les notes" },
|
||||
{ id: "note_write", nom: "Gérer les notes" },
|
||||
{ id: "module_read", nom: "Consulter les modules" },
|
||||
{ id: "module_write", nom: "Gérer les modules" },
|
||||
{ id: "user_read", nom: "Consulter les utilisateurs" },
|
||||
{ id: "user_write", nom: "Gérer les utilisateurs" },
|
||||
{ id: "role_write", nom: "Gérer les rôles" },
|
||||
];
|
||||
|
||||
Deno.test("permissions: known permission ids", () => {
|
||||
const ids = EXPECTED_PERMISSIONS.map((p) => p.id);
|
||||
assertEquals(ids.includes("student_read"), true);
|
||||
assertEquals(ids.includes("student_write"), true);
|
||||
assertEquals(ids.includes("note_read"), true);
|
||||
assertEquals(ids.includes("role_write"), true);
|
||||
assertEquals(ids.length, 9);
|
||||
});
|
||||
|
||||
Deno.test("permissions: all permissions have string id and nom", () => {
|
||||
for (const p of EXPECTED_PERMISSIONS) {
|
||||
assertEquals(typeof p.id, "string");
|
||||
assertEquals(typeof p.nom, "string");
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("mock API: GET /permissions returns all permissions", async () => {
|
||||
mockFetch({ "/permissions": EXPECTED_PERMISSIONS });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/permissions");
|
||||
assertEquals(res.status, 200);
|
||||
const data: Permission[] = await res.json();
|
||||
assertEquals(data.length, 9);
|
||||
assertExists(data.find((p) => p.id === "student_read"));
|
||||
assertExists(data.find((p) => p.id === "role_write"));
|
||||
} finally {
|
||||
restoreFetch();
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("mock API: GET /permissions - each permission has id and nom", async () => {
|
||||
mockFetch({ "/permissions": EXPECTED_PERMISSIONS });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/permissions");
|
||||
const data: Permission[] = await res.json();
|
||||
for (const p of data) {
|
||||
assertExists(p.id);
|
||||
assertExists(p.nom);
|
||||
}
|
||||
} finally {
|
||||
restoreFetch();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user