11import { beforeEach , describe , expect , it , vi } from "vitest" ;
22
3+ vi . hoisted ( ( ) => {
4+ process . env . NTFY_WISHES_ID = "baby-wishes" ;
5+ } ) ;
6+
37vi . mock ( "@workspace/flags" , ( ) => ( {
48 enableShareWishes : vi . fn ( ) ,
59} ) ) ;
@@ -13,13 +17,19 @@ vi.mock("@workspace/database", () => ({
1317 } ,
1418} ) ) ;
1519
20+ vi . mock ( "@workspace/ntfy" , ( ) => ( {
21+ publish : vi . fn ( ) ,
22+ } ) ) ;
23+
1624import { db } from "@workspace/database" ;
1725import { enableShareWishes } from "@workspace/flags" ;
26+ import { publish } from "@workspace/ntfy" ;
1827import { getPublicWishes , submitWish } from "./wishes" ;
1928
2029const mockSubmit = vi . mocked ( db . wishes . submit ) ;
2130const mockReadPublic = vi . mocked ( db . wishes . readPublic ) ;
2231const mockEnableShareWishes = vi . mocked ( enableShareWishes ) ;
32+ const mockPublish = vi . mocked ( publish ) ;
2333
2434function createFormData ( data : {
2535 name ?: string ;
@@ -39,6 +49,7 @@ describe("wishes actions", () => {
3949 beforeEach ( ( ) => {
4050 vi . clearAllMocks ( ) ;
4151 mockEnableShareWishes . mockResolvedValue ( true ) ;
52+ mockPublish . mockResolvedValue ( new Response ( ) ) ;
4253 } ) ;
4354
4455 describe ( "submitWish" , ( ) => {
@@ -60,6 +71,12 @@ describe("wishes actions", () => {
6071 message : "Congratulations!" ,
6172 isPublic : true ,
6273 } ) ;
74+ expect ( mockPublish ) . toHaveBeenCalledWith ( {
75+ topic : "baby-wishes" ,
76+ title : "New wish from John Doe (john@example.com)" ,
77+ message : "Congratulations!" ,
78+ tags : [ "baby" , "heart" ] ,
79+ } ) ;
6380 } ) ;
6481
6582 it ( "submits a private wish when isPublic is not checked" , async ( ) => {
@@ -93,6 +110,7 @@ describe("wishes actions", () => {
93110 ) . rejects . toThrow ( "Missing required fields" ) ;
94111
95112 expect ( mockSubmit ) . not . toHaveBeenCalled ( ) ;
113+ expect ( mockPublish ) . not . toHaveBeenCalled ( ) ;
96114 } ) ;
97115
98116 it ( "throws error when email is missing" , async ( ) => {
@@ -106,6 +124,7 @@ describe("wishes actions", () => {
106124 ) . rejects . toThrow ( "Missing required fields" ) ;
107125
108126 expect ( mockSubmit ) . not . toHaveBeenCalled ( ) ;
127+ expect ( mockPublish ) . not . toHaveBeenCalled ( ) ;
109128 } ) ;
110129
111130 it ( "throws error when message is missing" , async ( ) => {
@@ -119,6 +138,7 @@ describe("wishes actions", () => {
119138 ) . rejects . toThrow ( "Missing required fields" ) ;
120139
121140 expect ( mockSubmit ) . not . toHaveBeenCalled ( ) ;
141+ expect ( mockPublish ) . not . toHaveBeenCalled ( ) ;
122142 } ) ;
123143
124144 it ( "propagates database errors" , async ( ) => {
@@ -148,6 +168,7 @@ describe("wishes actions", () => {
148168 ) ;
149169
150170 expect ( mockSubmit ) . not . toHaveBeenCalled ( ) ;
171+ expect ( mockPublish ) . not . toHaveBeenCalled ( ) ;
151172 } ) ;
152173 } ) ;
153174
0 commit comments