Skip to content

Commit

Permalink
Store the HTML and TEXT parts of a stored message in the mock server
Browse files Browse the repository at this point in the history
  • Loading branch information
dax committed May 18, 2024
1 parent b39a353 commit e85840f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
36 changes: 19 additions & 17 deletions mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,25 @@ type MockServer interface {
type mockServer struct {
srv *httptest.Server

domainIPS []string
domainList []DomainContainer
exportList []Export
mailingList []MailingListContainer
routeList []Route
events []Event
templates []Template
templateVersions map[string][]TemplateVersion
unsubscribes []Unsubscribe
complaints []Complaint
bounces []Bounce
credentials []Credential
stats []Stats
tags []Tag
subaccountList []Subaccount
webhooks WebHooksListResponse
mutex sync.Mutex
domainIPS []string
domainList []DomainContainer
exportList []Export
mailingList []MailingListContainer
routeList []Route
events []Event
storedMessageHtml map[string]string
storedMessageText map[string]string
templates []Template
templateVersions map[string][]TemplateVersion
unsubscribes []Unsubscribe
complaints []Complaint
bounces []Bounce
credentials []Credential
stats []Stats
tags []Tag
subaccountList []Subaccount
webhooks WebHooksListResponse
mutex sync.Mutex
}

func (ms *mockServer) DomainIPS() []string {
Expand Down
9 changes: 9 additions & 0 deletions mock_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func (ms *mockServer) addMessagesRoutes(r chi.Router) {
// This path is made up; it could be anything as the storage url could change over time
r.Get("/se.storage.url/messages/{id}", ms.getStoredMessages)
r.Post("/se.storage.url/messages/{id}", ms.sendStoredMessages)

ms.storedMessageHtml = make(map[string]string)
ms.storedMessageText = make(map[string]string)
}

// TODO: This implementation doesn't support multiple recipients
Expand Down Expand Up @@ -49,6 +52,10 @@ func (ms *mockServer) createMessages(w http.ResponseWriter, r *http.Request) {
stored.Flags = events.Flags{
IsTestMode: false,
}

ms.storedMessageHtml[id] = r.FormValue("html")
ms.storedMessageText[id] = r.FormValue("text")

ms.mutex.Lock()
ms.events = append(ms.events, stored)
ms.mutex.Unlock()
Expand Down Expand Up @@ -124,6 +131,8 @@ func (ms *mockServer) getStoredMessages(w http.ResponseWriter, r *http.Request)
Sender: stored.Message.Headers.From,
Subject: stored.Message.Headers.Subject,
From: stored.Message.Headers.From,
BodyHtml: ms.storedMessageHtml[id],
BodyPlain: ms.storedMessageText[id],
MessageHeaders: [][]string{
{"Sender", stored.Message.Headers.From},
{"To", stored.Message.Headers.To},
Expand Down

0 comments on commit e85840f

Please sign in to comment.