File tree Expand file tree Collapse file tree 4 files changed +38
-2
lines changed
modules/baseMessageModule Expand file tree Collapse file tree 4 files changed +38
-2
lines changed File renamed without changes.
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import nock from 'nock';
22
33import { API_URL } from '../../constants' ;
44import { SMSAPI } from '../../smsapi' ;
5+ import { MessageErrorResponse } from '../../types' ;
56
67const smsapi = new SMSAPI ( 'someToken' ) ;
78
@@ -96,4 +97,39 @@ describe('Base message module', () => {
9697 // then
9798 expect ( req . isDone ( ) ) . toBeTruthy ( ) ;
9899 } ) ;
100+
101+ it ( 'should throw error when sms.do returns one' , async ( ) => {
102+ // given
103+ const invalidNumber = '500000xxx' ;
104+ const message = 'someMessage' ;
105+ const errorResponse : MessageErrorResponse = {
106+ error : 13 ,
107+ message : 'No correct phone numbers' ,
108+ } ;
109+
110+ const date = new Date ( ) ;
111+
112+ const req = nock ( API_URL )
113+ . post ( '/sms.do' , {
114+ date : date . toISOString ( ) ,
115+ date_validate : true ,
116+ details : true ,
117+ encoding : 'utf-8' ,
118+ format : 'json' ,
119+ message,
120+ to : invalidNumber ,
121+ } )
122+ . reply ( 200 , errorResponse ) ;
123+
124+ // when
125+ try {
126+ await smsapi . sms . sendSms ( invalidNumber , message , {
127+ date,
128+ } ) ;
129+ } catch ( error ) {
130+ expect ( req . isDone ( ) ) . toBeTruthy ( ) ;
131+
132+ expect ( error . data ) . toEqual ( errorResponse ) ;
133+ }
134+ } ) ;
99135} ) ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
1212 MessageError ,
1313 MessageErrorResponse ,
1414 isMessageErrorResponseData ,
15- } from '../../errors/MessageResponseError ' ;
15+ } from '../../errors/MessageError ' ;
1616
1717import {
1818 MessageContent ,
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import { SubuserCredentials } from '../modules/subusers/types/SubuserCredentials
1515import { SubuserPoints } from '../modules/subusers/types/SubuserPoints' ;
1616import { Template } from '../modules/templates/types/Template' ;
1717import { UpdateSubuser } from '../modules/subusers/types/UpdateSubuser' ;
18- import { MessageErrorResponse } from '../errors/MessageResponseError ' ;
18+ import { MessageErrorResponse } from '../errors/MessageError ' ;
1919
2020import { MessageStatus } from './MessageStatus' ;
2121import { MessageResponse } from './MessageResponse' ;
You can’t perform that action at this time.
0 commit comments