Skip to content

Commit 6bdca3a

Browse files
committed
add LimitRate tests to methods
1 parent 9bfa198 commit 6bdca3a

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

src/methods/send/send.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,66 @@ describe('sdk v4', () => {
152152
);
153153
});
154154

155+
it('should call the send method and fail on limit rate', async () => {
156+
const sendEmail = () =>
157+
send('default_service', 'my_test_template', undefined, {
158+
publicKey: 'C2JWGTestKeySomething',
159+
limitRate: {
160+
id: 'async-send',
161+
throttle: 100,
162+
},
163+
});
164+
165+
try {
166+
const result = await sendEmail();
167+
expect(result).toEqual({ status: 200, text: 'OK' });
168+
} catch (error) {
169+
expect(error).toBeUndefined();
170+
}
171+
172+
try {
173+
const result = await sendEmail();
174+
expect(result).toBeUndefined();
175+
} catch (error) {
176+
expect(error).toEqual({
177+
status: 429,
178+
text: 'Too Many Requests',
179+
});
180+
}
181+
});
182+
183+
it('should call the send method and fail on limit rate as promise', () => {
184+
const sendEmail = () =>
185+
send('default_service', 'my_test_template', undefined, {
186+
publicKey: 'C2JWGTestKeySomething',
187+
limitRate: {
188+
id: 'promise-send',
189+
throttle: 100,
190+
},
191+
});
192+
193+
return sendEmail().then(
194+
(result) => {
195+
expect(result).toEqual({ status: 200, text: 'OK' });
196+
197+
return sendEmail().then(
198+
(result) => {
199+
expect(result).toBeUndefined();
200+
},
201+
(error) => {
202+
expect(error).toEqual({
203+
status: 429,
204+
text: 'Too Many Requests',
205+
});
206+
},
207+
);
208+
},
209+
(error) => {
210+
expect(error).toBeUndefined();
211+
},
212+
);
213+
});
214+
155215
it('should call the send method successfully with 4 params', async () => {
156216
try {
157217
const result = await send(

src/methods/sendForm/sendForm.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,70 @@ describe('sdk v4', () => {
183183
);
184184
});
185185

186+
it('should call the sendForm method and fail on limit rate', async () => {
187+
const form: HTMLFormElement = document.createElement('form');
188+
189+
const sendEmail = () =>
190+
sendForm('default_service', 'my_test_template', form, {
191+
publicKey: 'C2JWGTestKeySomething',
192+
limitRate: {
193+
id: 'async-form',
194+
throttle: 100,
195+
},
196+
});
197+
198+
try {
199+
const result = await sendEmail();
200+
expect(result).toEqual({ status: 200, text: 'OK' });
201+
} catch (error) {
202+
expect(error).toBeUndefined();
203+
}
204+
205+
try {
206+
const result = await sendEmail();
207+
expect(result).toBeUndefined();
208+
} catch (error) {
209+
expect(error).toEqual({
210+
status: 429,
211+
text: 'Too Many Requests',
212+
});
213+
}
214+
});
215+
216+
it('should call the sendForm method and fail on limit rate as promise', () => {
217+
const form: HTMLFormElement = document.createElement('form');
218+
219+
const sendEmail = () =>
220+
sendForm('default_service', 'my_test_template', form, {
221+
publicKey: 'C2JWGTestKeySomething',
222+
limitRate: {
223+
id: 'promise-form',
224+
throttle: 100,
225+
},
226+
});
227+
228+
return sendEmail().then(
229+
(result) => {
230+
expect(result).toEqual({ status: 200, text: 'OK' });
231+
232+
return sendEmail().then(
233+
(result) => {
234+
expect(result).toBeUndefined();
235+
},
236+
(error) => {
237+
expect(error).toEqual({
238+
status: 429,
239+
text: 'Too Many Requests',
240+
});
241+
},
242+
);
243+
},
244+
(error) => {
245+
expect(error).toBeUndefined();
246+
},
247+
);
248+
});
249+
186250
it('should call the sendForm with id selector', async () => {
187251
const form: HTMLFormElement = document.createElement('form');
188252
form.id = 'form-id';

0 commit comments

Comments
 (0)