REST Service for POPCORN - ILIAS
alex
7 hours ago 07d24fc7a08276076495d90e1e0274a141acddbd
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
const expect = require("chai").expect
const _ = require("lodash")
 
const libIlias = require("../lib/libIlias")
const db = require("../lib/db")
const testData = require("./data")
 
/////////////////////////////////////////////////////////////////////////
 
describe("the function importIliasUser", function () {
 
   let lastUserId = null
   let user = null
 
   beforeEach(async function () {
      // deep clone so importIliasUser can not mutate the shared fixture
      user = _.cloneDeep(testData.user)
      lastUserId = null
   })
 
   afterEach(async function () {
      if (lastUserId) await deleteUser(lastUserId).catch(console.error)
   })
 
   it("should import a new user to ILIAS", async function () {
      const res = await libIlias.importIliasUser(user)
      // console.dir(res, {depth: null})
      expect(res).to.have.property("status").and.to.equal("ok")
      expect(res.command).to.equal("importUser")
      expect(res.usr_id).to.be.a("number").above(0)
 
      const {usr_id} = res
      lastUserId = usr_id
      const user2 = await db.getUserByUserId(usr_id)
      console.log(user2)
      expect(user2).to.have.property("login").and.to.equal(user.login)
      expect(user2).to.have.property("usr_id").and.to.equal(res.usr_id)
      expect(user2).to.have.property("firstname").and.to.equal(user.firstname)
      expect(user2).to.have.property("lastname").and.to.equal(user.lastname)
      expect(user2).to.have.property("email").and.to.equal(user.email)
      expect(user2).to.have.property("institution").and.to.equal(user.institution)
   })
 
   it("should not mutate the given user object", async function () {
      const before = _.cloneDeep(user)
      const res = await libIlias.importIliasUser(user)
      lastUserId = res.usr_id
      expect(user).to.deep.equal(before)
   })
 
   it("should resolve user defined field names to ids", async function () {
      const res = await libIlias.importIliasUser(user)
      lastUserId = res.usr_id
 
      const fields = await db.getUserDefinedField(lastUserId)
      const byName = _.keyBy(fields, "field_name")
      for (const [name, value] of Object.entries(user.udf)) {
         expect(byName).to.have.property(name)
         expect(byName[name].value).to.equal(value)
      }
   })
 
})
 
/////////////////////////////////////////////////////////////////////////
 
async function deleteUser (usr_id) {
   const res2 = await libIlias.deleteUser(usr_id)
   console.log(res2)
   expect(res2).to.have.property("status").and.to.equal("ok")
   expect(res2).to.have.property("command").and.to.equal("deleteUser")
}