1- import { beforeEach , describe , expect , mock , test } from "bun:test" ;
1+ import { afterEach , beforeEach , describe , expect , mock , test } from "bun:test" ;
22import { NextRequest } from "next/server" ;
3+ import { POST as postCalendarEvent } from "@/app/api/v1/milady/google/calendar/events/route" ;
4+ import { GET as getCalendarFeed } from "@/app/api/v1/milady/google/calendar/feed/route" ;
5+ import { POST as postConnectInitiate } from "@/app/api/v1/milady/google/connect/initiate/route" ;
6+ import { POST as postDisconnect } from "@/app/api/v1/milady/google/disconnect/route" ;
7+ import { POST as postReplySend } from "@/app/api/v1/milady/google/gmail/reply-send/route" ;
8+ import { GET as getGmailTriage } from "@/app/api/v1/milady/google/gmail/triage/route" ;
9+ import { GET as getStatus } from "@/app/api/v1/milady/google/status/route" ;
10+ import { miladyGoogleRouteDeps } from "../../lib/services/milady-google-route-deps" ;
311import { jsonRequest } from "./api/route-test-helpers" ;
412
513const mockRequireAuthOrApiKeyWithOrg = mock ( ) ;
@@ -10,46 +18,18 @@ const mockFetchCalendarFeed = mock();
1018const mockCreateCalendarEvent = mock ( ) ;
1119const mockFetchGmailTriage = mock ( ) ;
1220const mockSendReply = mock ( ) ;
13-
14- mock . module ( "@/lib/auth" , ( ) => ( {
15- requireAuthOrApiKeyWithOrg : mockRequireAuthOrApiKeyWithOrg ,
16- } ) ) ;
17-
18- mock . module ( "@/lib/services/milady-google-connector" , ( ) => ( {
19- getManagedGoogleConnectorStatus : mockGetStatus ,
20- initiateManagedGoogleConnection : mockInitiateConnection ,
21- disconnectManagedGoogleConnection : mockDisconnectConnection ,
22- fetchManagedGoogleCalendarFeed : mockFetchCalendarFeed ,
23- createManagedGoogleCalendarEvent : mockCreateCalendarEvent ,
24- fetchManagedGoogleGmailTriage : mockFetchGmailTriage ,
25- sendManagedGoogleReply : mockSendReply ,
26- MiladyGoogleConnectorError : class MiladyGoogleConnectorError extends Error {
27- constructor (
28- public readonly status : number ,
29- message : string ,
30- ) {
31- super ( message ) ;
32- this . name = "MiladyGoogleConnectorError" ;
33- }
34- } ,
35- } ) ) ;
36-
37- const { POST : postCalendarEvent } = await import (
38- "@/app/api/v1/milady/google/calendar/events/route"
39- ) ;
40- const { GET : getCalendarFeed } = await import ( "@/app/api/v1/milady/google/calendar/feed/route" ) ;
41- const { POST : postConnectInitiate } = await import (
42- "@/app/api/v1/milady/google/connect/initiate/route"
43- ) ;
44- const { POST : postDisconnect } = await import ( "@/app/api/v1/milady/google/disconnect/route" ) ;
45- const { POST : postReplySend } = await import ( "@/app/api/v1/milady/google/gmail/reply-send/route" ) ;
46- const { GET : getGmailTriage } = await import ( "@/app/api/v1/milady/google/gmail/triage/route" ) ;
47- const { GET : getStatus } = await import ( "@/app/api/v1/milady/google/status/route" ) ;
48-
49- mock . restore ( ) ;
21+ const originalRouteDeps = { ...miladyGoogleRouteDeps } ;
5022
5123describe ( "Milady managed Google routes" , ( ) => {
5224 beforeEach ( ( ) => {
25+ miladyGoogleRouteDeps . requireAuthOrApiKeyWithOrg = mockRequireAuthOrApiKeyWithOrg ;
26+ miladyGoogleRouteDeps . getManagedGoogleConnectorStatus = mockGetStatus ;
27+ miladyGoogleRouteDeps . initiateManagedGoogleConnection = mockInitiateConnection ;
28+ miladyGoogleRouteDeps . disconnectManagedGoogleConnection = mockDisconnectConnection ;
29+ miladyGoogleRouteDeps . fetchManagedGoogleCalendarFeed = mockFetchCalendarFeed ;
30+ miladyGoogleRouteDeps . createManagedGoogleCalendarEvent = mockCreateCalendarEvent ;
31+ miladyGoogleRouteDeps . fetchManagedGoogleGmailTriage = mockFetchGmailTriage ;
32+ miladyGoogleRouteDeps . sendManagedGoogleReply = mockSendReply ;
5333 mockRequireAuthOrApiKeyWithOrg . mockReset ( ) ;
5434 mockGetStatus . mockReset ( ) ;
5535 mockInitiateConnection . mockReset ( ) ;
@@ -67,6 +47,10 @@ describe("Milady managed Google routes", () => {
6747 } ) ;
6848 } ) ;
6949
50+ afterEach ( ( ) => {
51+ Object . assign ( miladyGoogleRouteDeps , originalRouteDeps ) ;
52+ } ) ;
53+
7054 test ( "GET /api/v1/milady/google/status returns the managed connector status" , async ( ) => {
7155 mockGetStatus . mockResolvedValue ( {
7256 provider : "google" ,
0 commit comments