tsk-58: Update names of Contact endpoint (#67)

Closes #58

Reviewed-on: phoenix/textsender-api#67
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2026-01-07 20:24:30 +00:00
committed by phoenix
parent 4e250d095c
commit a51979e724
11 changed files with 460 additions and 8 deletions
+43
View File
@@ -78,3 +78,46 @@ func TestGetContactWithMock(t *testing.T) {
assert.NotNil(t, response.Data[0].Id, "Id should not be nil")
}
func TestUpdateContactNamesWithMock(t *testing.T) {
mockstore := mock.NewMockContactStore()
testUserId := uuid.New()
testCon := contact.Contact{PhoneNumber: "+12335403383", UserId: &testUserId}
ctx := t.Context()
var firstname, lastname, nickname string
firstname = "Bob"
lastname = "De-Buildor"
nickname = "With The Tool"
if err := mockstore.CreateContact(ctx, &testCon); err != nil {
assert.NoError(t, err, "Error creating contact")
return
}
var requestBody UpdateNameRequest
requestBody.Firstname = &firstname
requestBody.Lastname = &lastname
requestBody.Nickname = &nickname
requestBody.ContactId = *testCon.Id
requestBody.UserId = testUserId
jsonValue, _ := json.Marshal(requestBody)
req, _ := http.NewRequest("PATCH", endpoint.Update_Names_Endpoint, strings.NewReader(string(jsonValue)))
rr := httptest.NewRecorder()
apiApp, err := GetApp()
assert.NoError(t, err, "Error getting app")
contactHandler := NewContactHandler(apiApp, mockstore)
contactHandler.UpdateName(rr, req)
assert.Equal(t, http.StatusOK, rr.Code)
var response UpdateNameResponse
err = json.Unmarshal(rr.Body.Bytes(), &response)
assert.NoError(t, err, "Error updating names of contact %v", err)
assert.NotEmpty(t, response.Data, "No Contact updated")
assert.NotNil(t, response.Data[0].Firstname, "Firstname should not be nil")
assert.NotNil(t, response.Data[0].Lastname, "Lastname should not be nil")
assert.NotNil(t, response.Data[0].Nickname, "Nickname should not be nil")
}