@jacebenson/jsn 5.4.0-dev.144.1 → 5.4.0-dev.149.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.
Files changed (2) hide show
  1. package/package.json +1 -3
  2. package/src/helpers.js +24 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jacebenson/jsn",
3
- "version": "5.4.0-dev.144.1",
3
+ "version": "5.4.0-dev.149.1",
4
4
  "description": "A command-line interface for ServiceNow that follows the Unix philosophy: simple, composable, and scriptable.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,8 +9,6 @@
9
9
  "main": "src/cli.js",
10
10
  "scripts": {
11
11
  "test": "node scripts/test.mjs",
12
- "test:acceptance": "node scripts/acceptance/run.mjs",
13
- "test:acceptance:offline": "node --test test/acceptance-runner.test.js test/acceptance-workflows.test.js test/acceptance-auth-perf.test.js test/acceptance-integration.test.js test/acceptance-read-only-catalog.test.js",
14
12
  "test:mutation": "stryker run",
15
13
  "lint": "npx eslint src/ bin/ test/",
16
14
  "start": "node bin/jsn.js",
package/src/helpers.js CHANGED
@@ -185,6 +185,29 @@ function getRawValue(val) {
185
185
  return String(val);
186
186
  }
187
187
 
188
+ /**
189
+ * Does the value supplied in --data match what the API stored for a field?
190
+ *
191
+ * The Table API accepts both choice values and their display labels
192
+ * ("true" and "True", "ignore" and "Leave alone"), so a successful write
193
+ * must not be reported as dropped just because the caller supplied the
194
+ * label. Matches the raw value exactly, or the display label
195
+ * case-insensitively when the label differs from the raw value.
196
+ */
197
+ function matchesPersisted(sent, val) {
198
+ if (val == null) return sent === '';
199
+ if (typeof val !== 'object') return String(val) === sent;
200
+
201
+ const raw = val.value == null ? null : String(val.value);
202
+ const display = val.display_value == null ? null : String(val.display_value);
203
+
204
+ if (raw != null && raw === sent) return true;
205
+ if (display && display !== raw) {
206
+ return display.toLowerCase() === sent.toLowerCase();
207
+ }
208
+ return false;
209
+ }
210
+
188
211
  /**
189
212
  * Normalize a value the user supplied in --data for comparison against
190
213
  * what the API persisted. Objects like {"value": "<sys_id>"} are unwrapped.
@@ -240,7 +263,7 @@ export async function verifyWriteBack(app, table, sysID, sentData) {
240
263
  for (const field of fields) {
241
264
  const sent = normalizeSupplied(sentData[field]);
242
265
  const got = getRawValue(persisted[field]);
243
- if (sent !== got) {
266
+ if (!matchesPersisted(sent, persisted[field])) {
244
267
  mismatches.push({ field, sent, got });
245
268
  }
246
269
  }