mirror of
https://github.com/OHTU-German-learning-website/OHTU-German-learning-website.git
synced 2026-10-12 19:13:51 +03:00
Updated tests
This commit is contained in:
@@ -26,11 +26,20 @@ describe("GET /api/admin/grammar-topics", () => {
|
||||
|
||||
const payload = await response.json();
|
||||
expect(Array.isArray(payload)).toBe(true);
|
||||
expect(payload.map((row) => row.name)).toEqual([
|
||||
"A Themen",
|
||||
"Z Themen",
|
||||
"M Themen",
|
||||
]);
|
||||
|
||||
const names = payload.map((row) => row.name);
|
||||
const aIndex = names.indexOf("A Themen");
|
||||
const zIndex = names.indexOf("Z Themen");
|
||||
const mIndex = names.indexOf("M Themen");
|
||||
|
||||
expect(aIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(zIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(mIndex).toBeGreaterThanOrEqual(0);
|
||||
|
||||
// We inserted A with sort_order=1, Z with sort_order=10, M with sort_order=NULL.
|
||||
// The endpoint sorts by sort_order ASC NULLS LAST, then name.
|
||||
expect(aIndex).toBeLessThan(zIndex);
|
||||
expect(zIndex).toBeLessThan(mIndex);
|
||||
});
|
||||
|
||||
it("returns 401 for non-admin user", async () => {
|
||||
|
||||
@@ -25,6 +25,13 @@ describe("POST /api/admin/pages", () => {
|
||||
const admin = await TestFactory.user({ is_admin: true });
|
||||
const { mockPost } = useTestRequest(admin);
|
||||
|
||||
const before = await DB.pool(
|
||||
`SELECT COALESCE(MAX(page_order), 0) AS max_order
|
||||
FROM html_pages
|
||||
WHERE page_group = 'resources'`
|
||||
);
|
||||
const expectedNextOrder = Number(before.rows[0].max_order) + 1;
|
||||
|
||||
const response = await POST(
|
||||
mockPost("/api/admin/pages", {
|
||||
title: "New Resource",
|
||||
@@ -42,7 +49,7 @@ describe("POST /api/admin/pages", () => {
|
||||
|
||||
expect(inserted.rowCount).toBe(1);
|
||||
expect(inserted.rows[0].title).toBe("New Resource");
|
||||
expect(inserted.rows[0].page_order).toBe(2);
|
||||
expect(inserted.rows[0].page_order).toBe(expectedNextOrder);
|
||||
expect(inserted.rows[0].grammar_topic_id).toBeNull();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user