From cdd36fe0c6afbfc3e5916023f1832b9baca227d1 Mon Sep 17 00:00:00 2001 From: Greg Walker Date: Wed, 20 Nov 2024 13:22:48 -0600 Subject: [PATCH] update git.gov to match upstream data structure; fix bug in handbook script --- src/scripts/dot-gov.js | 6 ++-- src/scripts/dot-gov.test.js | 56 ++++++++++++++++++------------------ src/scripts/handbook.js | 8 ++++-- src/scripts/handbook.test.js | 6 ++-- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/scripts/dot-gov.js b/src/scripts/dot-gov.js index 709e8be..47f82be 100644 --- a/src/scripts/dot-gov.js +++ b/src/scripts/dot-gov.js @@ -90,10 +90,10 @@ const DOMAIN_TYPES = { /** Current list of fields available in the CSV file. */ const DATA_FIELDS = { - NAME: "Domain Name", - TYPE: "Domain Type", + NAME: "Domain name", + TYPE: "Domain type", AGENCY: "Agency", - ORG: "Organization", + ORG: "Organization name", CITY: "City", STATE: "State", }; diff --git a/src/scripts/dot-gov.test.js b/src/scripts/dot-gov.test.js index 0ec4da3..01d0f42 100644 --- a/src/scripts/dot-gov.test.js +++ b/src/scripts/dot-gov.test.js @@ -11,81 +11,81 @@ describe("dot-gov domains", () => { { Agency: "Non-Federal Agency", City: "Albany", - "Domain Name": "ALBANYCA.GOV", - "Domain Type": "City", - Organization: "City of Albany", + "Domain name": "ALBANYCA.GOV", + "Domain type": "City", + "Organization name": "City of Albany", "Security Contact Email": "(blank)", State: "CA", }, { Agency: "Non-Federal Agency", City: "Belle Plaine", - "Domain Name": "BELLEPLAINEIOWA.GOV", - "Domain Type": "City", - Organization: "City of Belle Plaine", + "Domain name": "BELLEPLAINEIOWA.GOV", + "Domain type": "City", + "Organization name": "City of Belle Plaine", "Security Contact Email": "(blank)", State: "IA", }, { Agency: "U.S. Department of Agriculture", City: "Washington", - "Domain Name": "RURAL.GOV", - "Domain Type": "Federal - Executive", - Organization: "Rural Development", + "Domain name": "RURAL.GOV", + "Domain type": "Federal - Executive", + "Organization name": "Rural Development", "Security Contact Email": "cyber.(blank)", State: "DC", }, { Agency: "The Supreme Court", City: "Washington", - "Domain Name": "SUPREMECOURTUS.GOV", - "Domain Type": "Federal - Judicial", - Organization: "Supreme Court of the United Statest", + "Domain name": "SUPREMECOURTUS.GOV", + "Domain type": "Federal - Judicial", + "Organization name": "Supreme Court of the United Statest", "Security Contact Email": "(blank)", State: "DC", }, { Agency: "Government Publishing Office", City: "Washington", - "Domain Name": "USCODE.GOV", - "Domain Type": "Federal - Legislative", - Organization: "United States Government Publishing Office", + "Domain name": "USCODE.GOV", + "Domain type": "Federal - Legislative", + "Organization name": "United States Government Publishing Office", "Security Contact Email": "(blank)", State: "DC", }, { Agency: "Non-Federal Agency", City: "Arizona City", - "Domain Name": "ACSD-AZ.GOV", - "Domain Type": "Independent Intrastate", - Organization: "Arizona City Sanitary District ", + "Domain name": "ACSD-AZ.GOV", + "Domain type": "Independent Intrastate", + "Organization name": "Arizona City Sanitary District ", "Security Contact Email": "(blank)", State: "AZ", }, { Agency: "Non-Federal Agency", City: "Mechanicsburg", - "Domain Name": "EMSCOMPACT.GOV", - "Domain Type": "Interstate", - Organization: "Interstate Commission for EMS Personnel Practice", + "Domain name": "EMSCOMPACT.GOV", + "Domain type": "Interstate", + "Organization name": "Interstate Commission for EMS Personnel Practice", "Security Contact Email": "(blank)", State: "PA", }, { Agency: "Non-Federal Agency", City: "St Croix", - "Domain Name": "VIVOTE.GOV", - "Domain Type": "State", - Organization: "Election System of the Virgin Islands", + "Domain name": "VIVOTE.GOV", + "Domain type": "State", + "Organization name": "Election System of the Virgin Islands", "Security Contact Email": "(blank)", State: "VI", }, { Agency: "Non-Federal Agency", City: "Ada", - "Domain Name": "CHICKASAW-NSN.GOV", - "Domain Type": "Tribal", - Organization: "the Chickasaw Nation", + "Domain name": "CHICKASAW-NSN.GOV", + "Domain type": "Tribal", + "Organization name": "the Chickasaw Nation", "Security Contact Email": "(blank)", State: "OK", }, @@ -175,7 +175,7 @@ describe("dot-gov domains", () => { it("if the API does return some domains", async () => { fetchResponse.text.mockResolvedValue( [ - "Domain Name,Domain Type,Agency,Organization,City,State,Security Contact Email", + "Domain name,Domain type,Agency,Organization name,City,State,Security Contact Email", "ALBANYCA.GOV,City,Non-Federal Agency,City of Albany,Albany,CA,(blank)", "BELLEPLAINEIOWA.GOV,City,Non-Federal Agency,City of Belle Plaine,Belle Plaine,IA,(blank)", "RURAL.GOV,Federal - Executive,U.S. Department of Agriculture,Rural Development,Washington,DC,cyber.(blank)", diff --git a/src/scripts/handbook.js b/src/scripts/handbook.js index 15394af..e6958b0 100644 --- a/src/scripts/handbook.js +++ b/src/scripts/handbook.js @@ -41,15 +41,17 @@ module.exports = (app) => { const { context: { - matches: [, , search], + matches: [, search], }, event: { thread_ts: thread, ts }, say, } = msg; + console.log(msg.context.matches); + const searchString = search - .replace(/[”“]/g, '"') // replace smart quotes - .replace(/[’‘]/g, "'"); // more smart quotes + ?.replace(/[”“]/g, '"') // replace smart quotes + ?.replace(/[’‘]/g, "'"); // more smart quotes const url = `${baseUrl}${encodeURIComponent(searchString)}`; try { diff --git a/src/scripts/handbook.test.js b/src/scripts/handbook.test.js index 62a6bc5..45c2b64 100644 --- a/src/scripts/handbook.test.js +++ b/src/scripts/handbook.test.js @@ -28,7 +28,7 @@ describe("TTS Handbook search", () => { describe("it handles bot triggers", () => { const message = { - context: { matches: [null, null, "search string"] }, + context: { matches: [null, "search string"] }, event: { thread_ts: undefined, ts: 150 }, say: jest.fn(), }; @@ -38,7 +38,7 @@ describe("TTS Handbook search", () => { handbook(app); handler = app.getHandler(); - message.context.matches[2] = "search string"; + message.context.matches[1] = "search string"; }); it("gracefully responds if there is an error", async () => { @@ -53,7 +53,7 @@ describe("TTS Handbook search", () => { }); it("converts characters accordingly before putting them in the search URL", async () => { - message.context.matches[2] = "”some ’search‘ goes here“"; + message.context.matches[1] = "”some ’search‘ goes here“"; await handler(message); expect(fetch).toHaveBeenCalledWith(