-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Validate MX Record Setup for Inbound Parse Functionality
- Loading branch information
1 parent
29a0e27
commit a86085a
Showing
5 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package lib | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
type IInboundParser interface { | ||
Get(ctx context.Context) bool | ||
} | ||
type InboundParserService service | ||
|
||
func (i InboundParserService) Get(ctx context.Context) (*InboundParserResponse, error) { | ||
|
||
var resp InboundParserResponse | ||
|
||
URL := i.client.config.BackendURL.JoinPath("inbound-parse", "mx", "status") | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, URL.String(), http.NoBody) | ||
|
||
if err != nil { | ||
return &InboundParserResponse{}, err | ||
} | ||
_, err = i.client.sendRequest(req, &resp) | ||
|
||
if err != nil { | ||
return &InboundParserResponse{}, err | ||
} | ||
return &resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package lib_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/novuhq/go-novu/lib" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestInboundParserService_Get_Success(t *testing.T) { | ||
expectedResponse := &lib.InboundParserResponse{ | ||
Data: lib.MxRecordConfiguredStatus{MxRecordConfigured: false}, | ||
} | ||
|
||
inboundParserService := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
|
||
// Write the expected response as JSON | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
err := json.NewEncoder(w).Encode(expectedResponse) | ||
assert.NoError(t, err) | ||
|
||
t.Run("Header must contain ApiKey", func(t *testing.T) { | ||
authKey := r.Header.Get("Authorization") | ||
assert.True(t, strings.Contains(authKey, novuApiKey)) | ||
assert.True(t, strings.HasPrefix(authKey, "ApiKey")) | ||
}) | ||
|
||
t.Run("URL and request method is as expected", func(t *testing.T) { | ||
expectedURL := "/v1/inbound-parse/mx/status" | ||
assert.Equal(t, http.MethodGet, r.Method) | ||
assert.Equal(t, expectedURL, r.RequestURI) | ||
}) | ||
|
||
})) | ||
|
||
defer inboundParserService.Close() | ||
|
||
ctx := context.Background() | ||
i := lib.NewAPIClient(novuApiKey, &lib.Config{BackendURL: lib.MustParseURL(inboundParserService.URL)}) | ||
|
||
resp, err := i.InboundParserApi.Get(ctx) | ||
|
||
require.Nil(t, err) | ||
require.Equal(t, resp, expectedResponse) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters