Skip to content

Commit f514e26

Browse files
authored
Merge pull request #626 from marle3003/develop
Develop
2 parents 9024da3 + c1db8e1 commit f514e26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1301
-402
lines changed

acceptance/mail_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ func (suite *MailSuite) TestSendMail() {
6464
err = json.Unmarshal([]byte(body), &v)
6565
require.NoError(suite.T(), err)
6666
m := v.(map[string]any)
67+
require.Len(t, m, 2)
68+
require.Equal(t, "Mokapi MailServer", m["service"])
69+
m = m["data"].(map[string]any)
70+
6771
require.Len(t, m, 8)
68-
require.Equal(t, "[::1]:8025", m["server"])
72+
require.Regexp(t, ".*:8025", m["server"])
6973
require.Equal(t, []any{map[string]any{"address": "[email protected]"}}, m["from"])
7074
require.Equal(t, []any{map[string]any{"address": "[email protected]"}}, m["to"])
7175
require.NotContains(t, m, "attachments")
@@ -207,8 +211,9 @@ It can be any text data.
207211
err = json.Unmarshal([]byte(body), &v)
208212
require.NoError(suite.T(), err)
209213
m := v.(map[string]any)
214+
m = m["data"].(map[string]any)
210215
require.Len(t, m, 10)
211-
require.Equal(t, "[::1]:8030", m["server"])
216+
require.Regexp(t, ".*:8030", m["server"])
212217
require.Equal(t, []any{map[string]any{"address": "[email protected]"}}, m["from"])
213218
require.Equal(t, []any{map[string]any{"address": "[email protected]"}}, m["to"])
214219
require.Equal(t, []any{

acceptance/petstore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func (suite *PetStoreSuite) TestSearch_Paging() {
343343
evt := items[0].(map[string]interface{})
344344
require.Equal(t, "HTTP", evt["type"])
345345
require.Equal(t, "Swagger Petstore", evt["title"])
346-
require.Equal(t, "Swagger Petstore", evt["domain"])
346+
require.NotContains(t, evt, "domain")
347347
}),
348348
)
349349

api/handler_mail.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,18 @@ type messageInfo struct {
8383
}
8484

8585
type message struct {
86+
Service string `json:"service"`
87+
Data *messageData `json:"data"`
88+
}
89+
90+
type messageData struct {
8691
Server string `json:"server,omitempty"`
8792
Sender *address `json:"sender,omitempty"`
8893
From []address `json:"from"`
8994
To []address `json:"to"`
9095
ReplyTo []address `json:"replyTo,omitempty"`
9196
Cc []address `json:"cc,omitempty"`
92-
Bcc []address `json:"bbc,omitempty"`
97+
Bcc []address `json:"bcc,omitempty"`
9398
MessageId string `json:"messageId"`
9499
InReplyTo string `json:"inReplyTo,omitempty"`
95100
Date time.Time `json:"date"`
@@ -238,9 +243,11 @@ func (h *handler) handleMailService(w http.ResponseWriter, r *http.Request) {
238243

239244
func (h *handler) getMail(w http.ResponseWriter, messageId string) {
240245
var m *smtp.Message
246+
var store *mail.Store
241247
for _, s := range h.app.Mail.List() {
242248
m = s.Store.GetMail(messageId)
243249
if m != nil {
250+
store = s.Store
244251
break
245252
}
246253
}
@@ -250,7 +257,10 @@ func (h *handler) getMail(w http.ResponseWriter, messageId string) {
250257
}
251258

252259
w.Header().Set("Content-Type", "application/json")
253-
writeJsonBody(w, toMessage(m))
260+
writeJsonBody(w, message{
261+
Service: store.Name,
262+
Data: toMessage(m),
263+
})
254264
}
255265

256266
func (h *handler) getMailAttachment(w http.ResponseWriter, messageId, name string) {
@@ -397,8 +407,8 @@ func getRejectResponse(r *mail.Rule) *rejectResponse {
397407
}
398408
}
399409

400-
func toMessage(m *smtp.Message) *message {
401-
r := &message{
410+
func toMessage(m *smtp.Message) *messageData {
411+
r := &messageData{
402412
Server: m.Server,
403413
From: toAddress(m.From),
404414
To: toAddress(m.To),

api/handler_mail_test.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ func TestHandler_Smtp(t *testing.T) {
132132
app: func() *runtime.App {
133133
app := runtime.New(&static.Config{})
134134
app.Mail.Set("foo", &runtime.MailInfo{
135-
Config: &mail.Config{
136-
Info: mail.Info{Name: "foo"},
137-
},
138135
Store: &mail.Store{
139136
Mailboxes: map[string]*mail.Mailbox{
140137
"[email protected]": {Username: "alice", Password: "foo"},
@@ -157,9 +154,6 @@ func TestHandler_Smtp(t *testing.T) {
157154
app: func() *runtime.App {
158155
app := runtime.New(&static.Config{})
159156
app.Mail.Set("foo", &runtime.MailInfo{
160-
Config: &mail.Config{
161-
Info: mail.Info{Name: "foo"},
162-
},
163157
Store: &mail.Store{
164158
Mailboxes: map[string]*mail.Mailbox{
165159
@@ -181,9 +175,6 @@ func TestHandler_Smtp(t *testing.T) {
181175
app: func() *runtime.App {
182176
app := runtime.New(&static.Config{})
183177
app.Mail.Set("foo", &runtime.MailInfo{
184-
Config: &mail.Config{
185-
Info: mail.Info{Name: "foo"},
186-
},
187178
Store: &mail.Store{
188179
Mailboxes: map[string]*mail.Mailbox{
189180
@@ -219,9 +210,6 @@ func TestHandler_Smtp(t *testing.T) {
219210
app: func() *runtime.App {
220211
app := runtime.New(&static.Config{})
221212
app.Mail.Set("foo", &runtime.MailInfo{
222-
Config: &mail.Config{
223-
Info: mail.Info{Name: "foo"},
224-
},
225213
Store: &mail.Store{
226214
Mailboxes: map[string]*mail.Mailbox{
227215
@@ -268,10 +256,9 @@ func TestHandler_Smtp(t *testing.T) {
268256
app: func() *runtime.App {
269257
app := runtime.New(&static.Config{})
270258
app.Mail.Set("foo", &runtime.MailInfo{
271-
Config: &mail.Config{
272-
Info: mail.Info{Name: "foo"},
273-
},
259+
Config: &mail.Config{},
274260
Store: &mail.Store{
261+
Name: "foo",
275262
Mailboxes: map[string]*mail.Mailbox{
276263
277264
Folders: map[string]*mail.Folder{
@@ -301,16 +288,13 @@ func TestHandler_Smtp(t *testing.T) {
301288
},
302289
requestUrl: "http://foo.api/api/services/mail/messages/[email protected]",
303290
contentType: "application/json",
304-
responseBody: fmt.Sprintf(`{"from":[{"address":"[email protected]"}],"to":[{"address":"[email protected]"}],"messageId":"[email protected]","date":"%v","subject":"Hello Alice","contentType":"text/plain","body":"foobar","size":10}`, now.Format(time.RFC3339Nano)),
291+
responseBody: fmt.Sprintf(`{"service":"foo","data":{"from":[{"address":"[email protected]"}],"to":[{"address":"[email protected]"}],"messageId":"[email protected]","date":"%v","subject":"Hello Alice","contentType":"text/plain","body":"foobar","size":10}}`, now.Format(time.RFC3339Nano)),
305292
},
306293
{
307294
name: "get smtp mail attachment content",
308295
app: func() *runtime.App {
309296
app := runtime.New(&static.Config{})
310297
app.Mail.Set("foo", &runtime.MailInfo{
311-
Config: &mail.Config{
312-
Info: mail.Info{Name: "foo"},
313-
},
314298
Store: &mail.Store{
315299
Mailboxes: map[string]*mail.Mailbox{
316300

api/handler_search_test.go

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,10 @@ func TestHandler_SearchQuery(t *testing.T) {
3030
{
3131
name: "empty search query",
3232
requestUrl: "/api/search/query",
33-
responseBody: `{"results":[{"type":"HTTP","domain":"foo","title":"foo","params":{"service":"foo","type":"http"}}],"total":1}`,
33+
responseBody: `{"results":[{"type":"HTTP","title":"foo","params":{"service":"foo","type":"http"}}],"total":1}`,
3434
app: func() *runtime.App {
3535
app := runtime.New(&static.Config{Api: static.Api{Search: static.Search{
36-
Enabled: true,
37-
Analyzer: "ngram",
38-
Ngram: static.NgramAnalyzer{
39-
Min: 3,
40-
Max: 5,
41-
},
36+
Enabled: true,
4237
}}})
4338

4439
cfg := openapitest.NewConfig("3.0", openapitest.WithInfo("foo", "", ""))
@@ -50,15 +45,10 @@ func TestHandler_SearchQuery(t *testing.T) {
5045
{
5146
name: "search with query text",
5247
requestUrl: "/api/search/query?queryText=foo",
53-
responseBody: `{"results":[{"type":"HTTP","domain":"foo","title":"foo","fragments":["\u003cmark\u003efoo\u003c/mark\u003e"],"params":{"service":"foo","type":"http"}}],"total":1}`,
48+
responseBody: `{"results":[{"type":"HTTP","title":"foo","fragments":["\u003cmark\u003efoo\u003c/mark\u003e"],"params":{"service":"foo","type":"http"}}],"total":1}`,
5449
app: func() *runtime.App {
5550
app := runtime.New(&static.Config{Api: static.Api{Search: static.Search{
56-
Enabled: true,
57-
Analyzer: "ngram",
58-
Ngram: static.NgramAnalyzer{
59-
Min: 3,
60-
Max: 5,
61-
},
51+
Enabled: true,
6252
}}})
6353

6454
cfg := openapitest.NewConfig("3.0", openapitest.WithInfo("foo", "", ""))
@@ -70,15 +60,10 @@ func TestHandler_SearchQuery(t *testing.T) {
7060
{
7161
name: "search with param",
7262
requestUrl: "/api/search/query?queryText=api=foo",
73-
responseBody: `{"results":[{"type":"HTTP","domain":"foo","title":"foo","fragments":["\u003cmark\u003efoo\u003c/mark\u003e"],"params":{"service":"foo","type":"http"}}],"total":1}`,
63+
responseBody: `{"results":[{"type":"HTTP","title":"foo","fragments":["\u003cmark\u003efoo\u003c/mark\u003e"],"params":{"service":"foo","type":"http"}}],"total":1}`,
7464
app: func() *runtime.App {
7565
app := runtime.New(&static.Config{Api: static.Api{Search: static.Search{
76-
Enabled: true,
77-
Analyzer: "ngram",
78-
Ngram: static.NgramAnalyzer{
79-
Min: 3,
80-
Max: 5,
81-
},
66+
Enabled: true,
8267
}}})
8368

8469
cfg := openapitest.NewConfig("3.0", openapitest.WithInfo("foo", "", ""))

cmd/mokapi/main_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@ api:
5959
dashboard: true
6060
search:
6161
enabled: false
62-
analyzer: ngram
63-
ngram:
64-
min: 3
65-
max: 8
66-
types:
67-
- config
68-
- http
62+
types: []
6963
rootCaCert: ""
7064
rootCaKey: ""
7165
js:

config/static/static_config.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ func NewConfig() *Config {
3434
cfg.Api.Port = "8080"
3535
cfg.Api.Dashboard = true
3636
cfg.Api.Search.Enabled = false
37-
cfg.Api.Search.Analyzer = "ngram"
38-
cfg.Api.Search.Ngram.Min = 3
39-
cfg.Api.Search.Ngram.Max = 8
40-
cfg.Api.Search.Types = []string{"config", "http"}
4137

4238
cfg.Providers.File.SkipPrefix = []string{"_"}
4339
cfg.Event.Store = map[string]Store{"default": {Size: 100}}
@@ -65,10 +61,8 @@ type Api struct {
6561
}
6662

6763
type Search struct {
68-
Enabled bool
69-
Analyzer string
70-
Ngram NgramAnalyzer
71-
Types []string
64+
Enabled bool
65+
Types []string
7266
}
7367

7468
type NgramAnalyzer struct {

docs/guides/mail/quick-start.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: SMTP Quick Start
33
description: Send and inspect fake emails locally using Mokapi as a mock SMTP server.
44
---
5-
# Quick Start
5+
# SMTP Quick Start
66

77
Quickly get up and running with Mokapi as a fake SMTP server for testing and development — no real emails are sent,
88
and no risk of spamming real users.
@@ -64,6 +64,7 @@ You’ll see the received message under Mail → Messages, including its full co
6464

6565
## What's Next?
6666

67+
- [Test email workflows with Playwright and Mokapi](/docs/resources/blogs/testing-email-workflows-with-playwright-and-mokapi)
6768
- [Add recipient rules](/docs/guides/mail/rules.md) to allow or deny specific domains
6869
- [Patch the config](/docs/configuration/patching.md) to test different scenarios
6970

examples/mokapi/dashboard.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,17 +584,20 @@ components:
584584
type:
585585
type: string
586586
domain:
587-
type: string
587+
type: [string, 'null']
588588
title:
589589
type: string
590590
fragments:
591-
type: array
591+
type: [array, 'null']
592592
items:
593593
type: string
594594
params:
595595
type: object
596596
additionalProperties:
597597
type: string
598+
time:
599+
type: [string, 'null']
600+
format: date-time
598601
ServiceInfo:
599602
type: object
600603
properties:

0 commit comments

Comments
 (0)