Skip to content

Commit 3997ec3

Browse files
committed
Add tests for shopify orders
1 parent a3aa538 commit 3997ec3

File tree

10 files changed

+697
-40
lines changed

10 files changed

+697
-40
lines changed

auth/service/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func (s *Service) initializeRouter() error {
333333
return errors.Wrap(err, "unable to create fulfillment event processor")
334334
}
335335

336-
ordersCreateEventProcessor, err := shopify.NewOrdersCreateEventProcessor(s.Logger(), customerIOClient, shopifyClnt)
336+
ordersCreateEventProcessor, err := shopify.NewOrdersCreateEventProcessor(s.Logger(), customerIOClient)
337337
if err != nil {
338338
return errors.Wrap(err, "unable to create orders create event processor")
339339
}

oura/jotform/webhook_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
logTest "github.com/tidepool-org/platform/log/test"
2424
"github.com/tidepool-org/platform/oura/customerio"
2525
"github.com/tidepool-org/platform/oura/jotform"
26-
jotformTest "github.com/tidepool-org/platform/oura/jotform/test"
2726
shopfiyTest "github.com/tidepool-org/platform/oura/shopify/test"
2827
userTest "github.com/tidepool-org/platform/user/test"
2928
)
@@ -101,15 +100,15 @@ var _ = Describe("WebhookProcessor", func() {
101100
submissionID := "6410095903544943563"
102101
userID := "1aacb960-430c-4081-8b3b-a32688807dc5"
103102

104-
submission, err := jotformTest.LoadFixture("./test/fixtures/submission.json")
103+
submission, err := ouraTest.LoadFixture("./test/fixtures/submission.json")
105104
Expect(err).ToNot(HaveOccurred())
106105

107106
jotformResponses.AddResponse(
108107
[]ouraTest.RequestMatcher{ouraTest.NewRequestMethodAndPathMatcher(http.MethodGet, "/v1/submission/"+submissionID)},
109108
ouraTest.Response{StatusCode: http.StatusOK, Body: submission},
110109
)
111110

112-
customer, err := jotformTest.LoadFixture("./test/fixtures/customer.json")
111+
customer, err := ouraTest.LoadFixture("./test/fixtures/customer.json")
113112
Expect(err).ToNot(HaveOccurred())
114113

115114
appAPIResponses.AddResponse(
@@ -171,15 +170,15 @@ var _ = Describe("WebhookProcessor", func() {
171170
submissionID := "6410095903544943563"
172171
userID := "1aacb960-430c-4081-8b3b-a32688807dc5"
173172

174-
submission, err := jotformTest.LoadFixture("./test/fixtures/submission.json")
173+
submission, err := ouraTest.LoadFixture("./test/fixtures/submission.json")
175174
Expect(err).ToNot(HaveOccurred())
176175

177176
jotformResponses.AddResponse(
178177
[]ouraTest.RequestMatcher{ouraTest.NewRequestMethodAndPathMatcher(http.MethodGet, "/v1/submission/"+submissionID)},
179178
ouraTest.Response{StatusCode: http.StatusOK, Body: submission},
180179
)
181180

182-
customer, err := jotformTest.LoadFixture("./test/fixtures/customer.json")
181+
customer, err := ouraTest.LoadFixture("./test/fixtures/customer.json")
183182
Expect(err).ToNot(HaveOccurred())
184183

185184
appAPIResponses.AddResponse(
@@ -231,7 +230,7 @@ var _ = Describe("WebhookProcessor", func() {
231230
submissionID := "6410095903544943563"
232231
userID := "1aacb960-430c-4081-8b3b-a32688807dc5"
233232

234-
submission, err := jotformTest.LoadFixture("./test/fixtures/submission.json")
233+
submission, err := ouraTest.LoadFixture("./test/fixtures/submission.json")
235234
Expect(err).ToNot(HaveOccurred())
236235

237236
jotformResponses.AddResponse(
@@ -252,7 +251,7 @@ var _ = Describe("WebhookProcessor", func() {
252251
submissionID := "6410095903544943563"
253252
userID := "1aacb960-430c-4081-8b3b-a32688807dc5"
254253

255-
submission, err := jotformTest.LoadFixture("./test/fixtures/submission_participant_mismatch.json")
254+
submission, err := ouraTest.LoadFixture("./test/fixtures/submission_participant_mismatch.json")
256255
Expect(err).ToNot(HaveOccurred())
257256

258257
jotformResponses.AddResponse(
@@ -273,15 +272,15 @@ var _ = Describe("WebhookProcessor", func() {
273272
submissionID := "6410095903544943563"
274273
userID := "1aacb960-430c-4081-8b3b-a32688807dc5"
275274

276-
submission, err := jotformTest.LoadFixture("./test/fixtures/submission.json")
275+
submission, err := ouraTest.LoadFixture("./test/fixtures/submission.json")
277276
Expect(err).ToNot(HaveOccurred())
278277

279278
jotformResponses.AddResponse(
280279
[]ouraTest.RequestMatcher{ouraTest.NewRequestMethodAndPathMatcher(http.MethodGet, "/v1/submission/"+submissionID)},
281280
ouraTest.Response{StatusCode: http.StatusOK, Body: submission},
282281
)
283282

284-
customer, err := jotformTest.LoadFixture("./test/fixtures/customer.json")
283+
customer, err := ouraTest.LoadFixture("./test/fixtures/customer.json")
285284
Expect(err).ToNot(HaveOccurred())
286285

287286
appAPIResponses.AddResponse(

oura/shopify/api/api_suite_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package api_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/tidepool-org/platform/test"
7+
)
8+
9+
func TestSuite(t *testing.T) {
10+
test.Test(t)
11+
}

oura/shopify/api/router_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package api_test
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"net/http"
7+
8+
"github.com/ant0ine/go-json-rest/rest"
9+
. "github.com/onsi/ginkgo/v2"
10+
. "github.com/onsi/gomega"
11+
"github.com/tidepool-org/platform/log"
12+
"github.com/tidepool-org/platform/log/null"
13+
14+
"github.com/tidepool-org/platform/oura/test"
15+
16+
"github.com/tidepool-org/platform/oura/shopify/api"
17+
"github.com/tidepool-org/platform/request"
18+
19+
serviceTest "github.com/tidepool-org/platform/service/test"
20+
)
21+
22+
var _ = Describe("Router", func() {
23+
Context("NewRouter", func() {
24+
It("returns successfully", func() {
25+
rtr, err := api.NewRouter(nil, nil)
26+
Expect(err).ToNot(HaveOccurred())
27+
Expect(rtr).ToNot(BeNil())
28+
})
29+
})
30+
31+
Context("with new router", func() {
32+
var rtr *api.Router
33+
34+
BeforeEach(func() {
35+
var err error
36+
rtr, err = api.NewRouter(nil, nil)
37+
Expect(err).ToNot(HaveOccurred())
38+
Expect(rtr).ToNot(BeNil())
39+
})
40+
41+
Context("Routes", func() {
42+
It("returns the expected routes", func() {
43+
Expect(rtr.Routes()).ToNot(BeEmpty())
44+
})
45+
})
46+
47+
Context("HandleOrdersCreateEvent", func() {
48+
It("returns successfully", func() {
49+
ctx := log.NewContextWithLogger(request.NewContextWithAuthDetails(context.Background(), nil), null.NewLogger())
50+
body, err := test.LoadFixture("./test/fixtures/orders_create.json")
51+
Expect(err).ToNot(HaveOccurred())
52+
53+
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, "", bytes.NewBuffer([]byte(body)))
54+
Expect(err).ToNot(HaveOccurred())
55+
56+
req := &rest.Request{
57+
Request: httpReq,
58+
}
59+
res := serviceTest.NewMockRestResponseWriter()
60+
rtr.HandleOrdersCreateEvent(res, req)
61+
})
62+
})
63+
})
64+
})

0 commit comments

Comments
 (0)