import { assert } from "chai"; import { describe, it, beforeEach, afterEach } from "node:test"; import * as m from "../index"; import * as config from "./config"; import mockModule from "./mock"; describe("Partner", function() { let models: m.BackendModels, mongoose: m.MongooseModule; let testItem: Partial; beforeEach(async function() { const c = await m.connect(config.url); models = c.models; mongoose = c.mongoose; const mock = mockModule({ mongoose }); testItem = mock.partner; await mock.beforeEach(); }); afterEach(async function() { await mongoose.disconnect(); }); it("is saved", async function() { const item = new models.Partner(testItem); const sut = await item.save(); assert.isNotNull(testItem._id); assert.equal(sut.name, testItem.name); assert.equal(sut.active, testItem.active); assert.equal(sut.partnerKey, testItem.partnerKey); assert.isString(sut.uuid); assert.equal(sut.location.enabled, testItem.location?.enabled); assert.deepEqual(sut.location.departmentIds, testItem.location?.departmentIds); assert.equal(sut.location.includeVehicleStatus, testItem.location?.includeVehicleStatus); }); it("round-trips location filters including departmentId scope", async function() { const partner: Partial = { ...testItem, location: { enabled: true, departmentIds: testItem.location?.departmentIds ?? [], includeVehicleStatus: false, speedAsBinary: false, useCadVisibility: false, filters: [ { type: "agencyCode", enabled: true, values: ["AC1"], departmentId: "dept001" }, { type: "agencyCode", enabled: true, values: ["AC2"], departmentId: "" }, ], }, }; const item = new models.Partner(partner); const saved = await item.save(); const sut = await models.Partner.findById(saved._id); assert.isNotNull(sut); if (!sut) { return; } assert.lengthOf(sut.location.filters, 2); const scoped = sut.location.filters[0]; assert.isDefined(scoped); assert.equal(scoped?.type, "agencyCode"); assert.equal(scoped?.enabled, true); assert.deepEqual(scoped?.values, ["AC1"]); assert.equal(scoped?.departmentId, "dept001"); const unscoped = sut.location.filters[1]; assert.isDefined(unscoped); assert.equal(unscoped?.type, "agencyCode"); assert.equal(unscoped?.enabled, true); assert.deepEqual(unscoped?.values, ["AC2"]); assert.equal(unscoped?.departmentId, ""); }); });