|
2 | 2 |
|
3 | 3 | exports[`generateChatStepFile > should match snapshot 1`] = ` |
4 | 4 | "import { step } from '@novu/framework/step-resolver'; |
5 | | -
|
6 | | -export default step.chat('send-chat', async (controls, { payload, subscriber, context, steps }) => ({ |
7 | | - body: \`Hello \${subscriber.firstName ?? 'there'}, a message for you.\`, |
8 | | -})); |
| 5 | +import { z } from 'zod'; |
| 6 | +
|
| 7 | +export default step.chat( |
| 8 | + 'send-chat', |
| 9 | + async (controls, { payload, subscriber }) => ({ |
| 10 | + body: \`Hi \${subscriber.firstName ?? 'there'}, \${controls.message}\`, |
| 11 | + }), |
| 12 | + { |
| 13 | + controlSchema: z.object({ |
| 14 | + message: z.string().default('You have a new message.'), |
| 15 | + }), |
| 16 | + // skip: (_controls, { subscriber }) => !subscriber.channels?.chat, |
| 17 | + } |
| 18 | +); |
9 | 19 | " |
10 | 20 | `; |
11 | 21 |
|
12 | 22 | exports[`generateEmailStepFile > should match snapshot 1`] = ` |
13 | 23 | "import { step } from '@novu/framework/step-resolver'; |
14 | | -
|
15 | | -export default step.email('plain-email', async (controls, { payload, subscriber, context, steps }) => ({ |
16 | | - subject: 'No Subject', |
17 | | - body: \`<html><body><p>Hello \${subscriber.firstName ?? 'there'},</p><p>Your message here.</p></body></html>\`, |
18 | | -})); |
| 24 | +import { z } from 'zod'; |
| 25 | +
|
| 26 | +export default step.email( |
| 27 | + 'plain-email', |
| 28 | + async (controls, { payload, subscriber }) => ({ |
| 29 | + subject: controls.subject, |
| 30 | + body: \` |
| 31 | + <html> |
| 32 | + <body> |
| 33 | + <h1>\${controls.heading}</h1> |
| 34 | + <p>Hi \${subscriber.firstName ?? 'there'},</p> |
| 35 | + <p>\${controls.body}</p> |
| 36 | + <p><a href="\${controls.ctaUrl}">View details</a></p> |
| 37 | + </body> |
| 38 | + </html> |
| 39 | + \`, |
| 40 | + // Optionally override the sender for this step: |
| 41 | + // from: { email: 'noreply@example.com', name: 'My App' }, |
| 42 | + }), |
| 43 | + { |
| 44 | + controlSchema: z.object({ |
| 45 | + subject: z.string().default('You have a new notification'), |
| 46 | + heading: z.string().default('New activity'), |
| 47 | + body: z.string().default('You have a new message.'), |
| 48 | + ctaUrl: z.string().default('/'), |
| 49 | + }), |
| 50 | + // skip: (_controls, { subscriber }) => !subscriber.email, |
| 51 | + } |
| 52 | +); |
19 | 53 | " |
20 | 54 | `; |
21 | 55 |
|
22 | 56 | exports[`generateInAppStepFile > should match snapshot 1`] = ` |
23 | 57 | "import { step } from '@novu/framework/step-resolver'; |
24 | | -
|
25 | | -export default step.inApp('in-app-notify', async (controls, { payload, subscriber, context, steps }) => ({ |
26 | | - subject: 'New notification', |
27 | | - body: \`Hello \${subscriber.firstName ?? 'there'}, you have a new in-app notification.\`, |
28 | | -})); |
| 58 | +import { z } from 'zod'; |
| 59 | +
|
| 60 | +export default step.inApp( |
| 61 | + 'in-app-notify', |
| 62 | + async (controls, { payload, subscriber }) => ({ |
| 63 | + subject: controls.subject, |
| 64 | + body: controls.body, |
| 65 | + // avatar: subscriber.avatar, |
| 66 | + primaryAction: { |
| 67 | + label: controls.ctaLabel, |
| 68 | + redirect: { url: controls.ctaUrl, target: '_blank' }, |
| 69 | + }, |
| 70 | + // secondaryAction: { label: 'Dismiss' }, |
| 71 | + }), |
| 72 | + { |
| 73 | + controlSchema: z.object({ |
| 74 | + subject: z.string().default('New activity'), |
| 75 | + body: z.string().default('You have a new notification.'), |
| 76 | + ctaLabel: z.string().default('View details'), |
| 77 | + ctaUrl: z.string().default('/'), |
| 78 | + }), |
| 79 | + // skip: (_controls, { subscriber }) => !subscriber.channels?.in_app, |
| 80 | + } |
| 81 | +); |
29 | 82 | " |
30 | 83 | `; |
31 | 84 |
|
32 | 85 | exports[`generatePushStepFile > should match snapshot 1`] = ` |
33 | 86 | "import { step } from '@novu/framework/step-resolver'; |
34 | | -
|
35 | | -export default step.push('send-push', async (controls, { payload, subscriber, context, steps }) => ({ |
36 | | - subject: 'New notification', |
37 | | - body: \`Hello \${subscriber.firstName ?? 'there'}, you have a new notification.\`, |
38 | | -})); |
| 87 | +import { z } from 'zod'; |
| 88 | +
|
| 89 | +export default step.push( |
| 90 | + 'send-push', |
| 91 | + async (controls, { payload, subscriber }) => ({ |
| 92 | + subject: controls.title, |
| 93 | + body: controls.body, |
| 94 | + }), |
| 95 | + { |
| 96 | + controlSchema: z.object({ |
| 97 | + title: z.string().default('New activity'), |
| 98 | + body: z.string().default('You have a new notification.'), |
| 99 | + }), |
| 100 | + // skip: (_controls, { subscriber }) => !subscriber.channels?.push, |
| 101 | + } |
| 102 | +); |
39 | 103 | " |
40 | 104 | `; |
41 | 105 |
|
42 | 106 | exports[`generateReactEmailStepFile > should match snapshot 1`] = ` |
43 | 107 | "import { step } from '@novu/framework/step-resolver'; |
44 | 108 | import { render } from '@react-email/components'; |
| 109 | +import { z } from 'zod'; |
45 | 110 | import EmailTemplate from '../emails/welcome'; |
46 | 111 |
|
47 | | -export default step.email('welcome-email', async (controls, { payload, subscriber, context, steps }) => ({ |
48 | | - subject: 'No Subject', |
49 | | - body: await render( |
50 | | - <EmailTemplate |
51 | | - {...payload} |
52 | | - subscriber={subscriber} |
53 | | - context={context} |
54 | | - steps={steps} |
55 | | - controls={controls} |
56 | | - /> |
57 | | - ), |
58 | | -})); |
| 112 | +export default step.email( |
| 113 | + 'welcome-email', |
| 114 | + async (controls, { payload, subscriber, steps }) => ({ |
| 115 | + subject: controls.subject, |
| 116 | + body: await render( |
| 117 | + <EmailTemplate |
| 118 | + controls={controls} |
| 119 | + subscriber={subscriber} |
| 120 | + steps={steps} |
| 121 | + /> |
| 122 | + ), |
| 123 | + }), |
| 124 | + { |
| 125 | + controlSchema: z.object({ |
| 126 | + subject: z.string().default('You have a new notification'), |
| 127 | + }), |
| 128 | + } |
| 129 | +); |
59 | 130 | " |
60 | 131 | `; |
61 | 132 |
|
62 | 133 | exports[`generateReactEmailStepFile > should match snapshot with different import paths > nested-import 1`] = ` |
63 | 134 | "import { step } from '@novu/framework/step-resolver'; |
64 | 135 | import { render } from '@react-email/components'; |
| 136 | +import { z } from 'zod'; |
65 | 137 | import EmailTemplate from '../../src/emails/welcome'; |
66 | 138 |
|
67 | | -export default step.email('welcome-email', async (controls, { payload, subscriber, context, steps }) => ({ |
68 | | - subject: 'No Subject', |
69 | | - body: await render( |
70 | | - <EmailTemplate |
71 | | - {...payload} |
72 | | - subscriber={subscriber} |
73 | | - context={context} |
74 | | - steps={steps} |
75 | | - controls={controls} |
76 | | - /> |
77 | | - ), |
78 | | -})); |
| 139 | +export default step.email( |
| 140 | + 'welcome-email', |
| 141 | + async (controls, { payload, subscriber, steps }) => ({ |
| 142 | + subject: controls.subject, |
| 143 | + body: await render( |
| 144 | + <EmailTemplate |
| 145 | + controls={controls} |
| 146 | + subscriber={subscriber} |
| 147 | + steps={steps} |
| 148 | + /> |
| 149 | + ), |
| 150 | + }), |
| 151 | + { |
| 152 | + controlSchema: z.object({ |
| 153 | + subject: z.string().default('You have a new notification'), |
| 154 | + }), |
| 155 | + } |
| 156 | +); |
79 | 157 | " |
80 | 158 | `; |
81 | 159 |
|
82 | 160 | exports[`generateReactEmailStepFile > should match snapshot with different import paths > relative-import 1`] = ` |
83 | 161 | "import { step } from '@novu/framework/step-resolver'; |
84 | 162 | import { render } from '@react-email/components'; |
| 163 | +import { z } from 'zod'; |
85 | 164 | import EmailTemplate from './emails/welcome'; |
86 | 165 |
|
87 | | -export default step.email('welcome-email', async (controls, { payload, subscriber, context, steps }) => ({ |
88 | | - subject: 'No Subject', |
89 | | - body: await render( |
90 | | - <EmailTemplate |
91 | | - {...payload} |
92 | | - subscriber={subscriber} |
93 | | - context={context} |
94 | | - steps={steps} |
95 | | - controls={controls} |
96 | | - /> |
97 | | - ), |
98 | | -})); |
| 166 | +export default step.email( |
| 167 | + 'welcome-email', |
| 168 | + async (controls, { payload, subscriber, steps }) => ({ |
| 169 | + subject: controls.subject, |
| 170 | + body: await render( |
| 171 | + <EmailTemplate |
| 172 | + controls={controls} |
| 173 | + subscriber={subscriber} |
| 174 | + steps={steps} |
| 175 | + /> |
| 176 | + ), |
| 177 | + }), |
| 178 | + { |
| 179 | + controlSchema: z.object({ |
| 180 | + subject: z.string().default('You have a new notification'), |
| 181 | + }), |
| 182 | + } |
| 183 | +); |
99 | 184 | " |
100 | 185 | `; |
101 | 186 |
|
102 | 187 | exports[`generateSmsStepFile > should match snapshot 1`] = ` |
103 | 188 | "import { step } from '@novu/framework/step-resolver'; |
104 | | -
|
105 | | -export default step.sms('send-sms', async (controls, { payload, subscriber, context, steps }) => ({ |
106 | | - body: \`Hello \${subscriber.firstName ?? 'there'}, your message here.\`, |
107 | | -})); |
| 189 | +import { z } from 'zod'; |
| 190 | +
|
| 191 | +export default step.sms( |
| 192 | + 'send-sms', |
| 193 | + async (controls, { payload, subscriber }) => ({ |
| 194 | + body: \`Hi \${subscriber.firstName ?? 'there'}, \${controls.message}\`, |
| 195 | + }), |
| 196 | + { |
| 197 | + controlSchema: z.object({ |
| 198 | + message: z.string().default('You have a new notification. Reply STOP to unsubscribe.'), |
| 199 | + }), |
| 200 | + // skip: (_controls, { subscriber }) => !subscriber.phone, |
| 201 | + } |
| 202 | +); |
108 | 203 | " |
109 | 204 | `; |
0 commit comments