REST Service for POPCORN - ILIAS
alex
6 hours ago 6138ffe99d016cc311f250bc1555b5403b8b1216
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
const expect = require("chai").expect
const _ = require("lodash")
 
const libIlias = require("../lib/libIlias")
const db = require("../lib/db")
const testData = require("./data")
 
/////////////////////////////////////////////////////////////////////////
 
// Integration test against a real ILIAS instance.
// Creates a temporary user, enrolls it via libIlias.anmelden() into an
// existing course and verifies the membership, then cleans up.
describe("the function anmelden", function () {
 
   const courseId = testData.anmelden.obj_id
   let user = null
   let userId = null
 
   beforeEach(async function () {
      user = _.cloneDeep(testData.user)
      const res = await libIlias.importIliasUser(user)
      userId = res.usr_id
   })
 
   afterEach(async function () {
      if (!userId) return
      // best effort cleanup
      await libIlias.abmelden(userId, courseId).catch(console.error)
      await libIlias.deleteUser(userId).catch(console.error)
      userId = null
   })
 
   it("should enroll a user into a course", async function () {
      const res = await libIlias.anmelden(userId, courseId)
      expect(res).to.have.property("status").and.to.equal("ok")
      expect(res).to.have.property("command").and.to.equal("anmelden")
      expect(res).to.have.property("method").and.to.equal("POST")
 
      const members = await db.getKursTeilnehmerByRole(courseId)
      expect(members.map(m => m.usr_id)).to.include(userId)
   })
 
})
 
/////////////////////////////////////////////////////////////////////////