template-monorepo/docs/notification-testing.md

61 lines
1.8 KiB
Markdown
Raw Normal View History

2026-05-20 09:32:22 +00:00
# Notification 測試
單一入口:`make notify-test`,用 **METHOD** 指定要測哪一種,一次只跑一項。
異步Enqueue + Worker說明見 [internal/model/notification/README.md](../internal/model/notification/README.md#測異步enqueue)。
## 前置
```bash
make deps-up
make mongo-index
```
MailHog 本機 SMTP`make deps-up-smtp`yaml 設 `SMTP.Host=localhost`、`Port=1025`。
## METHOD 一覽
| METHOD | 需要參數 | 說明 |
|--------|----------|------|
| `email-send` | `TO=` | 同步寄驗證信 |
| `email-enqueue` | `TO=` | 異步佇列 + Worker 送達 |
| `email-idempotency` | `TO=` | 同 key 不重送 |
| `sms-send` | `PHONE=` | 同步簡訊 |
| `sms-enqueue` | `PHONE=` | 異步簡訊 |
| `member-email` | `TO=` | Member 信箱 OTP 流程 |
| `member-phone` | `PHONE=` | Member 手機 OTP 流程 |
| `admin-dlq` | — | 列出 DLQ |
Provider 由 `gateway.dev.yaml``SMTP/SES/Mitake.Enable` 決定。
不連外網時加 **`MOCK=1`**(強制 mock
## 範例
```bash
# 真實 SMTP依 yaml
make notify-test METHOD=email-send TO=you@example.com
# mock不真的寄
make notify-test METHOD=email-send TO=test@example.com MOCK=1
make notify-test METHOD=email-enqueue TO=you@example.com
make notify-test METHOD=sms-send PHONE=0912345678
make notify-test METHOD=member-email TO=you@example.com
make notify-test METHOD=admin-dlq
```
成功輸出末尾為 `OK`;失敗為 `FAIL: ...` 且 exit 1。
等同:
```bash
go run ./cmd/notify-test -method email-send -to you@example.com -f etc/gateway.dev.yaml
go run ./cmd/notify-test -method email-send -to t@e.com -mock
```
## Provider 提示
- 只測 **SES**:關 `SMTP.Enable`,開 `SES.Enable`
- 只測 **Mitake**`SMS.Mitake.Enable: true` + `METHOD=sms-send`
- 同時開 SMTP + SES**Sort** failover通常只會打到第一個成功的