Skip to content

Commit

Permalink
refactor: add send-email as separate action inside creation handler +…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
BarcoMasile committed Sep 10, 2024
1 parent 97e8182 commit 1a62043
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/identities/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ func (a *API) handleCreate(w http.ResponseWriter, r *http.Request) {
return
}

createdIdentity := &ids.Identities[0]
err = a.service.SendUserCreationEmail(r.Context(), createdIdentity)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(
types.Response{
Message: err.Error(),
Status: http.StatusInternalServerError,
},
)

return
}

w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(
types.Response{
Expand Down
1 change: 1 addition & 0 deletions pkg/identities/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func TestHandleCreateSuccess(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/api/v0/identities", bytes.NewReader(payload))

mockService.EXPECT().CreateIdentity(gomock.Any(), identityBody).Return(&IdentityData{Identities: []kClient.Identity{*identity}}, nil)
mockService.EXPECT().SendUserCreationEmail(gomock.Any(), identity).Return(nil)

w := httptest.NewRecorder()
mux := chi.NewMux()
Expand Down

0 comments on commit 1a62043

Please sign in to comment.