@remit/config-transfer 0.0.15 → 0.0.17
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 +1 -1
- package/src/import.test.ts +25 -1
- package/src/import.ts +14 -20
package/package.json
CHANGED
package/src/import.test.ts
CHANGED
|
@@ -1463,7 +1463,7 @@ test("a document naming the same label twice is refused before anything is writt
|
|
|
1463
1463
|
const document = (await exportSource()) as unknown as {
|
|
1464
1464
|
labels: { name: string; color: string }[];
|
|
1465
1465
|
};
|
|
1466
|
-
document.labels.push({ name: "
|
|
1466
|
+
document.labels.push({ name: "Facturen", color: "Green" });
|
|
1467
1467
|
const store = emptyStore();
|
|
1468
1468
|
|
|
1469
1469
|
const report = reportOf(await apply(store, document));
|
|
@@ -1473,6 +1473,30 @@ test("a document naming the same label twice is refused before anything is writt
|
|
|
1473
1473
|
assert.deepEqual(store.labels, []);
|
|
1474
1474
|
});
|
|
1475
1475
|
|
|
1476
|
+
test("two filters whose names differ only in case survive an export and an import", async () => {
|
|
1477
|
+
const fixture = sourceFixture();
|
|
1478
|
+
fixture.filters = [
|
|
1479
|
+
...fixture.filters,
|
|
1480
|
+
makeFilter({
|
|
1481
|
+
filterId: "flt-release-lower",
|
|
1482
|
+
name: "release notes",
|
|
1483
|
+
literalClauses: [{ field: "Subject", value: "changelog" }],
|
|
1484
|
+
}),
|
|
1485
|
+
];
|
|
1486
|
+
const document = await exportSource(fixture);
|
|
1487
|
+
const store = emptyStore();
|
|
1488
|
+
|
|
1489
|
+
const report = reportOf(await apply(store, document));
|
|
1490
|
+
|
|
1491
|
+
assert.deepEqual(report.errors, []);
|
|
1492
|
+
assert.equal(report.applied, true);
|
|
1493
|
+
assert.deepEqual(store.filters.map((filter) => filter.name).sort(), [
|
|
1494
|
+
"Invoices to Facturen",
|
|
1495
|
+
"Release notes",
|
|
1496
|
+
"release notes",
|
|
1497
|
+
]);
|
|
1498
|
+
});
|
|
1499
|
+
|
|
1476
1500
|
test("a filter pointing at a label no one has is refused", async () => {
|
|
1477
1501
|
const document = (await exportSource()) as unknown as {
|
|
1478
1502
|
labels: unknown[];
|
package/src/import.ts
CHANGED
|
@@ -197,11 +197,11 @@ const validateDocument = (
|
|
|
197
197
|
);
|
|
198
198
|
duplicate(
|
|
199
199
|
"labels",
|
|
200
|
-
document.labels.map((label) =>
|
|
200
|
+
document.labels.map((label) => label.name),
|
|
201
201
|
);
|
|
202
202
|
duplicate(
|
|
203
203
|
"filters",
|
|
204
|
-
document.filters.map((filter) =>
|
|
204
|
+
document.filters.map((filter) => filter.name),
|
|
205
205
|
);
|
|
206
206
|
duplicate(
|
|
207
207
|
"addressFlags",
|
|
@@ -209,8 +209,8 @@ const validateDocument = (
|
|
|
209
209
|
);
|
|
210
210
|
|
|
211
211
|
const labelNames = new Set([
|
|
212
|
-
...document.labels.map((label) =>
|
|
213
|
-
...existing.labels.map((label) =>
|
|
212
|
+
...document.labels.map((label) => label.name),
|
|
213
|
+
...existing.labels.map((label) => label.name),
|
|
214
214
|
]);
|
|
215
215
|
const accountIds = new Set([
|
|
216
216
|
...document.accounts.map((account) => account.accountId),
|
|
@@ -220,7 +220,7 @@ const validateDocument = (
|
|
|
220
220
|
for (const filter of document.filters) {
|
|
221
221
|
if (
|
|
222
222
|
filter.actionLabelName !== null &&
|
|
223
|
-
!labelNames.has(
|
|
223
|
+
!labelNames.has(filter.actionLabelName)
|
|
224
224
|
) {
|
|
225
225
|
errors.push(
|
|
226
226
|
problem(
|
|
@@ -442,13 +442,11 @@ const applyDocument = async (
|
|
|
442
442
|
|
|
443
443
|
// ---- labels ---------------------------------------------------------
|
|
444
444
|
const labelIdByName = new Map(
|
|
445
|
-
existing.labels.map(
|
|
446
|
-
(label) => [normalize(label.name), label.labelId] as const,
|
|
447
|
-
),
|
|
445
|
+
existing.labels.map((label) => [label.name, label.labelId] as const),
|
|
448
446
|
);
|
|
449
447
|
|
|
450
448
|
for (const label of document.labels) {
|
|
451
|
-
const key =
|
|
449
|
+
const key = label.name;
|
|
452
450
|
const heldId = labelIdByName.get(key);
|
|
453
451
|
if (heldId) {
|
|
454
452
|
await write(ConfigImportSection.Labels, label.name, () =>
|
|
@@ -477,7 +475,7 @@ const applyDocument = async (
|
|
|
477
475
|
|
|
478
476
|
// ---- filters --------------------------------------------------------
|
|
479
477
|
const existingFilterByName = new Map(
|
|
480
|
-
existing.filters.map((filter) => [
|
|
478
|
+
existing.filters.map((filter) => [filter.name, filter] as const),
|
|
481
479
|
);
|
|
482
480
|
|
|
483
481
|
const resolveFilterFolder = (
|
|
@@ -494,7 +492,7 @@ const applyDocument = async (
|
|
|
494
492
|
};
|
|
495
493
|
|
|
496
494
|
for (const filter of document.filters) {
|
|
497
|
-
const key =
|
|
495
|
+
const key = filter.name;
|
|
498
496
|
const folder = resolveFilterFolder(filter);
|
|
499
497
|
const shape = {
|
|
500
498
|
scope: filter.scope,
|
|
@@ -505,7 +503,7 @@ const applyDocument = async (
|
|
|
505
503
|
actionLabelId:
|
|
506
504
|
filter.actionLabelName === null
|
|
507
505
|
? NO_ACTION
|
|
508
|
-
: (labelIdByName.get(
|
|
506
|
+
: (labelIdByName.get(filter.actionLabelName) ?? NO_ACTION),
|
|
509
507
|
actionMailboxId: folder.actionMailboxId,
|
|
510
508
|
...(folder.pending
|
|
511
509
|
? {
|
|
@@ -978,12 +976,8 @@ const plan = (
|
|
|
978
976
|
const heldEmails = new Set(
|
|
979
977
|
existing.accounts.map((account) => normalize(account.email)),
|
|
980
978
|
);
|
|
981
|
-
const heldLabels = new Set(
|
|
982
|
-
|
|
983
|
-
);
|
|
984
|
-
const heldFilters = new Set(
|
|
985
|
-
existing.filters.map((filter) => normalize(filter.name)),
|
|
986
|
-
);
|
|
979
|
+
const heldLabels = new Set(existing.labels.map((label) => label.name));
|
|
980
|
+
const heldFilters = new Set(existing.filters.map((filter) => filter.name));
|
|
987
981
|
|
|
988
982
|
const verdict = (held: boolean): ConfigImportItemReport["verdict"] =>
|
|
989
983
|
held ? ConfigImportVerdict.Updated : ConfigImportVerdict.Created;
|
|
@@ -1005,7 +999,7 @@ const plan = (
|
|
|
1005
999
|
items.push({
|
|
1006
1000
|
section: ConfigImportSection.Labels,
|
|
1007
1001
|
key: label.name,
|
|
1008
|
-
verdict: verdict(heldLabels.has(
|
|
1002
|
+
verdict: verdict(heldLabels.has(label.name)),
|
|
1009
1003
|
});
|
|
1010
1004
|
}
|
|
1011
1005
|
for (const filter of document.filters) {
|
|
@@ -1018,7 +1012,7 @@ const plan = (
|
|
|
1018
1012
|
items.push({
|
|
1019
1013
|
section: ConfigImportSection.Filters,
|
|
1020
1014
|
key: filter.name,
|
|
1021
|
-
verdict: verdict(heldFilters.has(
|
|
1015
|
+
verdict: verdict(heldFilters.has(filter.name)),
|
|
1022
1016
|
...(awaiting && actionFolder
|
|
1023
1017
|
? { reason: awaitingFolderReason(actionFolder.folderPath) }
|
|
1024
1018
|
: {}),
|