@7365admin1/core 3.68.1 → 3.68.2

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.68.1",
4
+ "version": "3.68.2",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -0,0 +1,30 @@
1
+ /*
2
+ * A duplicate membership must read as "already a member" (400), not a 500.
3
+ *
4
+ * The live unique index on `members` is `org_1_siteId_1_user_1_type_1`; the old
5
+ * check only recognised a message naming `org_1_user_1`, so every real duplicate
6
+ * fell through as a raw MongoServerError.
7
+ */
8
+ import { strict as assert } from "node:assert";
9
+ import test from "node:test";
10
+
11
+ import { isDuplicateMemberError } from "./.build/models/member.model.mjs";
12
+
13
+ test("the live unique index's duplicate is recognised", () => {
14
+ const err = Object.assign(
15
+ new Error(
16
+ 'E11000 duplicate key error collection: iservice365.members index: org_1_siteId_1_user_1_type_1 dup key: { org: ObjectId("6a951ce603be44033d434f68") }',
17
+ ),
18
+ { code: 11000 },
19
+ );
20
+ assert.equal(isDuplicateMemberError(err), true);
21
+ });
22
+
23
+ test("a duplicate is recognised by code alone", () => {
24
+ assert.equal(isDuplicateMemberError({ code: 11000, message: "" }), true);
25
+ });
26
+
27
+ test("other errors are left alone", () => {
28
+ assert.equal(isDuplicateMemberError(new Error("connection reset")), false);
29
+ assert.equal(isDuplicateMemberError(undefined), false);
30
+ });