@7365admin1/core 3.126.0 → 3.126.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@7365admin1/core",
3
3
  "license": "MIT",
4
- "version": "3.126.0",
4
+ "version": "3.126.1",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -35,6 +35,7 @@ const ADMIN_EMAIL = "admin@sub.example.com";
35
35
  const OUTSIDER_EMAIL = "someone@rival.example.com";
36
36
  const NEWCO_EMAIL = "hello@newco.example.com";
37
37
  const LATE_EMAIL = "owner@late.example.com";
38
+ const PM_STAFF_EMAIL = "staff@northwind.example.com";
38
39
 
39
40
  describe("service provider invites a service provider, end to end", { concurrency: 1 }, () => {
40
41
  let h;
@@ -53,6 +54,7 @@ describe("service provider invites a service provider, end to end", { concurrenc
53
54
  admin: ADMIN_EMAIL,
54
55
  outsider: OUTSIDER_EMAIL,
55
56
  late: LATE_EMAIL,
57
+ pmStaff: PM_STAFF_EMAIL,
56
58
  })) {
57
59
  sid[k] = await h.login(e, PW);
58
60
  }
@@ -317,6 +319,48 @@ describe("service provider invites a service provider, end to end", { concurrenc
317
319
  assert.equal(item.viewStatus, "expired");
318
320
  assert.equal(item.statusLabel, "Expired");
319
321
  });
322
+
323
+ it("15. live shape - the property manager is ENGAGED on the client's site: its site staff invite as the client (held, not a subcontract)", async () => {
324
+ const res = await h.api("/service-providers/invite", {
325
+ method: "POST",
326
+ sid: sid.pmStaff,
327
+ body: { email: CLEAN_EMAIL, orgId: id.pmOrg.toString(), siteId: id.siteC.toString(), siteName: "Marina Tower", inviteType: "organization-invite", app: "cleaning_services" },
328
+ });
329
+ assert.equal(res.status, 200, JSON.stringify(res.body));
330
+ const r = await h.db.collection("verifications").findOne({ email: CLEAN_EMAIL, "metadata.siteId": id.siteC });
331
+ assert.equal(r.status, "awaiting-approval");
332
+ assert.equal(r.metadata.invitedByPropertyManagement, true);
333
+ const q = await h.api("/service-provider-invitations/approvals?status=awaiting-approval", { sid: sid.admin });
334
+ const item = q.body.items.find((i) => i._id.toString() === r._id.toString());
335
+ assert.equal(item.inviterKind, "property-management");
336
+ assert.equal(item.siteOwnerName, "Marina Tower MCST");
337
+ await h.api(`/service-provider-invitations/${r._id}/approve`, { method: "PUT", sid: sid.admin });
338
+ const acc = await h.api(`/service-provider-invitations/${r._id}/accept`, { method: "PUT", sid: sid.clean, body: { org: id.cleanOrg.toString() } });
339
+ assert.equal(acc.status, 200, JSON.stringify(acc.body));
340
+ });
341
+
342
+ it("16. that property manager sees its providers (never itself) with no 'via' on its own invitation, and the people list", async () => {
343
+ const list = await h.api(`/service-providers?siteId=${id.siteC}&status=active&include=engagements&limit=50`, { sid: sid.pm });
344
+ assert.equal(list.status, 200, JSON.stringify(list.body));
345
+ assert.deepEqual(list.body.items.map((i) => i.name).sort(), ["Aigle Security", "Sparkle Cleaning"]);
346
+ assert.equal(list.body.items.find((i) => i.name === "Sparkle Cleaning").invitedVia, undefined);
347
+ const people = await h.api(`/service-providers/site-members?siteId=${id.siteC}`, { sid: sid.pm });
348
+ assert.equal(people.status, 200, JSON.stringify(people.body));
349
+ assert.deepEqual(people.body.items.map((p) => p.name), ["Gina Guard"]);
350
+ assert.equal(people.body.companies.some((c) => c.name === "Northwind Property Management"), false);
351
+ });
352
+
353
+ it("17. a provider engaged beside the property manager still subcontracts as a provider", async () => {
354
+ const res = await h.api("/service-providers/invite", {
355
+ method: "POST",
356
+ sid: sid.aigle,
357
+ body: { email: LATE_EMAIL, orgId: id.aigleOrg.toString(), siteId: id.siteC.toString(), siteName: "Marina Tower", inviteType: "organization-invite", app: "landscaping_services" },
358
+ });
359
+ assert.equal(res.status, 200, JSON.stringify(res.body));
360
+ const r = await h.db.collection("verifications").findOne({ email: LATE_EMAIL, "metadata.siteId": id.siteC });
361
+ const q = await h.api("/service-provider-invitations/approvals?status=awaiting-approval", { sid: sid.admin });
362
+ assert.equal(q.body.items.find((i) => i._id.toString() === r._id.toString()).inviterKind, "service-provider");
363
+ });
320
364
  });
321
365
 
322
366
  async function seed(h) {
@@ -328,6 +372,11 @@ async function seed(h) {
328
372
  const adminRole = o(), pmRole = o(), orgOwnerRole = o(), guardRole = o(), cleanerRole = o(), rivalRole = o();
329
373
  const siteA = o(); // One Pearl Bank - Aigle and Pestbusters engaged
330
374
  const siteB = o(); // Seventh Condominium - Aigle NOT engaged
375
+ // Live-data shape: the site is OWNED by the client (an MCST) and the property
376
+ // manager is engaged on it, exactly like a contractor.
377
+ const siteC = o(); // Marina Tower - owned by the MCST, Northwind engaged
378
+ const mcstOrg = o();
379
+ const pmStaffUser = o(), pmSiteRole = o(), guard2User = o();
331
380
 
332
381
  await h.db.collection("organizations").insertMany([
333
382
  { _id: pmOrg, name: "Northwind Property Management", email: "pm-org@sub.example.com", nature: "property_management_agency", status: "active", createdAt: now },
@@ -335,17 +384,21 @@ async function seed(h) {
335
384
  { _id: cleanOrg, name: "Sparkle Cleaning", email: CLEAN_EMAIL, nature: "cleaning_services", status: "active", createdAt: now },
336
385
  { _id: pestOrg, name: "Pestbusters", email: "pest@sub.example.com", nature: "pest_control_services", status: "active", createdAt: now },
337
386
  { _id: rivalOrg, name: "Rival Estates", email: OUTSIDER_EMAIL, nature: "property_management_agency", status: "active", createdAt: now },
387
+ { _id: mcstOrg, name: "Marina Tower MCST", email: "mcst@sub.example.com", nature: "organization", status: "active", createdAt: now },
338
388
  { _id: lateOrg, name: "Late Landscapes", email: LATE_EMAIL, nature: "landscaping_services", status: "active", createdAt: now },
339
389
  ]);
340
390
 
341
391
  await h.db.collection("sites").insertMany([
342
392
  { _id: siteA, name: "One Pearl Bank", org: pmOrg.toString(), orgId: pmOrg, status: "active", createdAt: now },
343
393
  { _id: siteB, name: "Seventh Condominium", org: pmOrg.toString(), orgId: pmOrg, status: "active", createdAt: now },
394
+ { _id: siteC, name: "Marina Tower", org: mcstOrg.toString(), orgId: mcstOrg, status: "active", createdAt: now },
344
395
  ]);
345
396
 
346
397
  await h.db.collection("customer.sites").insertMany([
347
398
  { name: "One Pearl Bank", site: siteA, siteOrg: pmOrg, siteOrgName: "Northwind Property Management", org: aigleOrg, status: "active", createdAt: now },
348
399
  { name: "One Pearl Bank", site: siteA, siteOrg: pmOrg, siteOrgName: "Northwind Property Management", org: pestOrg, status: "active", createdAt: now },
400
+ { name: "Marina Tower", site: siteC, siteOrg: mcstOrg, siteOrgName: "Marina Tower MCST", org: pmOrg, status: "active", createdAt: now },
401
+ { name: "Marina Tower", site: siteC, siteOrg: mcstOrg, siteOrgName: "Marina Tower MCST", org: aigleOrg, status: "active", createdAt: now },
349
402
  ]);
350
403
 
351
404
  const user = async (_id, email, name, defaultOrg) => ({
@@ -361,6 +414,8 @@ async function seed(h) {
361
414
  await user(adminUser, ADMIN_EMAIL, "Sasha Seven"),
362
415
  await user(outsiderUser, OUTSIDER_EMAIL, "Olive Outsider", rivalOrg),
363
416
  await user(lateUser, LATE_EMAIL, "Lee Late", lateOrg),
417
+ await user(pmStaffUser, PM_STAFF_EMAIL, "Priya Staff", pmOrg),
418
+ await user(guard2User, "guard2@aigle.example.com", "Gina Guard", aigleOrg),
364
419
  ]);
365
420
 
366
421
  await h.db.collection("roles").insertMany([
@@ -371,6 +426,7 @@ async function seed(h) {
371
426
  // a guard's vertical role pinned to the site
372
427
  { _id: guardRole, name: "Guard", type: "security_agency", org: aigleOrg.toString(), site: siteA, permissions: ["*"], status: "active" },
373
428
  { _id: cleanerRole, name: "Cleaner", type: "cleaning_services", org: cleanOrg.toString(), site: siteA, permissions: ["feedbacks.view"], status: "active" },
429
+ { _id: pmSiteRole, name: "Site Manager", type: "property_management_agency", org: pmOrg.toString(), site: siteC, permissions: ["*"], status: "active" },
374
430
  { _id: rivalRole, name: "Rival Admin", type: "property_management_agency", permissions: ["*"], status: "active" },
375
431
  ]);
376
432
 
@@ -383,7 +439,9 @@ async function seed(h) {
383
439
  { user: cleanerUser, name: "Casey Cleaner", role: cleanerRole, type: "cleaning_services", org: cleanOrg, siteId: siteA, status: "active", createdAt: now },
384
440
  { user: outsiderUser, name: "Olive Outsider", role: rivalRole, type: "property_management_agency", org: rivalOrg, status: "active", createdAt: now },
385
441
  { user: lateUser, name: "Lee Late", role: orgOwnerRole, type: "landscaping_services", org: lateOrg, status: "active", createdAt: now },
442
+ { user: pmStaffUser, name: "Priya Staff", role: pmSiteRole, type: "property_management_agency", org: pmOrg, siteId: siteC, status: "active", createdAt: now },
443
+ { user: guard2User, name: "Gina Guard", role: guardRole, type: "security_agency", org: aigleOrg, siteId: siteC, status: "active", createdAt: now },
386
444
  ]);
387
445
 
388
- return { pmOrg, aigleOrg, cleanOrg, pestOrg, lateOrg, adminUser, cleanUser, siteA, siteB };
446
+ return { pmOrg, aigleOrg, cleanOrg, pestOrg, lateOrg, mcstOrg, adminUser, cleanUser, siteA, siteB, siteC };
389
447
  }