| | |
| | | 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 () { |
| | | |
| | | let lastUserId = null |
| | | const user = { |
| | | // Action: "Insert", |
| | | login: "123456789", |
| | | passwd: "123456789", |
| | | passwd_type: "plain", |
| | | firstname: "Adolfo", |
| | | lastname: "de la Cruz", |
| | | email: "alex@gorillaeis.com", |
| | | gender: "m", |
| | | department: "Bananenpflücker", |
| | | institution: "Globus Budapest", |
| | | role: 4, // assigned global role id |
| | | // udf_Markt: "Markt UDF", |
| | | udf: { |
| | | // ACHTUNG: Die Nummer enspricht der id in der Tabelle udf_definition und kann je nach Reihenfolge anders sein! |
| | | // wird in importIliasUser() aufgelöst aus dem Namen |
| | | // 1: "Markt UDF", |
| | | // 2: "Marktnummer UDF", |
| | | // 3: "Personal UDF", |
| | | "Markt": "Markt UDF 2", |
| | | "Marktnummer": "Marktnummer UDF 2", |
| | | "Personalnummer": "Personal UDF 2", |
| | | }, |
| | | } |
| | | 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 () { |
| | | await deleteUser(lastUserId) |
| | | 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) |
| | |
| | | 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) |
| | | }) |
| | | |
| | | // 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) |
| | | } |
| | | }) |
| | | |
| | | }) |