From d4209e5872abbc5c58d417491f28d18883e67f1c Mon Sep 17 00:00:00 2001 From: Simon Varney Date: Fri, 12 Jul 2024 09:17:11 +0200 Subject: [PATCH] Add flag on title to indicate whether we should be expecting a diff file to be created every day or not (#164) * Cleanup namespace tests * Add expectDiffFileEveryDeliveryDay to title config --- config/product-mapping.js | 9 +- lib/titles.js | 7 + .../namespaces-carrier-delivery-only-test.js | 26 --- test/unit/namespaces-common-test.js | 56 ----- .../namespaces-postal-delivery-only-test.js | 26 --- test/unit/namespaces-print-test.js | 14 -- test/unit/namespaces-test.js | 197 ++++++++++++++++++ test/unit/titles-get-all-titles-test.js | 15 -- .../titles-get-titles-by-namespace-test.js | 31 --- test/unit/titles-get-titles-test.js | 99 +++++++++ 10 files changed, 305 insertions(+), 175 deletions(-) delete mode 100644 test/unit/namespaces-carrier-delivery-only-test.js delete mode 100644 test/unit/namespaces-common-test.js delete mode 100644 test/unit/namespaces-postal-delivery-only-test.js delete mode 100644 test/unit/namespaces-print-test.js create mode 100644 test/unit/namespaces-test.js delete mode 100644 test/unit/titles-get-all-titles-test.js delete mode 100644 test/unit/titles-get-titles-by-namespace-test.js create mode 100644 test/unit/titles-get-titles-test.js diff --git a/config/product-mapping.js b/config/product-mapping.js index 35be168..c2c97eb 100644 --- a/config/product-mapping.js +++ b/config/product-mapping.js @@ -1,17 +1,10 @@ const sevenDay = [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" ]; - const sixDay = [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ]; - const fiveDay = [ "monday", "tuesday", "wednesday", "thursday", "friday" ]; - const mondayWednesdayThursdayFriday = [ "monday", "wednesday", "thursday", "friday" ]; - const mondayWednesdayFriday = [ "monday", "wednesday", "friday" ]; - const tuesdayThursdaySaturday = [ "tuesday", "thursday", "saturday" ]; - const tuesdayFriday = [ "tuesday", "friday" ]; - const wednesday = [ "wednesday" ]; const productConfig = { @@ -27,6 +20,7 @@ const productConfig = { diTitle: "Dagens Nyheter", complaintSenderId: "1160", deliveryDays: sevenDay, + expectDiffFileEveryDeliveryDay: true, }, { title: "kp", @@ -43,6 +37,7 @@ const productConfig = { productName: "di", diCustomerSystem: "DI", diTitle: "Dagens Industri", + expectDiffFileEveryDeliveryDay: true, }, ], paf: [ diff --git a/lib/titles.js b/lib/titles.js index 8df541a..f66e681 100644 --- a/lib/titles.js +++ b/lib/titles.js @@ -48,6 +48,12 @@ function getTitlesByNamespace(namespace) { return productConfig[namespace].map((pm) => pm.title).filter((t) => t); } +function getTitleConfig(title) { + const configByRealTitle = productMapping.find((pm) => pm.title === title); + if (configByRealTitle) return configByRealTitle; + return productMapping.find((pm) => pm.alternativeTitles?.includes(title)); +} + function getDeliveryDays(namespace, title) { const product = productConfig[namespace].find((p) => p.title === title); assert(product?.deliveryDays, "No delivery days for title was found. Update product-mapping config"); @@ -137,6 +143,7 @@ export { getPrintTitlesByNamespace, getAllTitles, getTitlesByNamespace, + getTitleConfig, getNamespaceByTitle, productMapping, productConfig, diff --git a/test/unit/namespaces-carrier-delivery-only-test.js b/test/unit/namespaces-carrier-delivery-only-test.js deleted file mode 100644 index 4e33316..0000000 --- a/test/unit/namespaces-carrier-delivery-only-test.js +++ /dev/null @@ -1,26 +0,0 @@ -import { carrierDeliveryOnly } from "../../lib/namespaces.js"; - -const scenarios = [ - { - expected: true, - namespace: "bnlo", - text: "Vetlanda-Posten", - }, - { - expected: false, - namespace: "some-namespace", - text: "Some namespace", - }, -]; - -describe("check if carrier delivery only", () => { - for (const s of scenarios) { - describe(s.text, () => { - const postOk = carrierDeliveryOnly(s.namespace); - - it(`should${!s.expected ? " not" : ""} only allow carrier delivery`, () => { - Boolean(postOk).should.eql(Boolean(s.expected)); - }); - }); - } -}); diff --git a/test/unit/namespaces-common-test.js b/test/unit/namespaces-common-test.js deleted file mode 100644 index adb8afa..0000000 --- a/test/unit/namespaces-common-test.js +++ /dev/null @@ -1,56 +0,0 @@ -import { - isCommonNamespace, - getCommonNamespaces, - carrierDeliveryOnlyNamespaces, - postalDeliveryOnlyNamespaces, -} from "../../lib/namespaces.js"; - -const expectedNamespaces = [ - "bbm-aktuellhallbarhet", - "bbm-byggindustrin", - "bbm-dagensmedicin", - "bbm-dagenssamhalle", - "bbm-dagligvarunytt", - "bbm-dam", - "bbm-fastighetsnytt", - "bbm-market", - "bbm-news", - "bbm-res", - "bnlo", - "di", - "dn", - "expressen", - "gotamedia", - "paf", -]; - -const expectedPostalDeliveryOnlyNamespaces = [ "paf" ]; -const expectedCarrierOnlyNamespaces = [ "bnlo", "gotamedia" ]; - -describe("isCommonNamespace", () => { - expectedNamespaces.forEach((namespace) => { - it(`should confirm '${namespace}' as part of common namespace`, () => { - const result = isCommonNamespace(namespace); - result.should.equal(true); - }); - }); - - it("should NOT confirm 'whatever' as part of common namespace", () => { - const result = isCommonNamespace("whatever"); - result.should.equal(false); - }); - - it("should give us a list of common namespaces", () => { - JSON.stringify(getCommonNamespaces().sort()).should.equal(JSON.stringify(expectedNamespaces)); - }); - - it("should give us a list of carrier only namespaces", () => { - JSON.stringify(carrierDeliveryOnlyNamespaces.sort()).should.equal(JSON.stringify(expectedCarrierOnlyNamespaces)); - }); - - it("should give us a list of postal delivery only namespaces", () => { - JSON.stringify(postalDeliveryOnlyNamespaces.sort()).should.equal( - JSON.stringify(expectedPostalDeliveryOnlyNamespaces) - ); - }); -}); diff --git a/test/unit/namespaces-postal-delivery-only-test.js b/test/unit/namespaces-postal-delivery-only-test.js deleted file mode 100644 index 52cc4ec..0000000 --- a/test/unit/namespaces-postal-delivery-only-test.js +++ /dev/null @@ -1,26 +0,0 @@ -import { postalDeliveryOnly } from "../../lib/namespaces.js"; - -const scenarios = [ - { - expected: true, - namespace: "paf", - text: "Privata Affärer", - }, - { - expected: false, - namespace: "some-namespace", - text: "Some namespace", - }, -]; - -describe("check if postal delivery only", () => { - for (const s of scenarios) { - describe(s.text, () => { - const postOk = postalDeliveryOnly(s.namespace); - - it(`should${!s.expected ? " not" : ""} only allow postal delivery`, () => { - Boolean(postOk).should.eql(Boolean(s.expected)); - }); - }); - } -}); diff --git a/test/unit/namespaces-print-test.js b/test/unit/namespaces-print-test.js deleted file mode 100644 index d5392b4..0000000 --- a/test/unit/namespaces-print-test.js +++ /dev/null @@ -1,14 +0,0 @@ -import { printNamespaces } from "../../lib/namespaces.js"; - -const expectedPrintNamespaces = [ "dn", "expressen", "bnlo", "paf", "gotamedia" ]; - -describe("printNamespaces", () => { - it("should give us the expected print namespaces", () => { - JSON.stringify(printNamespaces.sort()).should.equal(JSON.stringify(expectedPrintNamespaces.sort())); - }); - - it("should NOT contain 'whatever' as part of print namespace", () => { - const result = expectedPrintNamespaces.includes("whatever"); - result.should.equal(false); - }); -}); diff --git a/test/unit/namespaces-test.js b/test/unit/namespaces-test.js new file mode 100644 index 0000000..429ebe3 --- /dev/null +++ b/test/unit/namespaces-test.js @@ -0,0 +1,197 @@ +import { + carrierDeliveryOnly, + carrierDeliveryOnlyNamespaces, + commonNamespaces, + getCommonNamespaces, + isCommonNamespace, + kayakNamespaces, + knownNamespaces, + migratingNamespaces, + platformNamespaces, + postalDeliveryOnly, + printNamespaces, + provisionedNamespaces, + postalDeliveryOnlyNamespaces, + salesforceCaseNamespaces, + upsalesNamespaces, +} from "../../lib/namespaces.js"; + +// here in the tests we maintain a full list of expected namespaces just so that we're super clear what is what +// because the namespace config affects a lot of different parts of the system and we don't want to mess it up +// by making mistakes in the config +const expectedCarrierOnlyNamespaces = [ "bnlo", "gotamedia" ]; +const expectedCommonNamespaces = [ + "bbm-aktuellhallbarhet", + "bbm-byggindustrin", + "bbm-dagensmedicin", + "bbm-dagenssamhalle", + "bbm-dagligvarunytt", + "bbm-dam", + "bbm-fastighetsnytt", + "bbm-market", + "bbm-news", + "bbm-res", + "bnlo", + "di", + "dn", + "expressen", + "gotamedia", + "paf", +]; +const expectedKayakNamespaces = [ "di", "hbl" ]; +const expectedKnownNamespaces = [ + "bbm-aktuellhallbarhet", + "bbm-byggindustrin", + "bbm-dagensmedicin", + "bbm-dagenssamhalle", + "bbm-dagligvarunytt", + "bbm-dam", + "bbm-fastighetsnytt", + "bbm-market", + "bbm-news", + "bbm-res", + "bnlo", + "di", + "dn", + "expressen", + "gotamedia", + "hbl", + "paf", +]; +const expectedMigratingNamespaces = [ "bnlo", "gotamedia" ]; +const expectedPlatformNamespaces = [ "bnlo", "dn", "expressen", "gotamedia", "paf" ]; +const expectedPostalDeliveryOnlyNamespaces = [ "paf" ]; +const expectedPrintNamespaces = [ "bnlo", "dn", "expressen", "gotamedia", "paf" ]; +const expectedProvisionedNamespaces = [ + "bbm-aktuellhallbarhet", + "bbm-byggindustrin", + "bbm-dagensmedicin", + "bbm-dagenssamhalle", + "bbm-dagligvarunytt", + "bbm-dam", + "bbm-fastighetsnytt", + "bbm-market", + "bbm-news", + "bbm-res", + "bnlo", + "di", + "gotamedia", + "hbl", +]; +const expectedSfdcCaseNamespaces = [ "bnlo", "di", "dn", "expressen", "gotamedia", "paf" ]; +const expectedUpsalesNamespaces = [ + "bbm-aktuellhallbarhet", + "bbm-byggindustrin", + "bbm-dagensmedicin", + "bbm-dagenssamhalle", + "bbm-dagligvarunytt", + "bbm-dam", + "bbm-fastighetsnytt", + "bbm-market", + "bbm-news", + "bbm-res", +]; + +describe("namespaces tests", () => { + describe("distribution related namespace tests", () => { + describe("printNamespaces", () => { + it("should give us the expected print namespaces", () => { + JSON.stringify(printNamespaces.sort()).should.equal(JSON.stringify(expectedPrintNamespaces.sort())); + }); + + it("should NOT contain 'whatever' as part of print namespace", () => { + const result = expectedPrintNamespaces.includes("whatever"); + result.should.equal(false); + }); + }); + + describe("carrier delivery only tests", () => { + const scenarios = [ + { expected: true, namespace: "bnlo" }, + { expected: false, namespace: "some-namespace" }, + ]; + for (const s of scenarios) { + it(`should${!s.expected ? " not" : ""} only allow carrier delivery for ${s.namespace}`, () => { + const carrierOnly = carrierDeliveryOnly(s.namespace); + carrierOnly.should.eql(s.expected); + }); + } + + it("should give us a list of carrier only namespaces", () => { + JSON.stringify(carrierDeliveryOnlyNamespaces.sort()).should.equal( + JSON.stringify(expectedCarrierOnlyNamespaces) + ); + }); + }); + + describe("postal delivery only tests", () => { + const scenarios = [ + { expected: true, namespace: "paf" }, + { expected: false, namespace: "some-namespace" }, + ]; + for (const s of scenarios) { + it(`should${!s.expected ? " not" : ""} only allow postal delivery for ${s.namespace}`, () => { + const postOnly = postalDeliveryOnly(s.namespace); + postOnly.should.eql(s.expected); + }); + } + }); + }); + describe("namespace state tests", () => { + it("should give us a list of known namespaces", () => { + knownNamespaces.sort().should.eql(expectedKnownNamespaces); + }); + + it("should give us a list of namespaces that are currently migrating into the Platform", () => { + migratingNamespaces.sort().should.eql(expectedMigratingNamespaces); + }); + + it("should give us a list of namespaces that can receive provisioned resources", () => { + provisionedNamespaces.sort().should.eql(expectedProvisionedNamespaces); + }); + + it("should give us a list of namespaces that can create Salesforce cases", () => { + salesforceCaseNamespaces.sort().should.eql(expectedSfdcCaseNamespaces); + }); + + describe("common (credentials) namespace tests", () => { + it("should give us a list of common namespaces", () => { + JSON.stringify(commonNamespaces.sort()).should.equal(JSON.stringify(expectedCommonNamespaces)); + }); + + it("should give us a list of common namespaces via function call", () => { + JSON.stringify(getCommonNamespaces().sort()).should.equal(JSON.stringify(expectedCommonNamespaces)); + }); + + expectedCommonNamespaces.forEach((namespace) => { + it(`should confirm '${namespace}' as part of common namespace`, () => { + const result = isCommonNamespace(namespace); + result.should.equal(true); + }); + }); + + it("should NOT confirm 'whatever' as part of common namespace", () => { + const result = isCommonNamespace("whatever"); + result.should.equal(false); + }); + + it("should give us a list of postal delivery only namespaces", () => { + JSON.stringify(postalDeliveryOnlyNamespaces.sort()).should.equal( + JSON.stringify(expectedPostalDeliveryOnlyNamespaces) + ); + }); + }); + }); + + describe("system related namespace tests", () => { + it("should give us a list of Kayak namespaces", () => { + kayakNamespaces.should.eql(expectedKayakNamespaces); + }); + it("should give us a list of Platform namespaces", () => { + platformNamespaces.sort().should.eql(expectedPlatformNamespaces); + }); + it("should give us a list of Upsales namespaces", () => { + upsalesNamespaces.sort().should.eql(expectedUpsalesNamespaces); + }); + }); +}); diff --git a/test/unit/titles-get-all-titles-test.js b/test/unit/titles-get-all-titles-test.js deleted file mode 100644 index a938528..0000000 --- a/test/unit/titles-get-all-titles-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { getAllTitles, getAllPrintTitles, productMapping } from "../../lib/titles.js"; - -describe("get titles", () => { - it("should return all titles", () => { - const allTitles = getAllTitles(); - const allTitlesFromConfig = productMapping.filter((pm) => pm.title).map((pm) => pm.title); - allTitles.should.eql(allTitlesFromConfig); - }); - - it("should return all print titles", () => { - const allTitles = getAllPrintTitles(); - const allTitlesFromConfig = productMapping.filter((pm) => pm.tsCode).map((pm) => pm.title); - allTitles.should.eql(allTitlesFromConfig); - }); -}); diff --git a/test/unit/titles-get-titles-by-namespace-test.js b/test/unit/titles-get-titles-by-namespace-test.js deleted file mode 100644 index 637ff6b..0000000 --- a/test/unit/titles-get-titles-by-namespace-test.js +++ /dev/null @@ -1,31 +0,0 @@ -import { getTitlesByNamespace, getPrintTitlesByNamespace, productConfig } from "../../lib/titles.js"; - -const namespaceSafety = [ - { namespace: "dn", text: "DN" }, - { namespace: "di", text: "DI" }, - { namespace: "expressen", text: "Expressen" }, - { namespace: "bnlo", text: "BN Local" }, - { namespace: "paf", text: "Privata Affärer" }, - { namespace: "gotamedia", text: "Gota Media" }, -]; - -describe("get titles by namespace", () => { - for (const n of namespaceSafety) { - describe(n.text, () => { - it(`should return all titles in namespace: ${n.namespace}`, () => { - const titles = getTitlesByNamespace(n.namespace); - const titlesFromConfig = productConfig[n.namespace].map((pm) => pm.title).filter((t) => t); - titles.should.eql(titlesFromConfig); - }); - - it(`should return all print titles in namespace: ${n.namespace}`, () => { - const titles = getPrintTitlesByNamespace(n.namespace); - const titlesFromConfig = productConfig[n.namespace] - .filter((t) => t.tsCode) - .map((pm) => pm.title) - .filter((t) => t); - titles.should.eql(titlesFromConfig); - }); - }); - } -}); diff --git a/test/unit/titles-get-titles-test.js b/test/unit/titles-get-titles-test.js new file mode 100644 index 0000000..7c70d71 --- /dev/null +++ b/test/unit/titles-get-titles-test.js @@ -0,0 +1,99 @@ +import { + getAllTitles, + getAllPrintTitles, + getTitleConfig, + productMapping, + getTitlesByNamespace, + getPrintTitlesByNamespace, + productConfig, +} from "../../lib/titles.js"; + +const namespaceSafety = [ + { namespace: "dn", text: "DN" }, + { namespace: "di", text: "DI" }, + { namespace: "expressen", text: "Expressen" }, + { namespace: "bnlo", text: "BN Local" }, + { namespace: "paf", text: "Privata Affärer" }, + { namespace: "gotamedia", text: "Gota Media" }, +]; + +describe("get titles", () => { + describe("getting all titles", () => { + it("should return all titles", () => { + const allTitles = getAllTitles(); + const allTitlesFromConfig = productMapping.filter((pm) => pm.title).map((pm) => pm.title); + allTitles.should.eql(allTitlesFromConfig); + }); + + it("should return all print titles", () => { + const allTitles = getAllPrintTitles(); + const allTitlesFromConfig = productMapping.filter((pm) => pm.tsCode).map((pm) => pm.title); + allTitles.should.eql(allTitlesFromConfig); + }); + }); + + describe("get titles by namespace", () => { + for (const n of namespaceSafety) { + describe(n.text, () => { + it(`should return all titles in namespace: ${n.namespace}`, () => { + const titles = getTitlesByNamespace(n.namespace); + const titlesFromConfig = productConfig[n.namespace].map((pm) => pm.title).filter((t) => t); + titles.should.eql(titlesFromConfig); + }); + + it(`should return all print titles in namespace: ${n.namespace}`, () => { + const titles = getPrintTitlesByNamespace(n.namespace); + const titlesFromConfig = productConfig[n.namespace] + .filter((t) => t.tsCode) + .map((pm) => pm.title) + .filter((t) => t); + titles.should.eql(titlesFromConfig); + }); + }); + } + }); + + describe("get specific title config", () => { + it("should return the config for a title", () => { + getTitleConfig("dn").should.eql({ + namespace: "dn", + title: "dn", + tsCode: "0440", + shortName: "DN", + subDirectory: "", + type: "paper", + productName: "DN", + diCustomerSystem: "DNY", + diTitle: "Dagens Nyheter", + complaintSenderId: "1160", + deliveryDays: [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" ], + expectDiffFileEveryDeliveryDay: true, + }); + }); + it("should return the config for an alternative title", () => { + getTitleConfig("ljusnan").should.eql({ + namespace: "bnlo", + title: "lj", + alternativeTitles: [ "ljusnan" ], + tsCode: "1230", + shortName: "", + subDirectory: "", + type: "paper", + productName: "Ljusnan", + diCustomerSystem: "", + deliveryDays: [ "monday", "wednesday", "thursday", "friday" ], + }); + }); + it("should return nothing for an unknown title", () => { + should.not.exist(getTitleConfig("whatever")); + }); + [ "di", "dn" ].forEach((title) => { + it(`should expect ${title} to have so many subscriptions that a start/stop file is expected every day`, () => { + getTitleConfig(title).expectDiffFileEveryDeliveryDay.should.eql(true); + }); + }); + it("should expect expressen to have so few subscriptions that there won't necessarily be a start/stop file every day", () => { + Boolean(getTitleConfig("expressen").expectDiffFileEveryDeliveryDay).should.eql(false); + }); + }); +});