REST Service for POPCORN - ILIAS
alex
2025-11-17 5fa36d9ea426f6f3dffc31cce8a55821e9ead5bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
 * Testing connection to all components
 */
 
const expect = require("chai").expect
 
const settings = require("../settings")
const libIlias = require("../lib/libIlias")
const db = require("../lib/db");
 
/////////////////////////////////////////////////////////////////////////
 
describe("connection test", function () {
 
   const urlS = settings.ilias.url
   const urlD = new URL(urlS)
   const url = urlD.origin
 
 
   beforeEach(async function () {
   })
 
   afterEach(async function () {
   })
 
   describe("the ILIAS URL", function () {
      it("should be accessible", async function () {
         const res = await fetch(url)
         expect(res.status).to.equal(200)
         expect(res.statusText.toUpperCase()).to.equal("OK")
         const text = await res.text()
         expect(text).to.contain("html")
         expect(text).to.contain("ILIAS")
      })
      it("should use https", async function () {
         expect(urlD.protocol).to.equal("https:")
      })
   })
 
   describe("the Database", function () {
      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)
         expect(res.offset).to.equal(0)
         expect(res.limit).to.equal(1)
 
         const data = res.data
         expect(data).to.be.a("array").and.to.be.lengthOf(1)
 
         const user = data[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")
      })
   })
 
   describe("the PHP component", function () {
      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")
         expect(res.command).to.equal("ping")
         expect(res.status).to.equal("ok")
      })
   })
 
   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)
         // console.log(res)
 
         const data = await res.json()
         // console.log(data)
         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()
         // console.log(data)
 
         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")
      })
   })
 
})
 
/////////////////////////////////////////////////////////////////////////