From c8b6b6f7d9895137b73ac52f72ddfc2fe26851fe Mon Sep 17 00:00:00 2001 From: Ben Protheroe Date: Fri, 12 May 2023 10:58:39 +0100 Subject: [PATCH] fix(hubspotform): increase test coverage --- .../forms/getHubspotFormPayload.test.ts | 81 +++++++++++++++++-- .../hubspot/forms/getHubspotFormPayloads.ts | 7 +- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/src/browser-lib/hubspot/forms/getHubspotFormPayload.test.ts b/src/browser-lib/hubspot/forms/getHubspotFormPayload.test.ts index 88a8e0c509..c6dcd5bb95 100644 --- a/src/browser-lib/hubspot/forms/getHubspotFormPayload.test.ts +++ b/src/browser-lib/hubspot/forms/getHubspotFormPayload.test.ts @@ -1,9 +1,9 @@ -import { getHubspotNewsletterPayload as getHubspotFormPayload } from "./getHubspotFormPayloads"; +import { getHubspotDownloadsFormPayload, getHubspotNewsletterPayload } from "./getHubspotFormPayloads"; -describe("getHubspotFormPayload()", () => { +describe("getHubspotNewsletterFormPayload()", () => { test("primary form payload is correct", () => { expect( - getHubspotFormPayload({ + getHubspotNewsletterPayload({ hutk: "hubspotutk value 123", data: { email: "email value", @@ -38,7 +38,7 @@ describe("getHubspotFormPayload()", () => { }); test("fallback form payload is correct", () => { expect( - getHubspotFormPayload({ + getHubspotNewsletterPayload({ hutk: "hubspotutk value 456", data: { emailTextOnly: "email value", @@ -63,7 +63,7 @@ describe("getHubspotFormPayload()", () => { }); test("falsy values are removed", () => { expect( - getHubspotFormPayload({ + getHubspotNewsletterPayload({ hutk: "hubspotutk value 456", data: { emailTextOnly: "email value", @@ -86,3 +86,74 @@ describe("getHubspotFormPayload()", () => { }); }); }); +describe("getHubspotDownloadFormPayload()", () => { + test("primary form payload is correct", () => { + expect( + getHubspotDownloadsFormPayload({ + hutk: "hubspotutk value 123", + data: { + email: "email value", + schoolName: "school_name value", + school: "school_id value", + oakUserId: "oak_user_id value", + utm_campaign: "a campaign", + utm_content: "some content", + utm_medium: "some medium", + utm_source: "a source", + utm_term: "term", + }, + }) + ).toEqual({ + fields: [ + { name: "contact_school_name", value: "school_name value" }, + { name: "contact_school_urn", value: "school_id value" }, + { name: "email", value: "email value" }, + { name: "latest_utm_campaign", value: "a campaign" }, + { name: "latest_utm_content", value: "some content" }, + { name: "latest_utm_medium", value: "some medium" }, + { name: "latest_utm_source", value: "a source" }, + { name: "latest_utm_term", value: "term" }, + { name: "oak_user_id", value: "oak_user_id value" }, + ], + context: { + hutk: "hubspotutk value 123", + pageUri: "http://localhost/", + pageName: "", + }, + }); + }); + test("if schoolId === homeschool or notListed return schoolName as schoolId", () => { + expect( + getHubspotDownloadsFormPayload({ + hutk: "hubspotutk value 123", + data: { + email: "email value", + schoolName: "school_name value", + school: "notListed", + oakUserId: "oak_user_id value", + utm_campaign: "a campaign", + utm_content: "some content", + utm_medium: "some medium", + utm_source: "a source", + utm_term: "term", + }, + }) + ).toEqual({ + fields: [ + { name: "contact_school_name", value: "school_name value" }, + { name: "email", value: "email value" }, + { name: "latest_utm_campaign", value: "a campaign" }, + { name: "latest_utm_content", value: "some content" }, + { name: "latest_utm_medium", value: "some medium" }, + { name: "latest_utm_source", value: "a source" }, + { name: "latest_utm_term", value: "term" }, + { name: "oak_user_id", value: "oak_user_id value" }, + ], + context: { + hutk: "hubspotutk value 123", + pageUri: "http://localhost/", + pageName: "", + }, + }); + }); +}); diff --git a/src/browser-lib/hubspot/forms/getHubspotFormPayloads.ts b/src/browser-lib/hubspot/forms/getHubspotFormPayloads.ts index 0bc826cf46..c3ca51232c 100644 --- a/src/browser-lib/hubspot/forms/getHubspotFormPayloads.ts +++ b/src/browser-lib/hubspot/forms/getHubspotFormPayloads.ts @@ -1,4 +1,3 @@ -import { DownloadFormProps } from "../../../components/DownloadComponents/downloads.types"; import { UtmParams } from "../../../hooks/useUtmParams"; import { HubspotPayload } from "./hubspotSubmitForm"; @@ -44,7 +43,11 @@ export type NewsletterSnakeCaseData = typeof getSnakeCaseData extends ( ) => infer U ? U : never; -export type DownloadsHubspotFormData = DownloadFormProps & +export type DownloadsHubspotFormData = { + school: string; + schoolName?: string | undefined; + email?: string | undefined; +} & UtmParams & { oakUserId?: string }; export const getDownloadsSnakeCaseData = (data: DownloadsHubspotFormData) => { return {