TestSMTPAPI_Delete verifies the delete endpoint.
(t *testing.T)
| 465 | |
| 466 | // TestSMTPAPI_Delete verifies the delete endpoint. |
| 467 | func TestSMTPAPI_Delete(t *testing.T) { |
| 468 | mux, store, _ := setupAPITest(t) |
| 469 | ctx := context.Background() |
| 470 | |
| 471 | storeSMTPEvent(t, store, "del-uuid1", ParsedEmail{Subject: "Delete me"}, 1000.0, "default") |
| 472 | storeSMTPEvent(t, store, "del-uuid2", ParsedEmail{Subject: "Keep me"}, 1001.0, "other") |
| 473 | |
| 474 | t.Run("delete by project", func(t *testing.T) { |
| 475 | r := httptest.NewRequest("DELETE", "/api/smtp/messages?project=default", nil) |
| 476 | w := httptest.NewRecorder() |
| 477 | mux.ServeHTTP(w, r) |
| 478 | |
| 479 | if w.Code != 200 { |
| 480 | t.Fatalf("status = %d", w.Code) |
| 481 | } |
| 482 | |
| 483 | all, _ := store.FindAll(ctx, event.FindOptions{Type: "smtp"}) |
| 484 | if len(all) != 1 { |
| 485 | t.Errorf("expected 1 remaining, got %d", len(all)) |
| 486 | } |
| 487 | if all[0].UUID != "del-uuid2" { |
| 488 | t.Errorf("wrong event remaining: %s", all[0].UUID) |
| 489 | } |
| 490 | }) |
| 491 | |
| 492 | t.Run("delete all", func(t *testing.T) { |
| 493 | r := httptest.NewRequest("DELETE", "/api/smtp/messages", nil) |
| 494 | w := httptest.NewRecorder() |
| 495 | mux.ServeHTTP(w, r) |
| 496 | |
| 497 | if w.Code != 200 { |
| 498 | t.Fatalf("status = %d", w.Code) |
| 499 | } |
| 500 | |
| 501 | all, _ := store.FindAll(ctx, event.FindOptions{Type: "smtp"}) |
| 502 | if len(all) != 0 { |
| 503 | t.Errorf("expected 0, got %d", len(all)) |
| 504 | } |
| 505 | }) |
| 506 | } |
| 507 | |
| 508 | // TestSMTPAPI_Wait verifies the long-poll wait endpoint. |
| 509 | func TestSMTPAPI_Wait(t *testing.T) { |
nothing calls this directly
no test coverage detected