@@ -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" ;
2729import { POST } from "../../app/api/contact/route" ;
28- import { notifyContactCreated } from "../../utils/notifyContactCreated " ;
30+ import { notifyContactCreated } from "../../app/(helpers)/slack " ;
2931
3032const 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