Yicong-Huang commented on code in PR #5460:
URL: https://github.com/apache/texera/pull/5460#discussion_r3408310693


##########
frontend/src/app/common/service/gmail/gmail.service.spec.ts:
##########
@@ -63,4 +64,76 @@ describe("GmailService", () => {
     expect(notificationSpy.error).toHaveBeenCalledWith("Failed to send email. 
Please try again or contact admin.");
     expect(notificationSpy.success).not.toHaveBeenCalled();
   });
+
+  it("sends the correct PUT body for sendEmail with an explicit receiver", () 
=> {
+    service.sendEmail("subj", "body", "[email protected]");
+
+    const req = httpTestingController.expectOne(r => 
r.url.endsWith("/gmail/send") && r.method === "PUT");
+    expect(req.request.body).toEqual({ receiver: "[email protected]", subject: 
"subj", content: "body" });
+    req.flush(null);
+  });
+
+  it("defaults the receiver to an empty string when it is omitted", () => {
+    service.sendEmail("subj", "body");
+
+    const req = httpTestingController.expectOne(r => 
r.url.endsWith("/gmail/send") && r.method === "PUT");
+    expect(req.request.body).toEqual({ receiver: "", subject: "subj", content: 
"body" });
+    req.flush(null);
+  });
+
+  it("logs the underlying error to the console on a failed send", () => {
+    const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
+    service.sendEmail("subj", "body", "[email protected]");
+
+    const req = httpTestingController.expectOne(r => 
r.url.endsWith("/gmail/send") && r.method === "PUT");
+    req.flush("boom", { status: 502, statusText: "Bad Gateway" });
+
+    expect(consoleSpy).toHaveBeenCalledWith("Send email error:", "boom");
+  });

Review Comment:
   thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to