MCPcopy Index your code
hub / github.com/frain-dev/convoy / TestProcessNotifications

Function TestProcessNotifications

worker/task/process_notifications_test.go:20–203  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestProcessNotifications(t *testing.T) {
21 tests := []struct {
22 name string
23 payload string
24 nFn func() func()
25 clientFn func(sc *mocks.MockSmtpClient)
26 expectedError error
27 }{
28 {
29 name: "should_fail_for_invalid_payload",
30 payload: `bad payload`,
31 clientFn: func(sc *mocks.MockSmtpClient) {
32 sc.EXPECT().
33 SendEmail(gomock.Any(), gomock.Any(), gomock.Any()).
34 Return(nil).Times(0)
35 },
36 expectedError: ErrInvalidNotificationPayload,
37 },
38 {
39 name: "should_fail_for_invalid_notification_type",
40 payload: `
41 {
42 "notification_type": "invalid"
43 }
44 `,
45 clientFn: nil,
46 expectedError: ErrInvalidNotificationType,
47 },
48 {
49 name: "should_fail_for_invalid_email_payload",
50 payload: `
51 {
52 "notification_type": "email",
53 "payload": "invalid"
54 }
55 `,
56 clientFn: nil,
57 expectedError: ErrInvalidEmailPayload,
58 },
59 {
60 name: "should_pass_for_valid_email_notification",
61 payload: `
62 {
63 "notification_type": "email",
64 "payload": {
65 "email": "user@default.com",
66 "subject": "organisation invite",
67 "template_name": "organisation.invite"
68 }
69 }
70 `,
71 clientFn: func(sc *mocks.MockSmtpClient) {
72 sc.EXPECT().
73 SendEmail(gomock.Any(), gomock.Any(), gomock.Any()).
74 Return(nil).Times(1)
75 },
76 expectedError: nil,
77 },

Callers

nothing calls this directly

Calls 5

EXPECTMethod · 0.95
NewMockSmtpClientFunction · 0.92
ProcessNotificationsFunction · 0.85
SendEmailMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected