@talkpilot/core-db 1.3.8 → 1.3.11
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/.cursor/rules/development.mdc +65 -65
- package/DEVELOPMENT.md +141 -141
- package/README.md +287 -243
- package/README_OLD.md +160 -160
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts +34 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.statistics.aggregation.js +14 -1
- package/dist/municipal/tickets/tickets.statistics.aggregation.js.map +1 -1
- package/dist/municipal/tickets/tickets.statistics.getters.js +2 -2
- package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -1
- package/dist/municipal/tickets/tickets.types.d.ts +1 -0
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.statistics.getters.js +6 -3
- package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
- package/jest.config.js +20 -20
- package/package.json +46 -46
- package/src/connection.ts +54 -54
- package/src/index.ts +26 -26
- package/src/municipal/index.ts +22 -22
- package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +92 -92
- package/src/municipal/muniIssues/__tests__/muniIssues.setup.spec.ts +92 -92
- package/src/municipal/muniIssues/index.ts +17 -17
- package/src/municipal/muniIssues/muniIssues.constants.ts +18 -18
- package/src/municipal/muniIssues/muniIssues.getters.ts +24 -24
- package/src/municipal/muniIssues/muniIssues.schema.ts +66 -66
- package/src/municipal/muniIssues/muniIssues.setters.ts +24 -24
- package/src/municipal/muniIssues/muniIssues.setup.ts +65 -65
- package/src/municipal/muniIssues/muniIssues.types.ts +37 -37
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +30 -30
- package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +94 -68
- package/src/municipal/tickets/index.ts +3 -3
- package/src/municipal/tickets/tickets.constants.ts +8 -8
- package/src/municipal/tickets/tickets.getters.ts +121 -121
- package/src/municipal/tickets/tickets.statistics.aggregation.ts +110 -96
- package/src/municipal/tickets/tickets.statistics.getters.ts +109 -109
- package/src/municipal/tickets/tickets.types.ts +54 -53
- package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +149 -149
- package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +375 -351
- package/src/talkpilot/calls/calls.constants.ts +20 -20
- package/src/talkpilot/calls/calls.statistics.getters.ts +590 -587
- package/src/talkpilot/calls/calls.statistics.types.ts +47 -47
- package/src/talkpilot/calls/calls.types.ts +119 -119
- package/src/talkpilot/calls/dashboard/calls.dashboard.ts +292 -292
- package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +57 -57
- package/src/talkpilot/calls/index.ts +6 -6
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +190 -190
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +1 -1
- package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +176 -176
- package/src/talkpilot/contextNotes/contextNotes.getters.ts +86 -86
- package/src/talkpilot/contextNotes/contextNotes.types.ts +20 -20
- package/src/talkpilot/contextNotes/index.ts +2 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +96 -96
- package/src/talkpilot/flows/flows.schema.ts +154 -154
- package/src/talkpilot/flows/flows.types.ts +187 -187
- package/src/talkpilot/index.ts +31 -31
- package/src/talkpilot/products/__tests__/products.getters.spec.ts +45 -45
- package/src/talkpilot/products/index.ts +2 -2
- package/src/talkpilot/products/products.getters.ts +12 -12
- package/src/talkpilot/products/products.types.ts +9 -9
- package/src/test-utils/db-utils.ts +26 -26
- package/src/test-utils/factories/index.ts +15 -15
- package/src/test-utils/factories/municipal/muniIssues.ts +32 -32
- package/src/test-utils/factories/talkpilot/contextNotes.ts +33 -33
- package/src/test-utils/factories/websitalk/scans.ts +23 -23
- package/src/utils/date.utils.ts +116 -116
- package/src/websitalk/index.ts +15 -15
- package/src/websitalk/mongodb-client.ts +61 -61
- package/src/websitalk/scans/__tests__/scans.spec.ts +218 -218
- package/src/websitalk/scans/index.ts +2 -2
- package/src/websitalk/scans/scans.getters.ts +113 -113
- package/src/websitalk/scans/scans.types.ts +53 -53
- package/tsconfig.json +23 -23
- package/dist/talkpilot/calls/calls.dashboard.d.ts +0 -3
- package/dist/talkpilot/calls/calls.dashboard.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.dashboard.js +0 -191
- package/dist/talkpilot/calls/calls.dashboard.js.map +0 -1
package/jest.config.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
roots: ['<rootDir>/src'],
|
|
6
|
-
testPathIgnorePatterns: ['<rootDir>/src/__tests__/legacy/'],
|
|
7
|
-
testMatch: ['**/__tests__/**/*.spec.ts', '**/*.spec.ts'],
|
|
8
|
-
transform: {
|
|
9
|
-
'^.+\\.tsx?$': ['ts-jest', {
|
|
10
|
-
tsconfig: 'tsconfig.json',
|
|
11
|
-
}],
|
|
12
|
-
},
|
|
13
|
-
setupFilesAfterEnv: ['<rootDir>/src/__tests__/setup.ts'],
|
|
14
|
-
maxWorkers: 1,
|
|
15
|
-
verbose: true,
|
|
16
|
-
forceExit: true,
|
|
17
|
-
clearMocks: true,
|
|
18
|
-
resetMocks: true,
|
|
19
|
-
restoreMocks: true,
|
|
20
|
-
};
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
preset: 'ts-jest',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
roots: ['<rootDir>/src'],
|
|
6
|
+
testPathIgnorePatterns: ['<rootDir>/src/__tests__/legacy/'],
|
|
7
|
+
testMatch: ['**/__tests__/**/*.spec.ts', '**/*.spec.ts'],
|
|
8
|
+
transform: {
|
|
9
|
+
'^.+\\.tsx?$': ['ts-jest', {
|
|
10
|
+
tsconfig: 'tsconfig.json',
|
|
11
|
+
}],
|
|
12
|
+
},
|
|
13
|
+
setupFilesAfterEnv: ['<rootDir>/src/__tests__/setup.ts'],
|
|
14
|
+
maxWorkers: 1,
|
|
15
|
+
verbose: true,
|
|
16
|
+
forceExit: true,
|
|
17
|
+
clearMocks: true,
|
|
18
|
+
resetMocks: true,
|
|
19
|
+
restoreMocks: true,
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@talkpilot/core-db",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "Core database package for centralized connections and ORM integration.",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"dev": "tsc --watch",
|
|
10
|
-
"test": "jest",
|
|
11
|
-
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
12
|
-
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
13
|
-
"prepare": "npm run build"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"database",
|
|
17
|
-
"orm",
|
|
18
|
-
"typescript",
|
|
19
|
-
"postgres",
|
|
20
|
-
"db-client"
|
|
21
|
-
],
|
|
22
|
-
"author": "",
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"dayjs": "^1.11.21",
|
|
26
|
-
"express": "^4.18.0",
|
|
27
|
-
"google-libphonenumber": "^3.2.0",
|
|
28
|
-
"mongodb": "^6.11.0"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@faker-js/faker": "^8.0.0",
|
|
32
|
-
"@types/express": "^4.17.0",
|
|
33
|
-
"@types/google-libphonenumber": "^7.4.0",
|
|
34
|
-
"@types/jest": "^29.0.0",
|
|
35
|
-
"@types/node": "^20.0.0",
|
|
36
|
-
"fishery": "^2.4.0",
|
|
37
|
-
"jest": "^29.0.0",
|
|
38
|
-
"mongodb-memory-server": "^10.0.0",
|
|
39
|
-
"prettier": "^3.8.2",
|
|
40
|
-
"ts-jest": "^29.0.0",
|
|
41
|
-
"typescript": "^5.0.0"
|
|
42
|
-
},
|
|
43
|
-
"publishConfig": {
|
|
44
|
-
"access": "public"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@talkpilot/core-db",
|
|
3
|
+
"version": "1.3.11",
|
|
4
|
+
"description": "Core database package for centralized connections and ORM integration.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"dev": "tsc --watch",
|
|
10
|
+
"test": "jest",
|
|
11
|
+
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
12
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
13
|
+
"prepare": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"database",
|
|
17
|
+
"orm",
|
|
18
|
+
"typescript",
|
|
19
|
+
"postgres",
|
|
20
|
+
"db-client"
|
|
21
|
+
],
|
|
22
|
+
"author": "",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"dayjs": "^1.11.21",
|
|
26
|
+
"express": "^4.18.0",
|
|
27
|
+
"google-libphonenumber": "^3.2.0",
|
|
28
|
+
"mongodb": "^6.11.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@faker-js/faker": "^8.0.0",
|
|
32
|
+
"@types/express": "^4.17.0",
|
|
33
|
+
"@types/google-libphonenumber": "^7.4.0",
|
|
34
|
+
"@types/jest": "^29.0.0",
|
|
35
|
+
"@types/node": "^20.0.0",
|
|
36
|
+
"fishery": "^2.4.0",
|
|
37
|
+
"jest": "^29.0.0",
|
|
38
|
+
"mongodb-memory-server": "^10.0.0",
|
|
39
|
+
"prettier": "^3.8.2",
|
|
40
|
+
"ts-jest": "^29.0.0",
|
|
41
|
+
"typescript": "^5.0.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/connection.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { mongodbClient } from "./talkpilot";
|
|
2
|
-
import { municipalDataMongodbClient } from "./municipal";
|
|
3
|
-
import { websitalkMongodbClient } from "./websitalk";
|
|
4
|
-
|
|
5
|
-
let isConnected = false;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Ensures the database clients are initialized.
|
|
9
|
-
* This function reads from MONGO_URI.
|
|
10
|
-
*/
|
|
11
|
-
export async function ensureDbConnected() {
|
|
12
|
-
if (isConnected) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const mongoUri = process.env.MONGO_URI || process.env.MONGODB_URI;
|
|
17
|
-
const talkpilotUri = mongoUri;
|
|
18
|
-
const municipalUri = mongoUri;
|
|
19
|
-
const websiteTalkUri = mongoUri;
|
|
20
|
-
|
|
21
|
-
if (!talkpilotUri) {
|
|
22
|
-
console.warn("[core-db] MONGO_URI is not set");
|
|
23
|
-
} else {
|
|
24
|
-
const dbNameFromUri = talkpilotUri.split("/").pop()?.split("?")[0];
|
|
25
|
-
const dbName = dbNameFromUri || process.env.TALKPILOT_DB_NAME;
|
|
26
|
-
await mongodbClient.connect(talkpilotUri, dbName);
|
|
27
|
-
console.info(
|
|
28
|
-
`[core-db] Connected to TalkPilot MongoDB: ${dbName || "via env"}`,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!municipalUri) {
|
|
33
|
-
console.warn("[core-db] MONGO_URI is not set");
|
|
34
|
-
} else {
|
|
35
|
-
const dbNameFromUri = municipalUri.split("/").pop()?.split("?")[0];
|
|
36
|
-
const dbName = dbNameFromUri || process.env.MUNICIPAL_DB_NAME;
|
|
37
|
-
await municipalDataMongodbClient.connect(municipalUri, dbName);
|
|
38
|
-
console.info(
|
|
39
|
-
`[core-db] Connected to Municipal Data MongoDB: ${dbName || "via env"}`,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!websiteTalkUri) {
|
|
44
|
-
console.warn("[core-db] MONGO_URI is not set");
|
|
45
|
-
} else {
|
|
46
|
-
const dbName = process.env.WEBSITALK_DB_NAME;
|
|
47
|
-
await websitalkMongodbClient.connect(websiteTalkUri, dbName);
|
|
48
|
-
console.info(
|
|
49
|
-
`[core-db] Connected to Website Talk MongoDB: ${dbName || "website-talk (default)"}`,
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
isConnected = true;
|
|
54
|
-
}
|
|
1
|
+
import { mongodbClient } from "./talkpilot";
|
|
2
|
+
import { municipalDataMongodbClient } from "./municipal";
|
|
3
|
+
import { websitalkMongodbClient } from "./websitalk";
|
|
4
|
+
|
|
5
|
+
let isConnected = false;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Ensures the database clients are initialized.
|
|
9
|
+
* This function reads from MONGO_URI.
|
|
10
|
+
*/
|
|
11
|
+
export async function ensureDbConnected() {
|
|
12
|
+
if (isConnected) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const mongoUri = process.env.MONGO_URI || process.env.MONGODB_URI;
|
|
17
|
+
const talkpilotUri = mongoUri;
|
|
18
|
+
const municipalUri = mongoUri;
|
|
19
|
+
const websiteTalkUri = mongoUri;
|
|
20
|
+
|
|
21
|
+
if (!talkpilotUri) {
|
|
22
|
+
console.warn("[core-db] MONGO_URI is not set");
|
|
23
|
+
} else {
|
|
24
|
+
const dbNameFromUri = talkpilotUri.split("/").pop()?.split("?")[0];
|
|
25
|
+
const dbName = dbNameFromUri || process.env.TALKPILOT_DB_NAME;
|
|
26
|
+
await mongodbClient.connect(talkpilotUri, dbName);
|
|
27
|
+
console.info(
|
|
28
|
+
`[core-db] Connected to TalkPilot MongoDB: ${dbName || "via env"}`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!municipalUri) {
|
|
33
|
+
console.warn("[core-db] MONGO_URI is not set");
|
|
34
|
+
} else {
|
|
35
|
+
const dbNameFromUri = municipalUri.split("/").pop()?.split("?")[0];
|
|
36
|
+
const dbName = dbNameFromUri || process.env.MUNICIPAL_DB_NAME;
|
|
37
|
+
await municipalDataMongodbClient.connect(municipalUri, dbName);
|
|
38
|
+
console.info(
|
|
39
|
+
`[core-db] Connected to Municipal Data MongoDB: ${dbName || "via env"}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!websiteTalkUri) {
|
|
44
|
+
console.warn("[core-db] MONGO_URI is not set");
|
|
45
|
+
} else {
|
|
46
|
+
const dbName = process.env.WEBSITALK_DB_NAME;
|
|
47
|
+
await websitalkMongodbClient.connect(websiteTalkUri, dbName);
|
|
48
|
+
console.info(
|
|
49
|
+
`[core-db] Connected to Website Talk MongoDB: ${dbName || "website-talk (default)"}`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
isConnected = true;
|
|
54
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
// TalkPilot DB exports
|
|
2
|
-
export * from "./talkpilot";
|
|
3
|
-
export * from "./connection";
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
municipalDataMongodbClient,
|
|
7
|
-
getDb as getMunicipalDataDb,
|
|
8
|
-
setDb as setMunicipalDataDb,
|
|
9
|
-
ObjectId as MunicipalDataObjectId,
|
|
10
|
-
} from "./municipal";
|
|
11
|
-
export * from "./municipal/cities";
|
|
12
|
-
export * from "./municipal/streets";
|
|
13
|
-
export * from "./municipal/departmentsSubjects";
|
|
14
|
-
export * from "./municipal/tickets";
|
|
15
|
-
export * from "./municipal/systemInstructions";
|
|
16
|
-
export * from "./municipal/muniIssues";
|
|
17
|
-
export * from "./municipal/utils/types";
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
websitalkMongodbClient,
|
|
21
|
-
getDb as getWebsitalkDb,
|
|
22
|
-
setDb as setWebsitalkDb,
|
|
23
|
-
ObjectId as WebsitalkObjectId,
|
|
24
|
-
} from "./websitalk";
|
|
25
|
-
export * from "./websitalk/scans/scans.getters";
|
|
26
|
-
export type * from "./websitalk/scans/scans.types";
|
|
1
|
+
// TalkPilot DB exports
|
|
2
|
+
export * from "./talkpilot";
|
|
3
|
+
export * from "./connection";
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
municipalDataMongodbClient,
|
|
7
|
+
getDb as getMunicipalDataDb,
|
|
8
|
+
setDb as setMunicipalDataDb,
|
|
9
|
+
ObjectId as MunicipalDataObjectId,
|
|
10
|
+
} from "./municipal";
|
|
11
|
+
export * from "./municipal/cities";
|
|
12
|
+
export * from "./municipal/streets";
|
|
13
|
+
export * from "./municipal/departmentsSubjects";
|
|
14
|
+
export * from "./municipal/tickets";
|
|
15
|
+
export * from "./municipal/systemInstructions";
|
|
16
|
+
export * from "./municipal/muniIssues";
|
|
17
|
+
export * from "./municipal/utils/types";
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
websitalkMongodbClient,
|
|
21
|
+
getDb as getWebsitalkDb,
|
|
22
|
+
setDb as setWebsitalkDb,
|
|
23
|
+
ObjectId as WebsitalkObjectId,
|
|
24
|
+
} from "./websitalk";
|
|
25
|
+
export * from "./websitalk/scans/scans.getters";
|
|
26
|
+
export type * from "./websitalk/scans/scans.types";
|
package/src/municipal/index.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Db, ObjectId as MongoObjectId } from "mongodb";
|
|
2
|
-
|
|
3
|
-
export * from "./cities";
|
|
4
|
-
export * from "./streets";
|
|
5
|
-
export * from "./departmentsSubjects";
|
|
6
|
-
export * from "./tickets";
|
|
7
|
-
export * from "./systemInstructions";
|
|
8
|
-
export * from "./muniIssues";
|
|
9
|
-
export * from "./utils/types";
|
|
10
|
-
export { CityName } from "./utils/types";
|
|
11
|
-
export { municipalDataMongodbClient } from "./mongodb-client";
|
|
12
|
-
|
|
13
|
-
let db: Db;
|
|
14
|
-
export const setDb = (d: Db) => {
|
|
15
|
-
db = d;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const getDb = (): Db => {
|
|
19
|
-
if (!db) throw new Error("Municipal Data DB not initialised");
|
|
20
|
-
return db;
|
|
21
|
-
};
|
|
22
|
-
export const ObjectId = MongoObjectId;
|
|
1
|
+
import { Db, ObjectId as MongoObjectId } from "mongodb";
|
|
2
|
+
|
|
3
|
+
export * from "./cities";
|
|
4
|
+
export * from "./streets";
|
|
5
|
+
export * from "./departmentsSubjects";
|
|
6
|
+
export * from "./tickets";
|
|
7
|
+
export * from "./systemInstructions";
|
|
8
|
+
export * from "./muniIssues";
|
|
9
|
+
export * from "./utils/types";
|
|
10
|
+
export { CityName } from "./utils/types";
|
|
11
|
+
export { municipalDataMongodbClient } from "./mongodb-client";
|
|
12
|
+
|
|
13
|
+
let db: Db;
|
|
14
|
+
export const setDb = (d: Db) => {
|
|
15
|
+
db = d;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const getDb = (): Db => {
|
|
19
|
+
if (!db) throw new Error("Municipal Data DB not initialised");
|
|
20
|
+
return db;
|
|
21
|
+
};
|
|
22
|
+
export const ObjectId = MongoObjectId;
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import { createMuniIssue } from "../muniIssues.setters";
|
|
2
|
-
import {
|
|
3
|
-
generateMuniIssueId,
|
|
4
|
-
getMuniIssueById,
|
|
5
|
-
getMuniIssueByJiraKey,
|
|
6
|
-
} from "../muniIssues.getters";
|
|
7
|
-
import { createMuniIssueInput } from "../../../test-utils/factories";
|
|
8
|
-
|
|
9
|
-
describe("muniIssues setters", () => {
|
|
10
|
-
describe("createMuniIssue", () => {
|
|
11
|
-
it("should insert a well-formed document with createdAt and nested content/jira", async () => {
|
|
12
|
-
const input = createMuniIssueInput();
|
|
13
|
-
const id = generateMuniIssueId();
|
|
14
|
-
|
|
15
|
-
const insertedId = await createMuniIssue(input, id);
|
|
16
|
-
|
|
17
|
-
const saved = await getMuniIssueById(insertedId.toString());
|
|
18
|
-
expect(saved).toMatchObject({
|
|
19
|
-
callSid: input.callSid,
|
|
20
|
-
clientId: input.clientId,
|
|
21
|
-
cityName: input.cityName,
|
|
22
|
-
issueContent: input.issueContent,
|
|
23
|
-
jira: input.jira,
|
|
24
|
-
});
|
|
25
|
-
expect(saved?.createdAt).toBeInstanceOf(Date);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("should default jira.syncStatus to created when not provided", async () => {
|
|
29
|
-
const id = generateMuniIssueId();
|
|
30
|
-
|
|
31
|
-
const insertedId = await createMuniIssue(
|
|
32
|
-
createMuniIssueInput({ jira: { key: "CP-9" } }),
|
|
33
|
-
id,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const saved = await getMuniIssueById(insertedId.toString());
|
|
37
|
-
expect(saved?.jira.syncStatus).toBe("created");
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("should store long issueDescription and desiredBehavior in full", async () => {
|
|
41
|
-
const issueDescription = "a".repeat(2000);
|
|
42
|
-
const desiredBehavior = "b".repeat(2000);
|
|
43
|
-
const id = generateMuniIssueId();
|
|
44
|
-
|
|
45
|
-
const insertedId = await createMuniIssue(
|
|
46
|
-
createMuniIssueInput({
|
|
47
|
-
issueContent: {
|
|
48
|
-
issuerName: "Dana",
|
|
49
|
-
issuerRole: "Agent",
|
|
50
|
-
issueDescription,
|
|
51
|
-
desiredBehavior,
|
|
52
|
-
},
|
|
53
|
-
}),
|
|
54
|
-
id,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const saved = await getMuniIssueById(insertedId.toString());
|
|
58
|
-
expect(saved?.issueContent.issueDescription).toHaveLength(2000);
|
|
59
|
-
expect(saved?.issueContent.desiredBehavior).toBe(desiredBehavior);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should persist the caller-supplied _id so the Jira ticket can link back", async () => {
|
|
63
|
-
const id = generateMuniIssueId();
|
|
64
|
-
|
|
65
|
-
const insertedId = await createMuniIssue(createMuniIssueInput(), id);
|
|
66
|
-
|
|
67
|
-
expect(insertedId.toString()).toBe(id.toString());
|
|
68
|
-
expect(await getMuniIssueById(id.toString())).not.toBeNull();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("getMuniIssueById", () => {
|
|
73
|
-
it("should return null for an unknown or malformed id instead of throwing", async () => {
|
|
74
|
-
expect(await getMuniIssueById(generateMuniIssueId().toString())).toBeNull();
|
|
75
|
-
expect(await getMuniIssueById("not-a-valid-id")).toBeNull();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("getMuniIssueByJiraKey", () => {
|
|
80
|
-
it("should find the issue with the given Jira key", async () => {
|
|
81
|
-
await createMuniIssue(
|
|
82
|
-
createMuniIssueInput({ jira: { key: "CP-555" } }),
|
|
83
|
-
generateMuniIssueId(),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const found = await getMuniIssueByJiraKey("CP-555");
|
|
87
|
-
|
|
88
|
-
expect(found?.jira.key).toBe("CP-555");
|
|
89
|
-
expect(await getMuniIssueByJiraKey("CP-nope")).toBeNull();
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
1
|
+
import { createMuniIssue } from "../muniIssues.setters";
|
|
2
|
+
import {
|
|
3
|
+
generateMuniIssueId,
|
|
4
|
+
getMuniIssueById,
|
|
5
|
+
getMuniIssueByJiraKey,
|
|
6
|
+
} from "../muniIssues.getters";
|
|
7
|
+
import { createMuniIssueInput } from "../../../test-utils/factories";
|
|
8
|
+
|
|
9
|
+
describe("muniIssues setters", () => {
|
|
10
|
+
describe("createMuniIssue", () => {
|
|
11
|
+
it("should insert a well-formed document with createdAt and nested content/jira", async () => {
|
|
12
|
+
const input = createMuniIssueInput();
|
|
13
|
+
const id = generateMuniIssueId();
|
|
14
|
+
|
|
15
|
+
const insertedId = await createMuniIssue(input, id);
|
|
16
|
+
|
|
17
|
+
const saved = await getMuniIssueById(insertedId.toString());
|
|
18
|
+
expect(saved).toMatchObject({
|
|
19
|
+
callSid: input.callSid,
|
|
20
|
+
clientId: input.clientId,
|
|
21
|
+
cityName: input.cityName,
|
|
22
|
+
issueContent: input.issueContent,
|
|
23
|
+
jira: input.jira,
|
|
24
|
+
});
|
|
25
|
+
expect(saved?.createdAt).toBeInstanceOf(Date);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should default jira.syncStatus to created when not provided", async () => {
|
|
29
|
+
const id = generateMuniIssueId();
|
|
30
|
+
|
|
31
|
+
const insertedId = await createMuniIssue(
|
|
32
|
+
createMuniIssueInput({ jira: { key: "CP-9" } }),
|
|
33
|
+
id,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const saved = await getMuniIssueById(insertedId.toString());
|
|
37
|
+
expect(saved?.jira.syncStatus).toBe("created");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should store long issueDescription and desiredBehavior in full", async () => {
|
|
41
|
+
const issueDescription = "a".repeat(2000);
|
|
42
|
+
const desiredBehavior = "b".repeat(2000);
|
|
43
|
+
const id = generateMuniIssueId();
|
|
44
|
+
|
|
45
|
+
const insertedId = await createMuniIssue(
|
|
46
|
+
createMuniIssueInput({
|
|
47
|
+
issueContent: {
|
|
48
|
+
issuerName: "Dana",
|
|
49
|
+
issuerRole: "Agent",
|
|
50
|
+
issueDescription,
|
|
51
|
+
desiredBehavior,
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
id,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const saved = await getMuniIssueById(insertedId.toString());
|
|
58
|
+
expect(saved?.issueContent.issueDescription).toHaveLength(2000);
|
|
59
|
+
expect(saved?.issueContent.desiredBehavior).toBe(desiredBehavior);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should persist the caller-supplied _id so the Jira ticket can link back", async () => {
|
|
63
|
+
const id = generateMuniIssueId();
|
|
64
|
+
|
|
65
|
+
const insertedId = await createMuniIssue(createMuniIssueInput(), id);
|
|
66
|
+
|
|
67
|
+
expect(insertedId.toString()).toBe(id.toString());
|
|
68
|
+
expect(await getMuniIssueById(id.toString())).not.toBeNull();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("getMuniIssueById", () => {
|
|
73
|
+
it("should return null for an unknown or malformed id instead of throwing", async () => {
|
|
74
|
+
expect(await getMuniIssueById(generateMuniIssueId().toString())).toBeNull();
|
|
75
|
+
expect(await getMuniIssueById("not-a-valid-id")).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("getMuniIssueByJiraKey", () => {
|
|
80
|
+
it("should find the issue with the given Jira key", async () => {
|
|
81
|
+
await createMuniIssue(
|
|
82
|
+
createMuniIssueInput({ jira: { key: "CP-555" } }),
|
|
83
|
+
generateMuniIssueId(),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const found = await getMuniIssueByJiraKey("CP-555");
|
|
87
|
+
|
|
88
|
+
expect(found?.jira.key).toBe("CP-555");
|
|
89
|
+
expect(await getMuniIssueByJiraKey("CP-nope")).toBeNull();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|