Skip to content

Commit

Permalink
Add flag on title to indicate whether we should be expecting a diff f…
Browse files Browse the repository at this point in the history
…ile to be created every day or not (#164)

* Cleanup namespace tests

* Add expectDiffFileEveryDeliveryDay to title config
  • Loading branch information
varney authored Jul 12, 2024
1 parent f972619 commit d4209e5
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 175 deletions.
9 changes: 2 additions & 7 deletions config/product-mapping.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -27,6 +20,7 @@ const productConfig = {
diTitle: "Dagens Nyheter",
complaintSenderId: "1160",
deliveryDays: sevenDay,
expectDiffFileEveryDeliveryDay: true,
},
{
title: "kp",
Expand All @@ -43,6 +37,7 @@ const productConfig = {
productName: "di",
diCustomerSystem: "DI",
diTitle: "Dagens Industri",
expectDiffFileEveryDeliveryDay: true,
},
],
paf: [
Expand Down
7 changes: 7 additions & 0 deletions lib/titles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -137,6 +143,7 @@ export {
getPrintTitlesByNamespace,
getAllTitles,
getTitlesByNamespace,
getTitleConfig,
getNamespaceByTitle,
productMapping,
productConfig,
Expand Down
26 changes: 0 additions & 26 deletions test/unit/namespaces-carrier-delivery-only-test.js

This file was deleted.

56 changes: 0 additions & 56 deletions test/unit/namespaces-common-test.js

This file was deleted.

26 changes: 0 additions & 26 deletions test/unit/namespaces-postal-delivery-only-test.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/unit/namespaces-print-test.js

This file was deleted.

197 changes: 197 additions & 0 deletions test/unit/namespaces-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
15 changes: 0 additions & 15 deletions test/unit/titles-get-all-titles-test.js

This file was deleted.

Loading

0 comments on commit d4209e5

Please sign in to comment.