@@ -15,7 +15,7 @@ import TemplatesBaseAPI from "../../lib/api/Templates";
15
15
16
16
const { ERRORS , CLIENT_SETTINGS } = CONFIG ;
17
17
const { TESTING_ENDPOINT , BULK_ENDPOINT , SENDING_ENDPOINT } = CLIENT_SETTINGS ;
18
- const { TEST_INBOX_ID_MISSING , ACCOUNT_ID_MISSING , BULK_SANDBOX_INCOMPATIBLE } =
18
+ const { ACCOUNT_ID_MISSING , BULK_SANDBOX_INCOMPATIBLE , TEST_INBOX_ID_MISSING } =
19
19
ERRORS ;
20
20
21
21
describe ( "lib/mailtrap-client: " , ( ) => {
@@ -331,7 +331,49 @@ describe("lib/mailtrap-client: ", () => {
331
331
}
332
332
} ) ;
333
333
334
+ it ( "throws MailtrapError(TEST_INBOX_ID_MISSING) when sending in sandbox mode without testInboxId" , async ( ) => {
335
+ const client = new MailtrapClient ( {
336
+ token : "MY_API_TOKEN" ,
337
+ sandbox : true ,
338
+ accountId : 123 ,
339
+ } ) ;
340
+
341
+ await expect (
342
+ client . send ( {
343
+ from : { email : "a@b.com" , name : "Sender" } ,
344
+ to : [ { email : "c@d.com" } ] ,
345
+ subject : "Test" ,
346
+ text : "Body" ,
347
+ } )
348
+ ) . rejects . toEqual ( new MailtrapError ( TEST_INBOX_ID_MISSING ) ) ;
349
+ } ) ;
350
+
334
351
describe ( "batch sending:" , ( ) => {
352
+ it ( "throws MailtrapError(TEST_INBOX_ID_MISSING) when batch sending in sandbox mode without testInboxId" , async ( ) => {
353
+ const client = new MailtrapClient ( {
354
+ token : "MY_API_TOKEN" ,
355
+ sandbox : true ,
356
+ accountId : 123 ,
357
+ } ) ;
358
+
359
+ const batchData = {
360
+ base : {
361
+ from : { email : "a@b.com" , name : "Sender" } ,
362
+ subject : "Test" ,
363
+ text : "Body" ,
364
+ } ,
365
+ requests : [
366
+ {
367
+ to : [ { email : "c@d.com" } ] ,
368
+ } ,
369
+ ] ,
370
+ } ;
371
+
372
+ await expect ( client . batchSend ( batchData ) ) . rejects . toEqual (
373
+ new MailtrapError ( TEST_INBOX_ID_MISSING )
374
+ ) ;
375
+ } ) ;
376
+
335
377
it ( "rejects with Mailtrap error when bulk and sandbox modes are used together" , async ( ) => {
336
378
const batchClient = new MailtrapClient ( {
337
379
token : "MY_API_TOKEN" ,
@@ -664,7 +706,7 @@ describe("lib/mailtrap-client: ", () => {
664
706
} ) ;
665
707
666
708
describe ( "get testing(): " , ( ) => {
667
- it ( "rejects with Mailtrap error, when `testInboxId ` is missing." , ( ) => {
709
+ it ( "rejects with Mailtrap error, when `accountId ` is missing." , ( ) => {
668
710
const client = new MailtrapClient ( {
669
711
token : "MY_API_TOKEN" ,
670
712
} ) ;
@@ -674,30 +716,25 @@ describe("lib/mailtrap-client: ", () => {
674
716
try {
675
717
client . testing ;
676
718
} catch ( error ) {
677
- expect ( error ) . toEqual ( new MailtrapError ( TEST_INBOX_ID_MISSING ) ) ;
719
+ expect ( error ) . toEqual ( new MailtrapError ( ACCOUNT_ID_MISSING ) ) ;
678
720
}
679
721
} ) ;
680
722
681
- it ( "rejects with Mailtrap error, when ` accountId` is missing. " , ( ) => {
723
+ it ( "returns testing API object when accountId is provided, even without testInboxId " , ( ) => {
682
724
const client = new MailtrapClient ( {
683
725
token : "MY_API_TOKEN" ,
684
- testInboxId : 5 ,
726
+ accountId : 123 ,
727
+ // testInboxId is intentionally omitted
685
728
} ) ;
686
-
687
729
expect . assertions ( 1 ) ;
688
730
689
- try {
690
- client . testing ;
691
- } catch ( error ) {
692
- expect ( error ) . toEqual ( new MailtrapError ( ACCOUNT_ID_MISSING ) ) ;
693
- }
731
+ const testingClient = client . testing ;
732
+ expect ( testingClient ) . toBeInstanceOf ( TestingAPI ) ;
694
733
} ) ;
695
734
696
735
it ( "returns testing API object, console warn is called twice." , ( ) => {
697
736
const client = new MailtrapClient ( {
698
737
token : "MY_API_TOKEN" ,
699
- sandbox : true ,
700
- testInboxId : 10 ,
701
738
accountId : 10 ,
702
739
} ) ;
703
740
expect . assertions ( 1 ) ;
0 commit comments