From ff1a8d2280347d2dcc16518032439b5cc2fc7973 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 3 Jun 2025 19:32:17 +0300 Subject: [PATCH] test(etapi): port get-date-notes --- _regroup/test-etapi/get-date-notes.http | 72 -------------- _regroup/test-etapi/http-client.env.json | 5 - apps/server/spec/etapi/get-date-notes.spec.ts | 94 +++++++++++++++++++ 3 files changed, 94 insertions(+), 77 deletions(-) delete mode 100644 _regroup/test-etapi/get-date-notes.http delete mode 100644 _regroup/test-etapi/http-client.env.json create mode 100644 apps/server/spec/etapi/get-date-notes.spec.ts diff --git a/_regroup/test-etapi/get-date-notes.http b/_regroup/test-etapi/get-date-notes.http deleted file mode 100644 index 19f0b4fc9..000000000 --- a/_regroup/test-etapi/get-date-notes.http +++ /dev/null @@ -1,72 +0,0 @@ -GET {{triliumHost}}/etapi/inbox/2022-01-01 -Authorization: {{authToken}} - -> {% client.assert(response.status === 200); %} - -### - -GET {{triliumHost}}/etapi/calendar/days/2022-01-01 -Authorization: {{authToken}} - -> {% client.assert(response.status === 200); %} - -### - -GET {{triliumHost}}/etapi/calendar/days/2022-1 -Authorization: {{authToken}} - -> {% - client.assert(response.status === 400); - client.assert(response.body.code === "DATE_INVALID"); -%} - -### - -GET {{triliumHost}}/etapi/calendar/weeks/2022-01-01 -Authorization: {{authToken}} - -> {% client.assert(response.status === 200); %} - -### - -GET {{triliumHost}}/etapi/calendar/weeks/2022-1 -Authorization: {{authToken}} - -> {% - client.assert(response.status === 400); - client.assert(response.body.code === "DATE_INVALID"); -%} - -### - -GET {{triliumHost}}/etapi/calendar/months/2022-01 -Authorization: {{authToken}} - -> {% client.assert(response.status === 200); %} - -### - -GET {{triliumHost}}/etapi/calendar/months/2022-1 -Authorization: {{authToken}} - -> {% - client.assert(response.status === 400); - client.assert(response.body.code === "MONTH_INVALID"); -%} - -### - -GET {{triliumHost}}/etapi/calendar/years/2022 -Authorization: {{authToken}} - -> {% client.assert(response.status === 200); %} - -### - -GET {{triliumHost}}/etapi/calendar/years/202 -Authorization: {{authToken}} - -> {% - client.assert(response.status === 400); - client.assert(response.body.code === "YEAR_INVALID"); -%} diff --git a/_regroup/test-etapi/http-client.env.json b/_regroup/test-etapi/http-client.env.json deleted file mode 100644 index 8ede0719c..000000000 --- a/_regroup/test-etapi/http-client.env.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dev": { - "triliumHost": "http://localhost:37740" - } -} diff --git a/apps/server/spec/etapi/get-date-notes.spec.ts b/apps/server/spec/etapi/get-date-notes.spec.ts new file mode 100644 index 000000000..b472fde06 --- /dev/null +++ b/apps/server/spec/etapi/get-date-notes.spec.ts @@ -0,0 +1,94 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import config from "../../src/services/config.js"; +import { login } from "./utils.js"; +import { Application } from "express"; +import supertest from "supertest"; + +let app: Application; +let token: string; + +const USER = "etapi"; + +describe("etapi/get-date-notes", () => { + beforeAll(async () => { + config.General.noAuthentication = false; + const buildApp = (await (import("../../src/app.js"))).default; + app = await buildApp(); + token = await login(app); + }); + + it("obtains inbox", async () => { + await supertest(app) + .get("/etapi/inbox/2022-01-01") + .auth(USER, token, { "type": "basic"}) + .expect(200); + }); + + describe("days", () => { + it("obtains day from calendar", async () => { + await supertest(app) + .get("/etapi/calendar/days/2022-01-01") + .auth(USER, token, { "type": "basic"}) + .expect(200); + }); + + it("detects invalid date", async () => { + const response = await supertest(app) + .get("/etapi/calendar/days/2022-1") + .auth(USER, token, { "type": "basic"}) + .expect(400); + expect(response.body.code).toStrictEqual("DATE_INVALID"); + }); + }); + + describe("weeks", () => { + it("obtains week calendar", async () => { + await supertest(app) + .get("/etapi/calendar/weeks/2022-01-01") + .auth(USER, token, { "type": "basic"}) + .expect(200); + }); + + it("detects invalid date", async () => { + const response = await supertest(app) + .get("/etapi/calendar/weeks/2022-1") + .auth(USER, token, { "type": "basic"}) + .expect(400); + expect(response.body.code).toStrictEqual("DATE_INVALID"); + }); + }); + + describe("months", () => { + it("obtains month calendar", async () => { + await supertest(app) + .get("/etapi/calendar/weeks/2022-01") + .auth(USER, token, { "type": "basic"}) + .expect(200); + }); + + it("detects invalid month", async () => { + const response = await supertest(app) + .get("/etapi/calendar/months/2022-1") + .auth(USER, token, { "type": "basic"}) + .expect(400); + expect(response.body.code).toStrictEqual("MONTH_INVALID"); + }); + }); + + describe("years", () => { + it("obtains year calendar", async () => { + await supertest(app) + .get("/etapi/calendar/years/2022") + .auth(USER, token, { "type": "basic"}) + .expect(200); + }); + + it("detects invalid year", async () => { + const response = await supertest(app) + .get("/etapi/calendar/years/202") + .auth(USER, token, { "type": "basic"}) + .expect(400); + expect(response.body.code).toStrictEqual("YEAR_INVALID"); + }); + }); +});