Skip to content

Commit

Permalink
lets add another test to create a name that looks like " Abdul " and …
Browse files Browse the repository at this point in the history
…assert it gets added as "Abdul" (#1553)

* Added UT to test trim spaces

* Removed unnecessary log
  • Loading branch information
AbdulWahab3181 authored Feb 22, 2024
1 parent 6234e34 commit c8974fa
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions handlers/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,35 @@ func TestUnitCreateOrEditOrganization(t *testing.T) {
assert.Equal(t, http.StatusBadRequest, rr.Code)
})

t.Run("should trim spaces from organization name", func(t *testing.T) {
rr := httptest.NewRecorder()
handler := http.HandlerFunc(oHandler.CreateOrEditOrganization)

mockDb.On("GetOrganizationByUuid", mock.AnythingOfType("string")).Return(db.Organization{}).Once()
mockDb.On("GetOrganizationByName", "Abdul").Return(db.Organization{}).Once()
mockDb.On("CreateOrEditOrganization", mock.MatchedBy(func(org db.Organization) bool {
return org.Name == "Abdul" && org.Uuid != "" && org.Updated != nil && org.Created != nil
})).Return(db.Organization{Name: "Abdul"}, nil).Once()

jsonInput := []byte(`{"name": " Abdul ", "owner_pubkey": "test-key" ,"description": "Test"}`)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, "/", bytes.NewReader(jsonInput))
if err != nil {
t.Fatal(err)
}

handler.ServeHTTP(rr, req)

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

var responseOrg db.Organization
err = json.Unmarshal(rr.Body.Bytes(), &responseOrg)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, "Abdul", responseOrg.Name)
})

t.Run("should successfully add organization if request is valid", func(t *testing.T) {
rr := httptest.NewRecorder()
handler := http.HandlerFunc(oHandler.CreateOrEditOrganization)
Expand Down

0 comments on commit c8974fa

Please sign in to comment.