Skip to content

Commit 9422fa9

Browse files
author
Przemysław Dziewa
committed
Add custom service url
1 parent 9032d77 commit 9422fa9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/smsapi/index.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,26 @@ describe('SMSAPI', () => {
2929
expect(nock.pendingMocks()).toEqual([]);
3030
expect(nock.isDone()).toEqual(true);
3131
});
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+
});
3254
});

src/smsapi/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { extractDataFromResponse } from './httpClient/extractDataFromResponse';
1919

2020
export class SMSAPI {
2121
private accessToken: string;
22+
private serviceUrl: string;
2223

2324
private httpClient: AxiosInstance;
2425

@@ -32,8 +33,9 @@ export class SMSAPI {
3233
public templates: Templates;
3334
public vms: Vms;
3435

35-
constructor(accessToken: string) {
36+
constructor(accessToken: string, serviceUrl?: string) {
3637
this.accessToken = accessToken;
38+
this.serviceUrl = serviceUrl ?? API_URL;
3739

3840
this.httpClient = this.setHttpClient();
3941

@@ -55,7 +57,7 @@ export class SMSAPI {
5557
private setHttpClient(): AxiosInstance {
5658
const httpClient = axios.create({
5759
adapter: 'http',
58-
baseURL: API_URL,
60+
baseURL: this.serviceUrl,
5961
headers: {
6062
Accept: 'application/json',
6163
Authorization: `Bearer ${this.accessToken}`,

0 commit comments

Comments
 (0)