| | |
| | | const expect = require("chai").expect |
| | | const _ = require("lodash") |
| | | |
| | | const settings = require("../settings") |
| | | const libIlias = require("../lib/libIlias") |
| | | const db = require("../lib/db") |
| | | const testData = require("./data") |
| | | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | | |
| | | describe("the function importIliasUser", function () { |
| | | |
| | | const user = { |
| | | // Action: "Insert", |
| | | login: "affoReloaded", |
| | | passwd: "test1234", |
| | | passwd_type: "plain", |
| | | firstname: "Adolfo", |
| | | lastname: "de la Cruz", |
| | | email: "alex@gorillaeis.com", |
| | | gender: "m", |
| | | department: "Bananenpflücker", |
| | | institution: "Globus Budapest", |
| | | roleIdGlobal: 4, |
| | | userDefinedField: [ |
| | | { |
| | | name: "Markt", |
| | | value: "Markt UDF", |
| | | }, |
| | | { |
| | | name: "Marktnummer", |
| | | value: "Marktnummer UDF", |
| | | }, |
| | | { |
| | | name: "Personalnummer", |
| | | value: "Personalnummer UDF", |
| | | }, |
| | | ], |
| | | } |
| | | 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}) |
| | | // 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("affoReloaded") |
| | | 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) |
| | | }) |
| | | |
| | | 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") |
| | | 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") |
| | | } |