Skip to content

Commit

Permalink
test: minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
ceciliaromao committed Nov 28, 2023
1 parent 9bdc064 commit 9ef71f4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
9 changes: 9 additions & 0 deletions internal/data/disbursements.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ const (
VerificationFieldNationalID VerificationField = "NATIONAL_ID_NUMBER"
)

// GetAllVerificationFields returns all verification fields
func GetAllVerificationFields() []VerificationField {
return []VerificationField{
VerificationFieldDateOfBirth,
VerificationFieldPin,
VerificationFieldNationalID,
}
}

type DisbursementStatusHistoryEntry struct {
UserID string `json:"user_id"`
Status DisbursementStatus `json:"status"`
Expand Down
8 changes: 2 additions & 6 deletions internal/serve/httphandler/receiver_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ func (rh ReceiverHandler) GetReceivers(w http.ResponseWriter, r *http.Request) {
}

// GetReceiverVerification returns a list of verification types
func (rh ReceiverHandler) GetReceiverVerificatioTypes(w http.ResponseWriter, r *http.Request) {
httpjson.Render(w, []data.VerificationField{
data.VerificationFieldDateOfBirth,
data.VerificationFieldNationalID,
data.VerificationFieldPin,
}, httpjson.JSON)
func (rh ReceiverHandler) GetReceiverVerificationTypes(w http.ResponseWriter, r *http.Request) {
httpjson.Render(w, data.GetAllVerificationFields(), httpjson.JSON)
}
27 changes: 11 additions & 16 deletions internal/serve/httphandler/receiver_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1633,25 +1633,20 @@ func Test_ReceiverHandler_GetReceiverVerificatioTypes(t *testing.T) {
DBConnectionPool: dbConnectionPool,
}

r := chi.NewRouter()
r.Get("/receivers/verification-types", handler.GetReceiverVerificatioTypes)

rr := httptest.NewRecorder()
req, err := http.NewRequest(http.MethodGet, "/receivers/verification-types", nil)
require.NoError(t, err)
http.HandlerFunc(handler.GetReceiverVerificationTypes).ServeHTTP(rr, req)

rr := httptest.NewRecorder()
r.ServeHTTP(rr, req)

require.Equal(t, http.StatusOK, rr.Code)

respBody, err := io.ReadAll(rr.Body)
resp := rr.Result()
respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)

defer resp.Body.Close()
expectedBody := `[
"DATE_OF_BIRTH",
"NATIONAL_ID_NUMBER",
"PIN"
]`

assert.Equal(t, expectedBody, string(respBody))
"DATE_OF_BIRTH",
"PIN",
"NATIONAL_ID_NUMBER"
]`
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.JSONEq(t, expectedBody, string(respBody))
}
2 changes: 1 addition & 1 deletion internal/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func handleHTTP(o ServeOptions) *chi.Mux {
Get("/{id}", receiversHandler.GetReceiver)

r.With(middleware.AnyRoleMiddleware(authManager, data.GetAllRoles()...)).
Get("/verification-types", receiversHandler.GetReceiverVerificatioTypes)
Get("/verification-types", receiversHandler.GetReceiverVerificationTypes)

updateReceiverHandler := httphandler.UpdateReceiverHandler{Models: o.Models, DBConnectionPool: o.dbConnectionPool}
r.With(middleware.AnyRoleMiddleware(authManager, data.OwnerUserRole, data.FinancialControllerUserRole)).
Expand Down

0 comments on commit 9ef71f4

Please sign in to comment.