Skip to content

Commit a2732b9

Browse files
committed
feat: Making API version modifyable
1 parent f60e7ed commit a2732b9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/infrastructure/BaseService.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import XMLHttpRequester from './XMLHttpRequester';
44

55
class BaseModel {
66
constructor({
7-
url = 'https://gitlab.com', token, oauthToken, useXMLHttpRequest = false,
7+
token,
8+
oauthToken,
9+
url = 'https://gitlab.com',
10+
useXMLHttpRequest = false,
11+
version = 'v4',
812
} = {}) {
9-
this.url = URLJoin(url, 'api', 'v4');
13+
this.url = URLJoin(url, 'api', version);
1014
this.headers = {};
1115
this.requester = useXMLHttpRequest ? XMLHttpRequester : Request;
1216
this.useXMLHttpRequest = useXMLHttpRequest;

test/tests/infrastructure/BaseService.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ describe('Creation of BaseService instance', () => {
3737

3838
expect(service.headers['private-token']).toBe('1234');
3939
});
40+
41+
test('API version should be modified', async () => {
42+
const service = new BaseService({ url: 'https://testing.com', token: '1234', version: 'v3' });
43+
44+
expect(service.url).toBe('https://testing.com/api/v3');
45+
});
4046
});

0 commit comments

Comments
 (0)