Skip to content

Commit de921a3

Browse files
committed
Made needed updates after rebase and changes
1 parent aa02380 commit de921a3

File tree

5 files changed

+44
-36
lines changed

5 files changed

+44
-36
lines changed

apps/contact/app/api/contact/route.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { processContact } from "@/app/(helpers)/notion";
2-
import { notifyContactCreated } from "../../../utils/notifyContactCreated";
3-
import { Client, isFullPage } from "@notionhq/client";
1+
import { processContact } from "../../../app/(helpers)/notion";
42
import { nanoid } from "nanoid";
53
import { NextRequest } from "next/server";
64
import z from "zod";

apps/contact/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"build": "next build",
99
"start": "next start",
1010
"lint": "next lint",
11-
"playwright": "npx playwright test",
12-
"test": "npx jest"
11+
"test": "npx jest && npx playwright test"
1312
},
1413
"dependencies": {
1514
"react": "^19.0.0",

apps/contact/tests/e2e/form.spec.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ test.describe("Form page", () => {
3535
test("should support input of data and submission of a form", async ({
3636
page,
3737
}) => {
38-
await page.route(routeUrl, (route) => {
39-
route.fulfill({
38+
await page.route(`${routeUrl}**`, async (route) => {
39+
await route.fulfill({
4040
status: 200,
4141
contentType: "application/json",
4242
body: JSON.stringify({
@@ -71,11 +71,8 @@ test.describe("Form submission from home page", () => {
7171
});
7272

7373
test("sucessfull", async ({ page }) => {
74-
await expect(
75-
page.getByRole("heading", { name: "Let’s Talk About Your Project" }),
76-
).toBeVisible();
77-
await page.route(routeUrl, (route) => {
78-
route.fulfill({
74+
await page.route(`${routeUrl}**`, async (route) => {
75+
await route.fulfill({
7976
status: 200,
8077
contentType: "application/json",
8178
body: JSON.stringify({
@@ -85,7 +82,11 @@ test.describe("Form submission from home page", () => {
8582
}),
8683
});
8784
});
85+
8886
await page.getByRole("navigation").getByText("Contact us").last().click();
87+
await expect(
88+
page.getByRole("heading", { name: "Let’s Talk About Your Project" }),
89+
).toBeVisible();
8990

9091
await page.getByPlaceholder("Full name *").fill("Test name");
9192
await page.getByPlaceholder("E-mail *").fill("test@test.com");
@@ -106,16 +107,15 @@ test.describe("Form submission from home page", () => {
106107
await page.waitForURL(`${baseUrl}/`);
107108

108109
await expect(
109-
page.getByRole("heading", { name: "Let’s Talk About Your Project" }),
110+
page.getByRole("heading", {
111+
name: "Building Software that Builds Your Business",
112+
}),
110113
).toBeVisible();
111114
});
112115

113116
test("unsucessfull", async ({ page }) => {
114-
await expect(
115-
page.getByRole("heading", { name: "Let’s Talk About Your Project" }),
116-
).toBeVisible();
117-
await page.route(routeUrl, (route) => {
118-
route.fulfill({
117+
await page.route(`${routeUrl}**`, async (route) => {
118+
await route.fulfill({
119119
status: 501,
120120
contentType: "application/json",
121121
body: JSON.stringify({
@@ -124,7 +124,11 @@ test.describe("Form submission from home page", () => {
124124
}),
125125
});
126126
});
127+
127128
await page.getByRole("navigation").getByText("Contact us").last().click();
129+
await expect(
130+
page.getByRole("heading", { name: "Let’s Talk About Your Project" }),
131+
).toBeVisible();
128132

129133
await page.getByPlaceholder("Full name *").fill("Test name");
130134
await page.getByPlaceholder("E-mail *").fill("test@test.com");

apps/contact/tests/e2e/formMobile.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ test.describe("Form page in mobile view", () => {
4646
});
4747

4848
test("should support input of data and submission of a form", async () => {
49-
await page.route(routeUrl, (route) => {
50-
route.fulfill({
49+
await page.route(`${routeUrl}**`, async (route) => {
50+
await route.fulfill({
5151
status: 200,
5252
contentType: "application/json",
5353
body: JSON.stringify({
@@ -95,11 +95,12 @@ test.describe("Form submission in mobile view from home page", () => {
9595
});
9696

9797
test("sucessfull", async () => {
98+
await page.getByRole("link", { name: "Contact us", exact: true }).click();
9899
await expect(
99100
page.getByRole("heading", { name: "Let’s Talk About Your Project" }),
100101
).toBeVisible();
101-
await page.route(routeUrl, (route) => {
102-
route.fulfill({
102+
await page.route(`${routeUrl}**`, async (route) => {
103+
await route.fulfill({
103104
status: 200,
104105
contentType: "application/json",
105106
body: JSON.stringify({
@@ -109,7 +110,6 @@ test.describe("Form submission in mobile view from home page", () => {
109110
}),
110111
});
111112
});
112-
await page.getByRole("link", { name: "Contact us", exact: true }).click();
113113

114114
await page.getByPlaceholder("Full name *").fill("Test name");
115115
await page.getByPlaceholder("E-mail *").fill("test@test.com");
@@ -130,16 +130,19 @@ test.describe("Form submission in mobile view from home page", () => {
130130
await page.waitForURL(`${baseUrl}/`);
131131

132132
await expect(
133-
page.getByRole("heading", { name: "Let’s Talk About Your Project" }),
133+
page.getByRole("heading", {
134+
name: "Building Software that Builds Your Business",
135+
}),
134136
).toBeVisible();
135137
});
136138

137139
test("unsucessfull", async () => {
140+
await page.getByRole("link", { name: "Contact us", exact: true }).click();
138141
await expect(
139142
page.getByRole("heading", { name: "Let’s Talk About Your Project" }),
140143
).toBeVisible();
141-
await page.route(routeUrl, (route) => {
142-
route.fulfill({
144+
await page.route(`${routeUrl}**`, async (route) => {
145+
await route.fulfill({
143146
status: 501,
144147
contentType: "application/json",
145148
body: JSON.stringify({
@@ -148,7 +151,6 @@ test.describe("Form submission in mobile view from home page", () => {
148151
}),
149152
});
150153
});
151-
await page.getByRole("link", { name: "Contact us", exact: true }).click();
152154

153155
await page.getByPlaceholder("Full name *").fill("Test name");
154156
await page.getByPlaceholder("E-mail *").fill("test@test.com");

apps/contact/tests/jest/form.test.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ jest.mock("@notionhq/client", () => {
1717
};
1818
});
1919

20-
jest.mock("../../utils/notifyContactCreated", () => {
20+
jest.mock("../../app/(helpers)/slack", () => {
2121
return {
2222
notifyContactCreated: jest.fn(),
2323
};
2424
});
2525

26-
import { Request } from "@whatwg-node/fetch";
26+
process.env.NOTION_DATABASE_ID = "mocked-notion-database-id";
27+
28+
import { NextRequest } from "next/server";
2729
import { POST } from "../../app/api/contact/route";
28-
import { notifyContactCreated } from "../../utils/notifyContactCreated";
30+
import { notifyContactCreated } from "../../app/(helpers)/slack";
2931

3032
const mockSlack = notifyContactCreated as jest.Mock;
3133

@@ -50,9 +52,12 @@ describe("POST /api/contact", () => {
5052
const { isFullPage } = require("@notionhq/client");
5153
isFullPage.mockImplementation(() => true);
5254
});
55+
afterAll(() => {
56+
delete process.env.NOTION_DATABASE_ID;
57+
});
5358

5459
it("should call Notion, Slack and return 200 response on success", async () => {
55-
const request = new Request("http://localhost", {
60+
const request = new NextRequest("http://localhost", {
5661
method: "POST",
5762
body: JSON.stringify(mockBody),
5863
headers: {
@@ -70,7 +75,7 @@ describe("POST /api/contact", () => {
7075
});
7176

7277
it("shouldn't call Notion or Slack and return 400 response when incorect header Content-Type is set", async () => {
73-
const request = new Request("http://localhost", {
78+
const request = new NextRequest("http://localhost", {
7479
method: "POST",
7580
body: JSON.stringify(mockBody),
7681
headers: {
@@ -88,7 +93,7 @@ describe("POST /api/contact", () => {
8893
it("should call Notion but not Slack if isFullPage is false", async () => {
8994
const { isFullPage } = require("@notionhq/client");
9095
isFullPage.mockImplementation(() => false);
91-
const request = new Request("http://localhost", {
96+
const request = new NextRequest("http://localhost", {
9297
method: "POST",
9398
body: JSON.stringify(mockBody),
9499
headers: {
@@ -107,7 +112,7 @@ describe("POST /api/contact", () => {
107112

108113
it("should call Notion but not Slack if the page is not created", async () => {
109114
mockNotion.mockResolvedValue({ id: undefined });
110-
const request = new Request("http://localhost", {
115+
const request = new NextRequest("http://localhost", {
111116
method: "POST",
112117
body: JSON.stringify(mockBody),
113118
headers: {
@@ -125,7 +130,7 @@ describe("POST /api/contact", () => {
125130
});
126131

127132
it("shouldn't call Notion or Slack and return 400 response when no body was passed", async () => {
128-
const request = new Request("http://localhost", {
133+
const request = new NextRequest("http://localhost", {
129134
method: "POST",
130135
body: JSON.stringify({}),
131136
headers: {
@@ -142,7 +147,7 @@ describe("POST /api/contact", () => {
142147
});
143148

144149
it("should return 403 response when no consent from user", async () => {
145-
const request = new Request("http://localhost", {
150+
const request = new NextRequest("http://localhost", {
146151
method: "POST",
147152
body: JSON.stringify(mockNoConsent),
148153
headers: {

0 commit comments

Comments
 (0)