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, verifies that libIlias.abmelden() removes the // membership, then cleans up. describe("the function abmelden", 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 // precondition: the user must be enrolled await libIlias.anmelden(userId, courseId) }) afterEach(async function () { if (!userId) return // best effort cleanup (abmelden is idempotent) await libIlias.abmelden(userId, courseId).catch(console.error) await libIlias.deleteUser(userId).catch(console.error) userId = null }) it("should remove the Teilnahme of a user", async function () { const res = await libIlias.abmelden(userId, courseId) expect(res).to.have.property("status").and.to.equal("ok") expect(res).to.have.property("command").and.to.equal("abmelden") expect(res).to.have.property("method").and.to.equal("DELETE") const members = await db.getKursTeilnehmerByRole(courseId) expect(members.map(m => m.usr_id)).to.not.include(userId) }) }) /////////////////////////////////////////////////////////////////////////