Skip to content

Commit

Permalink
fix(hubspotform): increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Protheroe authored and Ben Protheroe committed May 12, 2023
1 parent 18e0fc2 commit c8b6b6f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 7 deletions.
81 changes: 76 additions & 5 deletions src/browser-lib/hubspot/forms/getHubspotFormPayload.test.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -38,7 +38,7 @@ describe("getHubspotFormPayload()", () => {
});
test("fallback form payload is correct", () => {
expect(
getHubspotFormPayload({
getHubspotNewsletterPayload({
hutk: "hubspotutk value 456",
data: {
emailTextOnly: "email value",
Expand All @@ -63,7 +63,7 @@ describe("getHubspotFormPayload()", () => {
});
test("falsy values are removed", () => {
expect(
getHubspotFormPayload({
getHubspotNewsletterPayload({
hutk: "hubspotutk value 456",
data: {
emailTextOnly: "email value",
Expand All @@ -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: "",
},
});
});
});
7 changes: 5 additions & 2 deletions src/browser-lib/hubspot/forms/getHubspotFormPayloads.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DownloadFormProps } from "../../../components/DownloadComponents/downloads.types";
import { UtmParams } from "../../../hooks/useUtmParams";

import { HubspotPayload } from "./hubspotSubmitForm";
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c8b6b6f

Please sign in to comment.