Repository navigation
Description
Task Summary
amber/src/main/scala/org/apache/texera/web/resource/GmailResource.scala sits at 31.2% of 77 lines measured in isolation (39.0% on live Codecov, where other suites incidentally touch its case class). A spec exists with 4 tests — extend it rather than adding a second.
The file's name is misleading, and it changes the whole assessment. This is a javax.mail / SMTP resource, not a Google-OAuth one: there is no GoogleCredential, no token exchange, no clientId. The only credential is an SMTP app password read from config and consumed inside an Authenticator callback that never fires unless a socket opens. So the parts worth testing are not credential-gated at all.
What is reachable offline:
- The recipient-format guard, clause by clause — the null short-circuit, the missing
@, the empty local part, an embedded space, a dotless domain, and the two-character TLD floor. - The admin fan-out in
notifyUnauthorizedUser, driven throughMockTexeraDBwith two ADMIN rows and a REGULAR decoy, so narrowing the role filter or notifying only the first admin are both visible. - The
ForbiddenExceptionguard on a malformed applicant address.
Three things to get right:
- Never let a test reach
Transport.send. It dialssmtp.gmail.com:465with no connect or read timeout configured. The existingrequireNoRealGmailSender()guard fails loudly instead; keep calling it. - A six-case malformed-address list is vacuous on its own. A regex that rejects everything keeps it green. It needs a companion test asserting a well-formed address gets past the guard and fails later in delivery, so the two together pin the regex from both sides.
- The fan-out fixture's admin addresses must be malformed in a way unrelated to the regex clause under test. Seeding them as
…@localhostcouples the fan-out test to the domain rules — loosening the domain regex then makes them deliverable and the fan-out test false-reddens. Use addresses with no@at all.
Left unpinnable, and worth recording so nobody contorts a test around them: both catch { case ex: Exception => logger.warn(...) } arms in notifyUnauthorizedUser are unreachable (sendEmail wraps everything in a Try and returns a Left; it never throws) and should be deleted rather than reached. The applicant acknowledgement has no observable effect offline. And only the admin notification's recipient is observable, not its payload — sendEmail is on the companion object, so nothing can intercept what it was handed; the builder's own contract is already pinned by EmailTemplateSpec.
Task Type
- Refactor / Cleanup
- DevOps / Deployment / CI
- Testing / QA
- Documentation
- Performance
- Other
Activity
test(amber): cover the mail resource's address guard and admin fan-out (