tsk-51: Send message endpoint (#52)
Closes #51 Reviewed-on: phoenix/textsender-api#52 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -23,7 +23,9 @@ type CreateMessageRequest struct {
|
||||
|
||||
func TestCreateMessageWithMock(t *testing.T) {
|
||||
mockStore := mock.NewMockMessageStore()
|
||||
handler := NewMessageHandler(mockStore)
|
||||
apiApp, err := GetApp()
|
||||
assert.NoError(t, err, "Error getting app")
|
||||
handler := NewMessageHandler(apiApp, mockStore)
|
||||
|
||||
testUserId := uuid.New()
|
||||
testBody := CreateMessageRequest{Content: "Who could tell?", UserId: testUserId}
|
||||
@@ -37,7 +39,7 @@ func TestCreateMessageWithMock(t *testing.T) {
|
||||
assert.Equal(t, http.StatusCreated, rr.Code)
|
||||
|
||||
var response AddMessageResponse
|
||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
||||
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||
assert.NoError(t, err, "Error Creating message %v", err)
|
||||
|
||||
assert.NotEmpty(t, response.Data, "No Message created")
|
||||
@@ -60,13 +62,15 @@ func TestGetMessageWithMock(t *testing.T) {
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
messageHandler := NewMessageHandler(mockstore)
|
||||
apiApp, err := GetApp()
|
||||
assert.NoError(t, err, "Error getting app")
|
||||
messageHandler := NewMessageHandler(apiApp, mockstore)
|
||||
messageHandler.GetMessage(rr, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var response GetMessageResponse
|
||||
err := json.Unmarshal(rr.Body.Bytes(), &response)
|
||||
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||
assert.NoError(t, err, "Error getting message %v", err)
|
||||
|
||||
assert.NotEmpty(t, response.Data, "No Message retrieved")
|
||||
|
||||
Reference in New Issue
Block a user