| | |
| | | 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 = testData.user |
| | | 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 () { |
| | |
| | | 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) |
| | | } |
| | | }) |
| | | |
| | | }) |