+ Body text content with some additional information. +
+Test email
", subject: "Test Subject", } @@ -49,20 +49,21 @@ describe("invalid requests", () => { `); }); - it("should return 404 when user is not found", async ({ expect }) => { + it("should return 200 with user not found error in results", async ({ expect }) => { await Project.createAndSwitch({ display_name: "Test Successful Email Project", config: { email_config: testEmailConfig, }, }); + const userId = randomUUID(); const response = await niceBackendFetch( "/api/v1/emails/send-email", { method: "POST", accessType: "server", body: { - user_id: randomUUID(), + user_ids: [userId], html: "Test email
", subject: "Test Subject", notification_category_name: "Marketing", @@ -71,8 +72,16 @@ describe("invalid requests", () => { ); expect(response).toMatchInlineSnapshot(` NiceResponse { - "status": 404, - "body": "User not found", + "status": 200, + "body": { + "results": [ + { + "error": "User not found", + "success": false, + "user_id": "Test email
", subject: "Test Subject", notification_category_name: "Marketing", @@ -128,7 +137,7 @@ describe("invalid requests", () => { method: "POST", accessType: "server", body: { - user_id: createUserResponse.body.id, + user_ids: [createUserResponse.body.id], html: "Test email
", subject: "Test Subject", notification_category_name: "Invalid", @@ -145,7 +154,7 @@ describe("invalid requests", () => { }); }); -it("should return 400 when user has disabled notifications for the category", async ({ expect }) => { +it("should return 200 with disabled notifications error in results when user has disabled notifications for the category", async ({ expect }) => { await Project.createAndSwitch({ display_name: "Test Successful Email Project", config: { @@ -181,7 +190,7 @@ it("should return 400 when user has disabled notifications for the category", as method: "POST", accessType: "server", body: { - user_id: user.userId, + user_ids: [user.userId], html: "Test email
", subject: "Test Subject", notification_category_name: "Marketing", @@ -190,14 +199,22 @@ it("should return 400 when user has disabled notifications for the category", as ); expect(response).toMatchInlineSnapshot(` NiceResponse { - "status": 400, - "body": "User has disabled notifications for this category", + "status": 200, + "body": { + "results": [ + { + "error": "User has disabled notifications for this category", + "success": false, + "user_id": "Test email
", subject: "Test Subject", notification_category_name: "Marketing", @@ -226,8 +243,16 @@ it("should return 400 when user does not have a primary email", async ({ expect ); expect(response).toMatchInlineSnapshot(` NiceResponse { - "status": 400, - "body": "User does not have a primary email", + "status": 200, + "body": { + "results": [ + { + "error": "User does not have a primary email", + "success": false, + "user_id": "This is a test email with HTML content.
", subject: "Custom Test Email Subject", notification_category_name: "Marketing", @@ -258,7 +283,15 @@ it("should return 200 and send email successfully", async ({ expect }) => { expect(response).toMatchInlineSnapshot(` NiceResponse { "status": 200, - "body": { "user_email": "unindexed-mailbox--This is a test email with HTML content.
"); + expect(sentEmail!.body?.html).toMatchInlineSnapshot(`"http://localhost:8102/api/v1/emails/unsubscribe-link?code=%3Cstripped+query+param%3E"`); +}); + +it("should handle mixed results for multiple users", async ({ expect }) => { + await Project.createAndSwitch({ + display_name: "Test Mixed Results Project", + config: { + email_config: testEmailConfig, + }, + }); + const userWithDisabledNotifications = await User.create(); + await niceBackendFetch(`/api/v1/emails/notification-preference/${userWithDisabledNotifications.userId}/4f6f8873-3d04-46bd-8bef-18338b1a1b4c`, { + method: "PATCH", + accessType: "server", + body: { + enabled: false, + }, + }); + const nonExistentUserId = randomUUID(); + const successfulUser = await User.create(); + + const response = await niceBackendFetch( + "/api/v1/emails/send-email", + { + method: "POST", + accessType: "server", + body: { + user_ids: [userWithDisabledNotifications.userId, nonExistentUserId, successfulUser.userId], + html: "This is a bulk test email.
", + subject: "Bulk Test Email Subject", + notification_category_name: "Marketing", + } + } + ); + + expect(response).toMatchInlineSnapshot(` + NiceResponse { + "status": 200, + "body": { + "results": [ + { + "error": "User has disabled notifications for this category", + "success": false, + "user_id": "This is a test email with HTML content.
", subject: "Custom Test Email Subject", notification_category_name: "Marketing", @@ -34,7 +34,15 @@ it("unsubscribe link should be sent and update notification preference", async ( expect(response).toMatchInlineSnapshot(` NiceResponse { "status": 200, - "body": { "user_email": "unindexed-mailbox--