File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -29,4 +29,26 @@ describe('SMSAPI', () => {
29
29
expect ( nock . pendingMocks ( ) ) . toEqual ( [ ] ) ;
30
30
expect ( nock . isDone ( ) ) . toEqual ( true ) ;
31
31
} ) ;
32
+
33
+ it ( `SMSAPI should call service provided by user` , async ( ) => {
34
+ // given
35
+ const url = 'https://ssl.smsapi.com/api' ;
36
+
37
+ nock ( url , {
38
+ reqheaders : {
39
+ authorization : `Bearer ${ token } ` ,
40
+ } ,
41
+ } )
42
+ . get ( '/profile' )
43
+ . reply ( 200 ) ;
44
+
45
+ const smsapi = new SMSAPI ( token , url ) ;
46
+
47
+ // when
48
+ await smsapi . profile . get ( ) ;
49
+
50
+ // then
51
+ expect ( nock . pendingMocks ( ) ) . toEqual ( [ ] ) ;
52
+ expect ( nock . isDone ( ) ) . toEqual ( true ) ;
53
+ } ) ;
32
54
} ) ;
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import { extractDataFromResponse } from './httpClient/extractDataFromResponse';
19
19
20
20
export class SMSAPI {
21
21
private accessToken : string ;
22
+ private serviceUrl : string ;
22
23
23
24
private httpClient : AxiosInstance ;
24
25
@@ -32,8 +33,9 @@ export class SMSAPI {
32
33
public templates : Templates ;
33
34
public vms : Vms ;
34
35
35
- constructor ( accessToken : string ) {
36
+ constructor ( accessToken : string , serviceUrl ?: string ) {
36
37
this . accessToken = accessToken ;
38
+ this . serviceUrl = serviceUrl ?? API_URL ;
37
39
38
40
this . httpClient = this . setHttpClient ( ) ;
39
41
@@ -55,7 +57,7 @@ export class SMSAPI {
55
57
private setHttpClient ( ) : AxiosInstance {
56
58
const httpClient = axios . create ( {
57
59
adapter : 'http' ,
58
- baseURL : API_URL ,
60
+ baseURL : this . serviceUrl ,
59
61
headers : {
60
62
Accept : 'application/json' ,
61
63
Authorization : `Bearer ${ this . accessToken } ` ,
You can’t perform that action at this time.
0 commit comments