From 8e11f2fd89c98e0a29835bac993f938b0db36386 Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 11:47:50 -0400 Subject: [PATCH 01/11] fix(): update client key to empty string --- packages/common/src/sites/domains/add-domain.ts | 3 +++ packages/common/src/sites/domains/update-domain.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/packages/common/src/sites/domains/add-domain.ts b/packages/common/src/sites/domains/add-domain.ts index d0f8103ea54..52b29e058a4 100644 --- a/packages/common/src/sites/domains/add-domain.ts +++ b/packages/common/src/sites/domains/add-domain.ts @@ -25,6 +25,9 @@ export function addDomain( if (typeof title === "number") { domainEntry.siteTitle = title.toString(); } + if (domainEntry?.clientKey) { + domainEntry.clientKey = ""; + } return fetch(url, { method: "POST", headers, diff --git a/packages/common/src/sites/domains/update-domain.ts b/packages/common/src/sites/domains/update-domain.ts index 7855bd62cf8..77bd3ef5650 100644 --- a/packages/common/src/sites/domains/update-domain.ts +++ b/packages/common/src/sites/domains/update-domain.ts @@ -28,6 +28,12 @@ export function updateDomain( if (typeof title === "number") { domainEntry.siteTitle = title.toString(); } + + // delete client key if we have one, as it won't pass schema validation + if (domainEntry.clientKey) { + domainEntry.clientKey = ""; + } + return fetch(url, { method: "PUT", headers, From 3c428156297c9f9493f4928e8736539d1e08a46b Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 11:51:09 -0400 Subject: [PATCH 02/11] style(): update comments --- packages/common/src/sites/domains/add-domain.ts | 1 + packages/common/src/sites/domains/update-domain.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/common/src/sites/domains/add-domain.ts b/packages/common/src/sites/domains/add-domain.ts index 52b29e058a4..643fb65f15b 100644 --- a/packages/common/src/sites/domains/add-domain.ts +++ b/packages/common/src/sites/domains/add-domain.ts @@ -25,6 +25,7 @@ export function addDomain( if (typeof title === "number") { domainEntry.siteTitle = title.toString(); } + // update client key to empty string if we have one, as it won't pass schema validation if (domainEntry?.clientKey) { domainEntry.clientKey = ""; } diff --git a/packages/common/src/sites/domains/update-domain.ts b/packages/common/src/sites/domains/update-domain.ts index 77bd3ef5650..4364d19b3bc 100644 --- a/packages/common/src/sites/domains/update-domain.ts +++ b/packages/common/src/sites/domains/update-domain.ts @@ -29,7 +29,7 @@ export function updateDomain( domainEntry.siteTitle = title.toString(); } - // delete client key if we have one, as it won't pass schema validation + // update client key to empty string if we have one, as it won't pass schema validation if (domainEntry.clientKey) { domainEntry.clientKey = ""; } From ce48dce1488e9644484f51acfbbf9f1ba7e5091f Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 12:07:33 -0400 Subject: [PATCH 03/11] test(): add test examples without client key --- .../test/sites/domains/add-domain.test.ts | 28 +++++++++++++++++++ .../test/sites/domains/update-domain.test.ts | 27 ++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/packages/common/test/sites/domains/add-domain.test.ts b/packages/common/test/sites/domains/add-domain.test.ts index 8b1b84da5a9..70eff27a35c 100644 --- a/packages/common/test/sites/domains/add-domain.test.ts +++ b/packages/common/test/sites/domains/add-domain.test.ts @@ -67,6 +67,34 @@ describe("addDomain", function () { expect(res.success).toBeTruthy("json parsed and response returned"); }); + it("handles not having a client key", async function () { + const ro = { isPortal: false } as IHubRequestOptions; + + spyOn( + _checkStatusAndParseJsonModule, + "_checkStatusAndParseJson" + ).and.returnValue(Promise.resolve({ success: true })); + + fetchMock.post("end:api/v3/domains", {}); + + const entry = { + domain: "zebra-dc.hubqa.arcgis.com", + hostname: "zebra-dc.hubqa.arcgis.com", + id: "146663", + orgId: "97KLIFOSt5CxbiRI", + orgKey: "dc", + orgTitle: "Washington, DC R&D Center (QA)", + permanentRedirect: false, + siteId: "9697f67b6d6343fa823dcdbe2d172073", + siteTitle: "Zebra", + sslOnly: true, + }; + + const res = await addDomain(entry, ro); + expect(fetchMock.done()).toBeTruthy("fetch should have been called once"); + expect(res.success).toBeTruthy("json parsed and response returned"); + }); + it("throws error on portal", async function () { const ro = { isPortal: true } as IHubRequestOptions; diff --git a/packages/common/test/sites/domains/update-domain.test.ts b/packages/common/test/sites/domains/update-domain.test.ts index 7ecde49440a..493c3a794e7 100644 --- a/packages/common/test/sites/domains/update-domain.test.ts +++ b/packages/common/test/sites/domains/update-domain.test.ts @@ -84,4 +84,31 @@ describe("updateDomain", function () { "fetch should NOT have been called" ); }); + + it("updates domain when no client key is passed in", async function () { + const ro = { isPortal: false } as IHubRequestOptions; + + spyOn( + _checkStatusAndParseJsonModule, + "_checkStatusAndParseJson" + ).and.returnValue(Promise.resolve({ success: true })); + + const entry = { + domain: "zebra-dc.hubqa.arcgis.com", + hostname: "zebra-dc.hubqa.arcgis.com", + id: "146663", + orgId: "97KLIFOSt5CxbiRI", + orgKey: "dc", + orgTitle: "Washington, DC R&D Center (QA)", + permanentRedirect: false, + siteId: "9697f67b6d6343fa823dcdbe2d172073", + siteTitle: "Zebra", + sslOnly: true, + }; + fetchMock.put(`end:api/v3/domains/${entry.id}`, {}); + + const res = await updateDomain(entry, ro); + expect(fetchMock.done()).toBeTruthy("fetch should have been called once"); + expect(res.success).toBeTruthy("json parsed and response returned"); + }); }); From 208c5a914ece1277c3ce9c27f76bcbcdb571cc88 Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 12:36:55 -0400 Subject: [PATCH 04/11] test(): code coverage --- .../test/sites/domains/add-domain.test.ts | 33 +++++++++++++++++++ .../test/sites/domains/update-domain.test.ts | 33 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/packages/common/test/sites/domains/add-domain.test.ts b/packages/common/test/sites/domains/add-domain.test.ts index 70eff27a35c..fcc9d84c639 100644 --- a/packages/common/test/sites/domains/add-domain.test.ts +++ b/packages/common/test/sites/domains/add-domain.test.ts @@ -67,6 +67,39 @@ describe("addDomain", function () { expect(res.success).toBeTruthy("json parsed and response returned"); }); + it("converts title to string", async function () { + const entry = { + domain: "zebra-dc.hubqa.arcgis.com", + hostname: "zebra-dc.hubqa.arcgis.com", + id: "146663", + orgId: "97KLIFOSt5CxbiRI", + orgKey: "dc", + orgTitle: "Washington, DC R&D Center (QA)", + permanentRedirect: false, + siteId: "9697f67b6d6343fa823dcdbe2d172073", + siteTitle: 1234, + sslOnly: true, + } as unknown as IDomainEntry; + const ro = { isPortal: false } as IHubRequestOptions; + + spyOn( + _checkStatusAndParseJsonModule, + "_checkStatusAndParseJson" + ).and.returnValue(Promise.resolve({ success: true })); + + fetchMock.post("end:api/v3/domains", {}); + + const res = await addDomain(entry, ro); + expect(fetchMock.done()).toBeTruthy("fetch should have been called once"); + const opts = fetchMock.lastOptions("end:api/v3/domains"); + const body = JSON.parse(opts.body as string); + expect(getProp(body, "siteTitle")).toBe( + "1234", + "should coerce numeric title to a string" + ); + expect(res.success).toBeTruthy("json parsed and response returned"); + }); + it("handles not having a client key", async function () { const ro = { isPortal: false } as IHubRequestOptions; diff --git a/packages/common/test/sites/domains/update-domain.test.ts b/packages/common/test/sites/domains/update-domain.test.ts index 493c3a794e7..872ab6ae3fc 100644 --- a/packages/common/test/sites/domains/update-domain.test.ts +++ b/packages/common/test/sites/domains/update-domain.test.ts @@ -67,6 +67,39 @@ describe("updateDomain", function () { expect(res.success).toBeTruthy("json parsed and response returned"); }); + it("converts title to a string", async function () { + const entry = { + domain: "zebra-dc.hubqa.arcgis.com", + hostname: "zebra-dc.hubqa.arcgis.com", + id: "146663", + orgId: "97KLIFOSt5CxbiRI", + orgKey: "dc", + orgTitle: "Washington, DC R&D Center (QA)", + permanentRedirect: false, + siteId: "9697f67b6d6343fa823dcdbe2d172073", + siteTitle: 1234, + sslOnly: true, + } as unknown as IDomainEntry; + const ro = { isPortal: false } as IHubRequestOptions; + + spyOn( + _checkStatusAndParseJsonModule, + "_checkStatusAndParseJson" + ).and.returnValue(Promise.resolve({ success: true })); + + fetchMock.put(`end:api/v3/domains/${entry.id}`, {}); + + const res = await updateDomain(entry, ro); + expect(fetchMock.done()).toBeTruthy("fetch should have been called once"); + const opts = fetchMock.lastOptions(`end:api/v3/domains/${entry.id}`); + const body = JSON.parse(opts.body as string); + expect(getProp(body, "siteTitle")).toBe( + "1234", + "should coerce numeric title to a string" + ); + expect(res.success).toBeTruthy("json parsed and response returned"); + }); + it("throws error on portal", async function () { const ro = { isPortal: true } as IHubRequestOptions; From 1e73d8a445cefe44e70311d85fe65d6af6af8e51 Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 12:38:44 -0400 Subject: [PATCH 05/11] test(): update test name --- packages/common/test/sites/domains/add-domain.test.ts | 2 +- packages/common/test/sites/domains/update-domain.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/common/test/sites/domains/add-domain.test.ts b/packages/common/test/sites/domains/add-domain.test.ts index fcc9d84c639..e4481d67893 100644 --- a/packages/common/test/sites/domains/add-domain.test.ts +++ b/packages/common/test/sites/domains/add-domain.test.ts @@ -67,7 +67,7 @@ describe("addDomain", function () { expect(res.success).toBeTruthy("json parsed and response returned"); }); - it("converts title to string", async function () { + it("converts title to string without client key", async function () { const entry = { domain: "zebra-dc.hubqa.arcgis.com", hostname: "zebra-dc.hubqa.arcgis.com", diff --git a/packages/common/test/sites/domains/update-domain.test.ts b/packages/common/test/sites/domains/update-domain.test.ts index 872ab6ae3fc..2459adab6f9 100644 --- a/packages/common/test/sites/domains/update-domain.test.ts +++ b/packages/common/test/sites/domains/update-domain.test.ts @@ -67,7 +67,7 @@ describe("updateDomain", function () { expect(res.success).toBeTruthy("json parsed and response returned"); }); - it("converts title to a string", async function () { + it("converts title to a string without client key", async function () { const entry = { domain: "zebra-dc.hubqa.arcgis.com", hostname: "zebra-dc.hubqa.arcgis.com", From 1e98af87e3ab70f1a956193cf0cd14e747e9607c Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 12:45:02 -0400 Subject: [PATCH 06/11] test(): fighting code coverage --- packages/common/src/sites/domains/add-domain.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/common/src/sites/domains/add-domain.ts b/packages/common/src/sites/domains/add-domain.ts index 643fb65f15b..7072adc5fb2 100644 --- a/packages/common/src/sites/domains/add-domain.ts +++ b/packages/common/src/sites/domains/add-domain.ts @@ -25,10 +25,10 @@ export function addDomain( if (typeof title === "number") { domainEntry.siteTitle = title.toString(); } - // update client key to empty string if we have one, as it won't pass schema validation - if (domainEntry?.clientKey) { - domainEntry.clientKey = ""; - } + // // update client key to empty string if we have one, as it won't pass schema validation + // if (domainEntry?.clientKey) { + // domainEntry.clientKey = ""; + // } return fetch(url, { method: "POST", headers, From 4d9e6e0ba3f3d03f497844726b339a39528faf3e Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 12:55:07 -0400 Subject: [PATCH 07/11] fix(): get rid of optional chaining --- packages/common/src/sites/domains/add-domain.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/common/src/sites/domains/add-domain.ts b/packages/common/src/sites/domains/add-domain.ts index 7072adc5fb2..db00aa9a2e7 100644 --- a/packages/common/src/sites/domains/add-domain.ts +++ b/packages/common/src/sites/domains/add-domain.ts @@ -25,10 +25,10 @@ export function addDomain( if (typeof title === "number") { domainEntry.siteTitle = title.toString(); } - // // update client key to empty string if we have one, as it won't pass schema validation - // if (domainEntry?.clientKey) { - // domainEntry.clientKey = ""; - // } + // update client key to empty string if we have one, as it won't pass schema validation + if (domainEntry.clientKey) { + domainEntry.clientKey = ""; + } return fetch(url, { method: "POST", headers, From 45862204bb0661528c967a62cc46a1256dd74eba Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 13:20:50 -0400 Subject: [PATCH 08/11] test(): check value of clientKey --- packages/common/test/sites/domains/add-domain.test.ts | 10 ++++++++++ .../common/test/sites/domains/update-domain.test.ts | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/common/test/sites/domains/add-domain.test.ts b/packages/common/test/sites/domains/add-domain.test.ts index e4481d67893..6867f07f3ae 100644 --- a/packages/common/test/sites/domains/add-domain.test.ts +++ b/packages/common/test/sites/domains/add-domain.test.ts @@ -31,6 +31,12 @@ describe("addDomain", function () { const res = await addDomain(domainEntry, ro); expect(fetchMock.done()).toBeTruthy("fetch should have been called once"); expect(res.success).toBeTruthy("json parsed and response returned"); + const opts = fetchMock.lastOptions("end:api/v3/domains"); + const body = JSON.parse(opts.body as string); + expect(getProp(body, "clientKey")).toBe( + "", + "should update clientKey to empty string" + ); }); it("converts title to string", async function () { @@ -65,6 +71,10 @@ describe("addDomain", function () { "should coerce numeric title to a string" ); expect(res.success).toBeTruthy("json parsed and response returned"); + expect(getProp(body, "clientKey")).toBe( + "", + "should update clientKey to empty string" + ); }); it("converts title to string without client key", async function () { diff --git a/packages/common/test/sites/domains/update-domain.test.ts b/packages/common/test/sites/domains/update-domain.test.ts index 2459adab6f9..e9ad85ca941 100644 --- a/packages/common/test/sites/domains/update-domain.test.ts +++ b/packages/common/test/sites/domains/update-domain.test.ts @@ -31,6 +31,12 @@ describe("updateDomain", function () { const res = await updateDomain(domainEntry, ro); expect(fetchMock.done()).toBeTruthy("fetch should have been called once"); expect(res.success).toBeTruthy("json parsed and response returned"); + const opts = fetchMock.lastOptions(`end:api/v3/domains/${domainEntry.id}`); + const body = JSON.parse(opts.body as string); + expect(getProp(body, "clientKey")).toBe( + "", + "should update clientKey to empty string" + ); }); it("converts title to a string", async function () { @@ -64,6 +70,10 @@ describe("updateDomain", function () { "1234", "should coerce numeric title to a string" ); + expect(getProp(body, "clientKey")).toBe( + "", + "should update clientKey to empty string" + ); expect(res.success).toBeTruthy("json parsed and response returned"); }); From 66967651121d757858854ed4d8aea5c58759ffa0 Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 13:30:24 -0400 Subject: [PATCH 09/11] test(): update client key tests --- packages/common/test/sites/domains/add-domain.test.ts | 5 ++++- packages/common/test/sites/domains/update-domain.test.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/common/test/sites/domains/add-domain.test.ts b/packages/common/test/sites/domains/add-domain.test.ts index 6867f07f3ae..90007bc4f1b 100644 --- a/packages/common/test/sites/domains/add-domain.test.ts +++ b/packages/common/test/sites/domains/add-domain.test.ts @@ -110,7 +110,7 @@ describe("addDomain", function () { expect(res.success).toBeTruthy("json parsed and response returned"); }); - it("handles not having a client key", async function () { + it("function runs as expected without a client key (code coverage)", async function () { const ro = { isPortal: false } as IHubRequestOptions; spyOn( @@ -136,6 +136,9 @@ describe("addDomain", function () { const res = await addDomain(entry, ro); expect(fetchMock.done()).toBeTruthy("fetch should have been called once"); expect(res.success).toBeTruthy("json parsed and response returned"); + const opts = fetchMock.lastOptions("end:api/v3/domains"); + const body = JSON.parse(opts.body as string); + expect(getProp(body, "clientKey")).toBe(null, "should not have clientKey"); }); it("throws error on portal", async function () { diff --git a/packages/common/test/sites/domains/update-domain.test.ts b/packages/common/test/sites/domains/update-domain.test.ts index e9ad85ca941..6086f4d9f2d 100644 --- a/packages/common/test/sites/domains/update-domain.test.ts +++ b/packages/common/test/sites/domains/update-domain.test.ts @@ -128,7 +128,7 @@ describe("updateDomain", function () { ); }); - it("updates domain when no client key is passed in", async function () { + it("function runs as expected without a client key (code coverage)", async function () { const ro = { isPortal: false } as IHubRequestOptions; spyOn( @@ -153,5 +153,8 @@ describe("updateDomain", function () { const res = await updateDomain(entry, ro); expect(fetchMock.done()).toBeTruthy("fetch should have been called once"); expect(res.success).toBeTruthy("json parsed and response returned"); + const opts = fetchMock.lastOptions("end:api/v3/domains"); + const body = JSON.parse(opts.body as string); + expect(getProp(body, "clientKey")).toBe(null, "should not have clientKey"); }); }); From 0c24d5482dda7812f5b189dd0442147efab0667a Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 13:43:05 -0400 Subject: [PATCH 10/11] test(): correct tests --- packages/common/test/sites/domains/add-domain.test.ts | 7 +++++-- packages/common/test/sites/domains/update-domain.test.ts | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/common/test/sites/domains/add-domain.test.ts b/packages/common/test/sites/domains/add-domain.test.ts index 90007bc4f1b..2f80fd47f83 100644 --- a/packages/common/test/sites/domains/add-domain.test.ts +++ b/packages/common/test/sites/domains/add-domain.test.ts @@ -70,11 +70,11 @@ describe("addDomain", function () { "1234", "should coerce numeric title to a string" ); - expect(res.success).toBeTruthy("json parsed and response returned"); expect(getProp(body, "clientKey")).toBe( "", "should update clientKey to empty string" ); + expect(res.success).toBeTruthy("json parsed and response returned"); }); it("converts title to string without client key", async function () { @@ -138,7 +138,10 @@ describe("addDomain", function () { expect(res.success).toBeTruthy("json parsed and response returned"); const opts = fetchMock.lastOptions("end:api/v3/domains"); const body = JSON.parse(opts.body as string); - expect(getProp(body, "clientKey")).toBe(null, "should not have clientKey"); + expect(getProp(body, "clientKey")).toBe( + undefined, + "should not have clientKey" + ); }); it("throws error on portal", async function () { diff --git a/packages/common/test/sites/domains/update-domain.test.ts b/packages/common/test/sites/domains/update-domain.test.ts index 6086f4d9f2d..c83a9a94dd9 100644 --- a/packages/common/test/sites/domains/update-domain.test.ts +++ b/packages/common/test/sites/domains/update-domain.test.ts @@ -153,8 +153,11 @@ describe("updateDomain", function () { const res = await updateDomain(entry, ro); expect(fetchMock.done()).toBeTruthy("fetch should have been called once"); expect(res.success).toBeTruthy("json parsed and response returned"); - const opts = fetchMock.lastOptions("end:api/v3/domains"); + const opts = fetchMock.lastOptions(`end:api/v3/domains/${entry.id}`); const body = JSON.parse(opts.body as string); - expect(getProp(body, "clientKey")).toBe(null, "should not have clientKey"); + expect(getProp(body, "clientKey")).toBe( + undefined, + "should not have clientKey" + ); }); }); From 7247f78200bd1bc111e11dec1cdd027673552344 Mon Sep 17 00:00:00 2001 From: Jordan Sanz Date: Fri, 11 Aug 2023 13:59:07 -0400 Subject: [PATCH 11/11] test(): check client key on test --- packages/common/test/sites/domains/add-domain.test.ts | 4 ++++ packages/common/test/sites/domains/update-domain.test.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/common/test/sites/domains/add-domain.test.ts b/packages/common/test/sites/domains/add-domain.test.ts index 2f80fd47f83..18b079c1d78 100644 --- a/packages/common/test/sites/domains/add-domain.test.ts +++ b/packages/common/test/sites/domains/add-domain.test.ts @@ -107,6 +107,10 @@ describe("addDomain", function () { "1234", "should coerce numeric title to a string" ); + expect(getProp(body, "clientKey")).toBe( + undefined, + "should not have client key" + ); expect(res.success).toBeTruthy("json parsed and response returned"); }); diff --git a/packages/common/test/sites/domains/update-domain.test.ts b/packages/common/test/sites/domains/update-domain.test.ts index c83a9a94dd9..7a70f47bb48 100644 --- a/packages/common/test/sites/domains/update-domain.test.ts +++ b/packages/common/test/sites/domains/update-domain.test.ts @@ -107,6 +107,10 @@ describe("updateDomain", function () { "1234", "should coerce numeric title to a string" ); + expect(getProp(body, "clientKey")).toBe( + undefined, + "should not have client key" + ); expect(res.success).toBeTruthy("json parsed and response returned"); });