@tenonhq/dovetail-core 0.0.134 → 0.0.135
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/dist/FileUtils.js +7 -0
- package/dist/createRecordCommand.js +18 -2
- package/dist/deleteRecordCommand.js +45 -20
- package/dist/fingerprint.js +40 -2
- package/dist/recordFolder.js +86 -0
- package/dist/snClient.js +5 -2
- package/dist/tests/createRecordLocalPath.test.js +145 -0
- package/dist/tests/deleteRecordLocalCleanup.test.js +153 -24
- package/dist/tests/fileContextSkipReason.test.js +41 -0
- package/dist/tests/fingerprint.test.js +37 -0
- package/dist/tests/pushFingerprintedField.test.js +64 -0
- package/dist/tests/recordFolder.test.js +57 -0
- package/dist/tests/snClient.fingerprint.test.js +20 -0
- package/package.json +1 -1
- package/release-manifest.json +310 -326
- package/skills/dove-delete-record.md +2 -2
package/dist/FileUtils.js
CHANGED
|
@@ -254,6 +254,13 @@ const getFileContextWithSkipReason = (filePath) => {
|
|
|
254
254
|
if (!field) {
|
|
255
255
|
return { skipReason: "not in manifest" };
|
|
256
256
|
}
|
|
257
|
+
// The field is mirrored as a fingerprint, so no file on disk holds its
|
|
258
|
+
// content: a `script.js` beside a fingerprinted `script` is stale (left
|
|
259
|
+
// from before `fingerprint` was set; refresh never deletes) and pushing
|
|
260
|
+
// it would write an old bundle over the live one.
|
|
261
|
+
if (field.type === fingerprint_1.FINGERPRINT_FILE_TYPE) {
|
|
262
|
+
return { skipReason: "fingerprinted field, read-only" };
|
|
263
|
+
}
|
|
257
264
|
return {
|
|
258
265
|
context: {
|
|
259
266
|
filePath,
|
|
@@ -50,6 +50,7 @@ const commands_1 = require("./commands");
|
|
|
50
50
|
const ConfigManager = __importStar(require("./config"));
|
|
51
51
|
const AppUtils = __importStar(require("./appUtils"));
|
|
52
52
|
const projectFiles_1 = require("./projectFiles");
|
|
53
|
+
const recordFolder_1 = require("./recordFolder");
|
|
53
54
|
/**
|
|
54
55
|
* Table whose rows must NOT go through the generic record insert. A plain
|
|
55
56
|
* insert lets ServiceNow default `application` to the API session's current
|
|
@@ -560,9 +561,24 @@ async function createRecordCommand(args) {
|
|
|
560
561
|
// getSourcePathForScope(scope), which a scope config can override. Using
|
|
561
562
|
// the top-level getSourcePath() here would print a wrong path in
|
|
562
563
|
// multi-scope setups even though the files landed correctly.
|
|
564
|
+
//
|
|
565
|
+
// The folder is the record's key in the manifest the sync just wrote,
|
|
566
|
+
// found by sys_id, not its display name: a namesake or letter-case
|
|
567
|
+
// twin gets a suffixed folder (folderNaming.ts), and the bare name
|
|
568
|
+
// would point at the other record's folder.
|
|
563
569
|
var sourcePath = ConfigManager.getSourcePathForScope(scope);
|
|
564
|
-
var
|
|
565
|
-
|
|
570
|
+
var syncedManifest = await ConfigManager.loadScopeManifest(scope);
|
|
571
|
+
var folders = (0, recordFolder_1.recordFoldersBySysId)(syncedManifest, table, newSysId);
|
|
572
|
+
var localPath = folders.length === 1 ? (0, recordFolder_1.recordDirFor)(sourcePath, table, folders[0]) : undefined;
|
|
573
|
+
if (localPath !== undefined) {
|
|
574
|
+
Logger_1.logger.success(chalk_1.default.green("Local files created at: ") + localPath);
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
// syncManifest has already warned when the record is not in the
|
|
578
|
+
// refreshed manifest; never print a path the files may not be at.
|
|
579
|
+
FileLogger_1.fileLogger.debug("Created record " + newSysId + " has " + folders.length +
|
|
580
|
+
" folder(s) in the " + scope + " manifest for " + table + "; no local path printed");
|
|
581
|
+
}
|
|
566
582
|
}
|
|
567
583
|
}
|
|
568
584
|
catch (syncErr) {
|
|
@@ -47,6 +47,7 @@ const FileLogger_1 = require("./FileLogger");
|
|
|
47
47
|
const commands_1 = require("./commands");
|
|
48
48
|
const ConfigManager = __importStar(require("./config"));
|
|
49
49
|
const FileUtils = __importStar(require("./FileUtils"));
|
|
50
|
+
const recordFolder_1 = require("./recordFolder");
|
|
50
51
|
/**
|
|
51
52
|
* Resolves the target scope from args, manifest, or user prompt.
|
|
52
53
|
*/
|
|
@@ -226,28 +227,52 @@ async function deleteRecordCommand(args) {
|
|
|
226
227
|
if (!typedArgs.keepLocal) {
|
|
227
228
|
Logger_1.logger.info("Cleaning up local files...");
|
|
228
229
|
try {
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
230
|
+
// The record's folder is its manifest key, found by sys_id: the
|
|
231
|
+
// manifest is the naming authority (folderNaming.ts). A folder built
|
|
232
|
+
// from the instance's display name is wrong for every record the
|
|
233
|
+
// naming rule renamed, and is ANOTHER record's folder when a local
|
|
234
|
+
// namesake exists and this one was never refreshed.
|
|
235
|
+
var manifest = await ConfigManager.loadScopeManifest(scope);
|
|
236
|
+
var folderSource = manifest;
|
|
237
|
+
if (!folderSource) {
|
|
238
|
+
// A project without per-scope manifests keeps one dove.manifest.json.
|
|
239
|
+
var loadedManifest = ConfigManager.getManifest(true);
|
|
240
|
+
folderSource = loadedManifest
|
|
241
|
+
? ConfigManager.resolveManifestForScope(loadedManifest, scope)
|
|
242
|
+
: undefined;
|
|
238
243
|
}
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
var folders = (0, recordFolder_1.recordFoldersBySysId)(folderSource, table, sysId);
|
|
245
|
+
if (folders.length === 0) {
|
|
246
|
+
Logger_1.logger.warn("Record " + sysId + " is not in the " + scope + " manifest for " + table +
|
|
247
|
+
", so no local folder was removed. Remove its folder by hand if it has one.");
|
|
241
248
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
else if (folders.length > 1) {
|
|
250
|
+
Logger_1.logger.warn("Record " + sysId + " is listed more than once in the " + scope + " manifest for " + table +
|
|
251
|
+
" (" + folders.join(", ") + "), so no local folder was removed. Run 'npx dove refresh' and check the folders by hand.");
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
var folder = folders[0];
|
|
255
|
+
// Records live at <scope dir>/<table>/<folder> (src/Core/...,
|
|
256
|
+
// src/UIComponents/<scope>/...), not under the top-level
|
|
257
|
+
// sourceDirectory. recordDirFor refuses anything that is not a direct
|
|
258
|
+
// child of <scope dir>/<table>, so a folder or table such as ".."
|
|
259
|
+
// can never point the recursive delete at the scope folder.
|
|
260
|
+
var sourcePath = ConfigManager.getSourcePathForScope(scope);
|
|
261
|
+
var recordDir = (0, recordFolder_1.recordDirFor)(sourcePath, table, folder);
|
|
262
|
+
if (recordDir === undefined) {
|
|
263
|
+
Logger_1.logger.warn("Not removing '" + folder + "': it is not a record folder under " +
|
|
264
|
+
path_1.default.join(sourcePath, table) + ".");
|
|
265
|
+
}
|
|
266
|
+
else if (fs_1.default.existsSync(recordDir)) {
|
|
267
|
+
fs_1.default.rmSync(recordDir, { recursive: true, force: true });
|
|
268
|
+
Logger_1.logger.success(chalk_1.default.green("Removed: ") + recordDir);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
FileLogger_1.fileLogger.debug("Local directory not found: " + recordDir);
|
|
272
|
+
}
|
|
273
|
+
// Update the scope manifest: drop the entry this sys_id owns, and no other.
|
|
274
|
+
if (manifest && manifest.tables && manifest.tables[table] && manifest.tables[table].records) {
|
|
275
|
+
delete manifest.tables[table].records[folder];
|
|
251
276
|
// Remove table entry if no records remain
|
|
252
277
|
if (Object.keys(manifest.tables[table].records).length === 0) {
|
|
253
278
|
delete manifest.tables[table];
|
package/dist/fingerprint.js
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
// - the field file's content becomes "sha256:<hex>\nbytes:<n>\n";
|
|
19
19
|
// - the field's value in metaData.json becomes "sha256:<hex>".
|
|
20
20
|
// Push refuses a `.sha256` file (FileUtils.getFileContextWithSkipReason), so a
|
|
21
|
-
// digest can never be written back over a bundle
|
|
21
|
+
// digest can never be written back over a bundle, and any other file of a
|
|
22
|
+
// fingerprinted field (a stale `script.js` from before the option was set).
|
|
22
23
|
//
|
|
23
24
|
// Client-side only: `fingerprint` is stripped from tableOptions before they are
|
|
24
25
|
// sent to the instance. The server echoes the requested file type back, so a
|
|
@@ -28,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
30
|
};
|
|
30
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.isFingerprintFilePath = exports.applyFingerprints = exports.stripClientOnlyTableOptions = exports.fingerprintFieldsFor = exports.isFingerprintContent = exports.formatFingerprint = exports.FINGERPRINT_FILE_TYPE = void 0;
|
|
32
|
+
exports.isFingerprintFilePath = exports.applyFingerprints = exports.stripClientOnlyTableOptions = exports.checkFingerprintOptions = exports.fingerprintFieldsFor = exports.isFingerprintContent = exports.formatFingerprint = exports.FINGERPRINT_FILE_TYPE = void 0;
|
|
32
33
|
const crypto_1 = __importDefault(require("crypto"));
|
|
33
34
|
exports.FINGERPRINT_FILE_TYPE = "sha256";
|
|
34
35
|
const DIGEST_PREFIX = "sha256:";
|
|
@@ -45,6 +46,7 @@ exports.isFingerprintContent = isFingerprintContent;
|
|
|
45
46
|
// Fields configured for fingerprinting on one table. Anything malformed in the
|
|
46
47
|
// config (not an array, non-string or empty entries) is dropped rather than
|
|
47
48
|
// trusted, so a typo fingerprints nothing instead of throwing mid-refresh.
|
|
49
|
+
// checkFingerprintOptions reports what was dropped.
|
|
48
50
|
const fingerprintFieldsFor = (tableOptions, tableName) => {
|
|
49
51
|
if (!isPlainObject(tableOptions))
|
|
50
52
|
return [];
|
|
@@ -64,6 +66,42 @@ const fingerprintFieldsFor = (tableOptions, tableName) => {
|
|
|
64
66
|
return fields;
|
|
65
67
|
};
|
|
66
68
|
exports.fingerprintFieldsFor = fingerprintFieldsFor;
|
|
69
|
+
// An entry fingerprintFieldsFor would use as is. One with surrounding spaces is
|
|
70
|
+
// kept there but can never equal a field name, so it is reported here too.
|
|
71
|
+
const isFieldName = (f) => typeof f === "string" && f.trim() !== "" && f.trim() === f;
|
|
72
|
+
/**
|
|
73
|
+
* Reports through `warn` every `fingerprint` option that does not fingerprint
|
|
74
|
+
* what it names: a value that is not an array (`fingerprint: "script"`), or
|
|
75
|
+
* entries that are not field names. Without this the option is dropped
|
|
76
|
+
* silently and the next refresh writes, and a commit carries, the full bundle:
|
|
77
|
+
* the outcome the option exists to prevent. Matches layoutElementTablesFor's
|
|
78
|
+
* warning. An empty array, like an absent option, means off and is not reported.
|
|
79
|
+
*/
|
|
80
|
+
const checkFingerprintOptions = (tableOptions, warn) => {
|
|
81
|
+
if (!isPlainObject(tableOptions))
|
|
82
|
+
return;
|
|
83
|
+
const tables = Object.keys(tableOptions).sort();
|
|
84
|
+
for (let i = 0; i < tables.length; i++) {
|
|
85
|
+
const opts = tableOptions[tables[i]];
|
|
86
|
+
if (!isPlainObject(opts) || !("fingerprint" in opts) || opts.fingerprint === undefined)
|
|
87
|
+
continue;
|
|
88
|
+
const raw = opts.fingerprint;
|
|
89
|
+
if (!Array.isArray(raw)) {
|
|
90
|
+
warn("tableOptions." + tables[i] + ".fingerprint is ignored: it must be an array of field names, e.g. [\"script\"]");
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const bad = [];
|
|
94
|
+
for (let j = 0; j < raw.length; j++) {
|
|
95
|
+
if (!isFieldName(raw[j]))
|
|
96
|
+
bad.push(String(JSON.stringify(raw[j])));
|
|
97
|
+
}
|
|
98
|
+
if (bad.length > 0) {
|
|
99
|
+
warn("tableOptions." + tables[i] + ".fingerprint ignores " + bad.join(", ") +
|
|
100
|
+
": each entry must be a field name, e.g. \"script\"");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
exports.checkFingerprintOptions = checkFingerprintOptions;
|
|
67
105
|
// A copy of tableOptions without the client-only keys (`fingerprint`, and
|
|
68
106
|
// `layoutElements` from layoutElements.ts), for the request body. The input is
|
|
69
107
|
// never mutated: the caller keeps using it to apply them to the response.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Where a record lives on disk, read from the scope manifest.
|
|
4
|
+
*
|
|
5
|
+
* A manifest key IS the record's folder name (appUtils.normalizeManifestKeys,
|
|
6
|
+
* folderNaming.ts), so a command that knows a record's sys_id and needs its
|
|
7
|
+
* folder looks the key up by sys_id. Building the folder from the instance's
|
|
8
|
+
* display name instead is wrong for every record the naming rule renamed
|
|
9
|
+
* (namesakes, letter-case twins, unsafe names, nameTemplate tables), and points
|
|
10
|
+
* at ANOTHER record's folder when a local namesake exists and the record in
|
|
11
|
+
* hand has not been refreshed yet.
|
|
12
|
+
*/
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.recordDirFor = exports.recordFoldersBySysId = void 0;
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
/**
|
|
20
|
+
* Every manifest key in `table` whose record has this sys_id. Normally zero or
|
|
21
|
+
* one; more than one means a hand-edited or corrupt manifest, and a caller
|
|
22
|
+
* about to delete something should treat it as "unknown".
|
|
23
|
+
*/
|
|
24
|
+
const recordFoldersBySysId = (manifest, table, sysId) => {
|
|
25
|
+
const out = [];
|
|
26
|
+
if (!manifest || typeof manifest !== "object")
|
|
27
|
+
return out;
|
|
28
|
+
if (typeof table !== "string" || table === "")
|
|
29
|
+
return out;
|
|
30
|
+
if (typeof sysId !== "string" || sysId === "")
|
|
31
|
+
return out;
|
|
32
|
+
const tables = manifest.tables;
|
|
33
|
+
if (!tables || typeof tables !== "object")
|
|
34
|
+
return out;
|
|
35
|
+
if (!Object.prototype.hasOwnProperty.call(tables, table))
|
|
36
|
+
return out;
|
|
37
|
+
const tableEntry = tables[table];
|
|
38
|
+
if (!tableEntry || typeof tableEntry !== "object")
|
|
39
|
+
return out;
|
|
40
|
+
const records = tableEntry.records;
|
|
41
|
+
if (!records || typeof records !== "object")
|
|
42
|
+
return out;
|
|
43
|
+
const keys = Object.keys(records);
|
|
44
|
+
for (let i = 0; i < keys.length; i++) {
|
|
45
|
+
const record = records[keys[i]];
|
|
46
|
+
if (record && typeof record === "object" && record.sys_id === sysId) {
|
|
47
|
+
out.push(keys[i]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
};
|
|
52
|
+
exports.recordFoldersBySysId = recordFoldersBySysId;
|
|
53
|
+
// `child` is exactly one path segment below `parent`: not the parent itself,
|
|
54
|
+
// not above it, not two levels down, not on another drive.
|
|
55
|
+
const isDirectChild = (parent, child) => {
|
|
56
|
+
const rel = path_1.default.relative(parent, child);
|
|
57
|
+
if (rel === "" || rel === "." || rel === "..")
|
|
58
|
+
return false;
|
|
59
|
+
if (path_1.default.isAbsolute(rel))
|
|
60
|
+
return false;
|
|
61
|
+
return rel.indexOf("/") === -1 && rel.indexOf("\\") === -1;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* `<scopeDir>/<table>/<folder>`, resolved, or undefined when the result is not
|
|
65
|
+
* a record folder: `<scopeDir>/<table>` must be a direct child of `<scopeDir>`
|
|
66
|
+
* and the record folder a direct child of that. A table or folder of "", "..",
|
|
67
|
+
* "a/b" or an absolute path is refused, so a caller that deletes the result can
|
|
68
|
+
* never reach the scope folder, a sibling scope or anything outside them.
|
|
69
|
+
*/
|
|
70
|
+
const recordDirFor = (scopeDir, table, folder) => {
|
|
71
|
+
if (typeof scopeDir !== "string" || scopeDir === "")
|
|
72
|
+
return undefined;
|
|
73
|
+
if (typeof table !== "string" || table === "")
|
|
74
|
+
return undefined;
|
|
75
|
+
if (typeof folder !== "string" || folder === "")
|
|
76
|
+
return undefined;
|
|
77
|
+
const scopeRoot = path_1.default.resolve(scopeDir);
|
|
78
|
+
const tableDir = path_1.default.resolve(scopeRoot, table);
|
|
79
|
+
if (!isDirectChild(scopeRoot, tableDir))
|
|
80
|
+
return undefined;
|
|
81
|
+
const recordDir = path_1.default.resolve(tableDir, folder);
|
|
82
|
+
if (!isDirectChild(tableDir, recordDir))
|
|
83
|
+
return undefined;
|
|
84
|
+
return recordDir;
|
|
85
|
+
};
|
|
86
|
+
exports.recordDirFor = recordDirFor;
|
package/dist/snClient.js
CHANGED
|
@@ -632,7 +632,9 @@ const snClient = (baseURL, username, password, apiKey) => {
|
|
|
632
632
|
}
|
|
633
633
|
return rows;
|
|
634
634
|
};
|
|
635
|
-
|
|
635
|
+
// A client-only table option that is set but malformed (fingerprint,
|
|
636
|
+
// layoutElements) is ignored and reported, never guessed at.
|
|
637
|
+
const warnTableOption = (message) => {
|
|
636
638
|
Logger_1.logger.warn(message);
|
|
637
639
|
};
|
|
638
640
|
const getMissingFiles = (missingFiles, tableOptions) => {
|
|
@@ -678,10 +680,11 @@ const snClient = (baseURL, username, password, apiKey) => {
|
|
|
678
680
|
// missing-file check and every writer agree on the on-disk name.
|
|
679
681
|
if (resp && resp.data && resp.data.result && resp.data.result.tables) {
|
|
680
682
|
const tables = resp.data.result.tables;
|
|
683
|
+
(0, fingerprint_1.checkFingerprintOptions)(tableOptions, warnTableOption);
|
|
681
684
|
(0, fingerprint_1.applyFingerprints)(tables, tableOptions);
|
|
682
685
|
// Layout elements: list the file on every record of an enabled layout
|
|
683
686
|
// table, and read its content now when contents were asked for.
|
|
684
|
-
const layoutTables = (0, layoutElements_1.layoutElementTablesFor)(tableOptions,
|
|
687
|
+
const layoutTables = (0, layoutElements_1.layoutElementTablesFor)(tableOptions, warnTableOption);
|
|
685
688
|
if (layoutTables.length > 0) {
|
|
686
689
|
(0, layoutElements_1.addLayoutElementFiles)(tables, layoutTables);
|
|
687
690
|
if (withFiles) {
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// After `dove create` syncs the new record, it prints where the files landed.
|
|
3
|
+
// That path was built from the display name, but the sync writes the record
|
|
4
|
+
// under its manifest folder, which carries a suffix when another record of the
|
|
5
|
+
// table has the same name ignoring letter case (folderNaming.ts). The printed
|
|
6
|
+
// path then named the OTHER record's folder on a case-insensitive disk. It now
|
|
7
|
+
// reads the folder from the manifest the sync wrote, by sys_id.
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var logMessages = [];
|
|
13
|
+
function pushLog(level) {
|
|
14
|
+
return jest.fn(function (msg) {
|
|
15
|
+
logMessages.push({ level: level, msg: String(msg) });
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
jest.mock("../Logger", function () {
|
|
19
|
+
return {
|
|
20
|
+
logger: {
|
|
21
|
+
setLogLevel: jest.fn(),
|
|
22
|
+
success: pushLog("success"),
|
|
23
|
+
info: pushLog("info"),
|
|
24
|
+
error: pushLog("error"),
|
|
25
|
+
warn: pushLog("warn"),
|
|
26
|
+
debug: jest.fn(),
|
|
27
|
+
getLogLevel: function () { return "info"; },
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
jest.mock("../FileLogger", function () {
|
|
32
|
+
return {
|
|
33
|
+
fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() },
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
jest.mock("../commands", function () {
|
|
37
|
+
return { setLogLevel: jest.fn() };
|
|
38
|
+
});
|
|
39
|
+
// The scope manifest as the sync leaves it on disk.
|
|
40
|
+
var mockWrittenManifest = undefined;
|
|
41
|
+
var mockManifestAfterSync = undefined;
|
|
42
|
+
jest.mock("../config", function () {
|
|
43
|
+
return {
|
|
44
|
+
getManifest: jest.fn(function () { return undefined; }),
|
|
45
|
+
isMultiScopeManifest: jest.fn(function () { return false; }),
|
|
46
|
+
getConfig: jest.fn(function () { return {}; }),
|
|
47
|
+
getSourcePathForScope: jest.fn(function () { return "/virtual/src/x_cadso_ux"; }),
|
|
48
|
+
loadScopeManifest: jest.fn(function () { return Promise.resolve(mockWrittenManifest); }),
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
var mockSyncManifest = jest.fn(function () {
|
|
52
|
+
// syncManifest writes the full scope manifest before it returns.
|
|
53
|
+
mockWrittenManifest = mockManifestAfterSync;
|
|
54
|
+
return Promise.resolve({ failedScopes: [], notWritten: [] });
|
|
55
|
+
});
|
|
56
|
+
jest.mock("../appUtils", function () {
|
|
57
|
+
return { syncManifest: mockSyncManifest };
|
|
58
|
+
});
|
|
59
|
+
jest.mock("../projectFiles", function () {
|
|
60
|
+
return {
|
|
61
|
+
getUpdateSetsConfigPath: jest.fn(function () {
|
|
62
|
+
return "/nonexistent/dove-create-local-path-test/.dove-update-sets.json";
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
jest.mock("inquirer", function () {
|
|
67
|
+
return { prompt: jest.fn() };
|
|
68
|
+
});
|
|
69
|
+
var mockCreateRecord = jest.fn();
|
|
70
|
+
jest.mock("../snClient", function () {
|
|
71
|
+
return {
|
|
72
|
+
defaultClient: jest.fn(function () { return { createRecord: mockCreateRecord }; }),
|
|
73
|
+
unwrapSNResponse: jest.fn(),
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
const path_1 = __importDefault(require("path"));
|
|
77
|
+
const createRecordCommand_1 = require("../createRecordCommand");
|
|
78
|
+
var TABLE = "sys_ux_screen";
|
|
79
|
+
var SCOPE = "x_cadso_ux";
|
|
80
|
+
var NEW_ID = "fb55e60d00000000000000000000000a";
|
|
81
|
+
var OLD_ID = "0a1b2c3d00000000000000000000000b";
|
|
82
|
+
var SCOPE_DIR = "/virtual/src/x_cadso_ux";
|
|
83
|
+
function manifestWith(records) {
|
|
84
|
+
var entries = {};
|
|
85
|
+
var keys = Object.keys(records);
|
|
86
|
+
for (var i = 0; i < keys.length; i++) {
|
|
87
|
+
entries[keys[i]] = { name: keys[i], sys_id: records[keys[i]], files: [] };
|
|
88
|
+
}
|
|
89
|
+
var tables = {};
|
|
90
|
+
tables[TABLE] = { records: entries };
|
|
91
|
+
return { scope: SCOPE, tables: tables };
|
|
92
|
+
}
|
|
93
|
+
function locationMessages() {
|
|
94
|
+
return logMessages
|
|
95
|
+
.filter(function (m) { return m.msg.indexOf("Local files created at: ") !== -1; })
|
|
96
|
+
.map(function (m) { return m.msg; });
|
|
97
|
+
}
|
|
98
|
+
describe("dove create prints the folder the sync wrote", function () {
|
|
99
|
+
var exitSpy;
|
|
100
|
+
beforeEach(function () {
|
|
101
|
+
logMessages = [];
|
|
102
|
+
mockWrittenManifest = undefined;
|
|
103
|
+
mockManifestAfterSync = undefined;
|
|
104
|
+
jest.clearAllMocks();
|
|
105
|
+
exitSpy = jest.spyOn(process, "exit").mockImplementation(function (code) {
|
|
106
|
+
throw new Error("process.exit(" + code + ")");
|
|
107
|
+
});
|
|
108
|
+
mockCreateRecord.mockResolvedValue({
|
|
109
|
+
status: 200,
|
|
110
|
+
data: { result: { sys_id: NEW_ID, table: TABLE, name: "Search Default" } },
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
afterEach(function () {
|
|
114
|
+
exitSpy.mockRestore();
|
|
115
|
+
});
|
|
116
|
+
async function create() {
|
|
117
|
+
await (0, createRecordCommand_1.createRecordCommand)({ table: TABLE, name: "Search Default", scope: SCOPE, ci: true, logLevel: "info" });
|
|
118
|
+
}
|
|
119
|
+
it("names the suffixed folder of a letter-case twin, not the display name", async function () {
|
|
120
|
+
mockManifestAfterSync = manifestWith({
|
|
121
|
+
"Search default (0a1b2c3d)": OLD_ID,
|
|
122
|
+
"Search Default (fb55e60d)": NEW_ID,
|
|
123
|
+
});
|
|
124
|
+
await create();
|
|
125
|
+
expect(mockSyncManifest).toHaveBeenCalledWith(SCOPE, { record: { table: TABLE, sysId: NEW_ID } });
|
|
126
|
+
var located = locationMessages();
|
|
127
|
+
expect(located.length).toBe(1);
|
|
128
|
+
expect(located[0]).toContain(path_1.default.join(SCOPE_DIR, TABLE, "Search Default (fb55e60d)"));
|
|
129
|
+
expect(located[0].slice(-("Search Default".length + 1))).not.toBe(path_1.default.sep + "Search Default");
|
|
130
|
+
expect(exitSpy).not.toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
it("names the plain folder when no other record shares the name", async function () {
|
|
133
|
+
mockManifestAfterSync = manifestWith({ "Search Default": NEW_ID });
|
|
134
|
+
await create();
|
|
135
|
+
var located = locationMessages();
|
|
136
|
+
expect(located.length).toBe(1);
|
|
137
|
+
expect(located[0]).toContain(path_1.default.join(SCOPE_DIR, TABLE, "Search Default"));
|
|
138
|
+
});
|
|
139
|
+
it("prints no location when the synced manifest does not list the new record", async function () {
|
|
140
|
+
mockManifestAfterSync = manifestWith({ "Search default": OLD_ID });
|
|
141
|
+
await create();
|
|
142
|
+
expect(locationMessages()).toEqual([]);
|
|
143
|
+
expect(exitSpy).not.toHaveBeenCalled();
|
|
144
|
+
});
|
|
145
|
+
});
|