Skip to content

Commit

Permalink
Merge pull request #12 from ewarehousing-solutions/EWA-913
Browse files Browse the repository at this point in the history
Fix delete response error
  • Loading branch information
Fichtme authored Apr 29, 2024
2 parents a4c0e33 + bb23219 commit cfe0114
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
4 changes: 0 additions & 4 deletions ewhs/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,5 @@ func (os *WebhooksService) Delete(ctx context.Context, webhookID string) (webhoo
return
}

if err = json.Unmarshal(res.content, &webhook); err != nil {
return
}

return
}
76 changes: 76 additions & 0 deletions ewhs/webhooks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ewhs

import (
"context"
"github.com/ewarehousing-solutions/ewhs-api-go/test/testdata"
"github.com/stretchr/testify/suite"
"net/http"
"testing"
)

type webhooksServiceSuite struct{ suite.Suite }

func (os *webhooksServiceSuite) TestWebhooksSuite_Delete() {
type args struct {
ctx context.Context
webhook string
}
cases := []struct {
name string
args args
wantErr bool
err error
pre func()
handler http.HandlerFunc
}{
{
"delete webhooks returns 204 as expected.",
args{
context.Background(),
"c9165f93-8301-4aaa-9f64-27f191c0c778",
},
false,
nil,
func() {
tClient.WithAuthToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9")
},
func(w http.ResponseWriter, r *http.Request) {
testHeader(os.T(), r, AuthHeader, "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9")
testHeader(os.T(), r, CustomerCodeHeader, "test_customer")
testHeader(os.T(), r, WmsCodeHeader, "test_wms")
testMethod(os.T(), r, "DELETE")

if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
} else {
w.WriteHeader(http.StatusNoContent)
}
_, _ = w.Write([]byte(testdata.DeleteWebhooksResponse))
},
},
}

for _, c := range cases {
setup()
defer teardown()

os.T().Run(c.name, func(t *testing.T) {
c.pre()
tMux.HandleFunc("/webhooks/", c.handler)

m, res, err := tClient.Webhooks.Delete(c.args.ctx, c.args.webhook)
if c.wantErr {
os.NotNil(err)
os.EqualError(err, c.err.Error())
} else {
os.Nil(err)
os.IsType(&Webhook{}, m)
os.IsType(&http.Response{}, res.Response)
}
})
}
}

func TestWebhooksSuite(t *testing.T) {
suite.Run(t, new(webhooksServiceSuite))
}
5 changes: 5 additions & 0 deletions test/testdata/webhooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package testdata

// DeleteWebhooksResponse is a test data for webhooks response
// It returns 204 no content
const DeleteWebhooksResponse = ``

0 comments on commit cfe0114

Please sign in to comment.