TestSelfSend_HappyPath: an agent sending to its own address short-circuits to the loopback path (no SMTP) and lands BOTH an outbound and an inbound row tagged to the agent, with the outbound row persisting method="loopback".
(t *testing.T)
| 95 | // to the loopback path (no SMTP) and lands BOTH an outbound and an inbound row |
| 96 | // tagged to the agent, with the outbound row persisting method="loopback". |
| 97 | func TestSelfSend_HappyPath(t *testing.T) { |
| 98 | api, store, pool := setupCoreAPI(t) |
| 99 | ctx := context.Background() |
| 100 | user, ag := selfAgent(t, store, "owner") |
| 101 | |
| 102 | res, oerr := api.DeliverOutbound(ctx, user, ag, outbound.SendRequest{ |
| 103 | To: []string{ag.EmailAddress()}, Subject: "note to self", Body: "remember to refill coffee", |
| 104 | }, "send", "", nil) |
| 105 | if oerr != nil { |
| 106 | t.Fatalf("DeliverOutbound: status=%d code=%s msg=%s", oerr.Status, oerr.Code, oerr.Msg) |
| 107 | } |
| 108 | if res.Method != "loopback" { |
| 109 | t.Errorf("method=%q want loopback", res.Method) |
| 110 | } |
| 111 | if !strings.HasPrefix(res.MessageID, "<") || !strings.Contains(res.MessageID, "loopback.") { |
| 112 | t.Errorf("message_id=%q should look like an RFC 5322 Message-ID with loopback host", res.MessageID) |
| 113 | } |
| 114 | |
| 115 | var outboundCount, inboundCount int |
| 116 | pool.QueryRow(ctx, |
| 117 | `SELECT count(*) FROM messages WHERE agent_id=$1 AND direction='outbound' AND subject='note to self'`, |
| 118 | ag.ID).Scan(&outboundCount) |
| 119 | pool.QueryRow(ctx, |
| 120 | `SELECT count(*) FROM messages WHERE agent_id=$1 AND direction='inbound' AND subject='note to self'`, |
| 121 | ag.ID).Scan(&inboundCount) |
| 122 | if outboundCount != 1 { |
| 123 | t.Errorf("outbound rows=%d want 1", outboundCount) |
| 124 | } |
| 125 | if inboundCount != 1 { |
| 126 | t.Errorf("inbound rows=%d want 1", inboundCount) |
| 127 | } |
| 128 | |
| 129 | var sender, recipient string |
| 130 | pool.QueryRow(ctx, |
| 131 | `SELECT sender, recipient FROM messages WHERE agent_id=$1 AND direction='inbound' AND subject='note to self'`, |
| 132 | ag.ID).Scan(&sender, &recipient) |
| 133 | if sender != ag.EmailAddress() || recipient != ag.EmailAddress() { |
| 134 | t.Errorf("self-note row sender=%q recipient=%q; both must be the agent's own address", sender, recipient) |
| 135 | } |
| 136 | |
| 137 | var method string |
| 138 | pool.QueryRow(ctx, |
| 139 | `SELECT method FROM messages WHERE agent_id=$1 AND direction='outbound' AND subject='note to self'`, |
| 140 | ag.ID).Scan(&method) |
| 141 | if method != "loopback" { |
| 142 | t.Errorf("outbound method=%q want loopback", method) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // TestSelfSend_PreservesAttachmentsInMIME: a self-send with an attachment must |
| 147 | // persist the attachment in the inbound row's raw_message so the SDK's MIME |
nothing calls this directly
no test coverage detected