From a8c152f255665bc4eae00cc5a7f266cc9e7ffa51 Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Thu, 27 Nov 2025 15:20:16 +0000
Subject: [PATCH] GS-2333
---
test/testConnect.js | 56 +++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/test/testConnect.js b/test/testConnect.js
index 0f54a1d..83c4844 100644
--- a/test/testConnect.js
+++ b/test/testConnect.js
@@ -3,28 +3,18 @@
*/
const expect = require("chai").expect
-
const settings = require("../settings")
-const libIlias = require("../lib/libIlias")
-const db = require("../lib/db");
/////////////////////////////////////////////////////////////////////////
describe("connection test", function () {
-
- beforeEach(async function () {
- })
-
- afterEach(async function () {
- })
+ const urlS = settings.ilias.url
+ const urlD = new URL(urlS)
+ const url = urlD.origin
describe("the ILIAS URL", function () {
it("should be accessible", async function () {
- const urlS = settings.ilias.url
- const urlD = new URL(urlS)
- const url = urlD.origin
-
const res = await fetch(url)
expect(res.status).to.equal(200)
expect(res.statusText.toUpperCase()).to.equal("OK")
@@ -33,8 +23,6 @@
expect(text).to.contain("ILIAS")
})
it("should use https", async function () {
- const urlS = settings.ilias.url
- const urlD = new URL(urlS)
expect(urlD.protocol).to.equal("https:")
})
})
@@ -43,7 +31,6 @@
it("should be accessible", async function () {
const db = require("../lib/db")
const res = await db.getUsers(0, 1)
- // console.log(res)
expect(res).to.be.a("object")
expect(res.total).to.be.a("number").above(0)
@@ -65,7 +52,6 @@
it("should respond to a ping request", async function () {
const libIlias = require("../lib/libIlias")
const res = await libIlias.ping()
- // console.log(res)
expect(res).to.be.a("object")
expect(res.method).to.equal("GET")
@@ -74,6 +60,42 @@
})
})
+ describe("the rest service", function () {
+ it("should be accessible through GET /version", async function () {
+ const urlR = `${settings.restUrl}/api/version`
+ const res = await fetch(urlR)
+
+ const data = await res.json()
+ expect(data).to.be.a("object")
+ expect(data).to.have.property("version")
+ expect(data.version).to.be.a("string")
+ })
+ it("should not be accessible without a TOKEN", async function () {
+ const urlR = `${settings.restUrl}/api/user?offset=0&limit=1`
+ const res = await fetch(urlR)
+ expect(res.status).to.equal(403)
+ })
+ it("should be accessible with a TOKEN", async function () {
+ const urlR = `${settings.restUrl}/api/user?offset=0&limit=1&token=${settings.authtoken}`
+ const res = await fetch(urlR)
+ expect(res.status).to.equal(200)
+
+ const data = await res.json()
+ expect(data).to.be.a("object")
+ expect(data.total).to.be.a("number").above(0)
+ expect(data.offset).to.equal(0)
+ expect(data.limit).to.equal(1)
+
+ const data2 = data.data
+ expect(data2).to.be.a("array").and.to.be.lengthOf(1)
+
+ const user = data2[0]
+ expect(user.usr_id).to.be.a("number").above(0)
+ expect(user).to.have.property("login")
+ expect(user).to.have.property("firstname")
+ expect(user).to.have.property("lastname")
+ })
+ })
})
--
Gitblit v1.8.0