Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit b2f9d38

Browse files
committed
Extracted all APIs to configuration variables.
1 parent 01ffa97 commit b2f9d38

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ To override default settings please add them to a file `./config/local.js`:
2020
- `RABBITMQ.NOTIFICATIONS_EXCHANGE_NAME`: the notification RabbitMQ's topic exchange name
2121
- `LOGENTRIES_TOKEN`: the Logentries token generated from https://logentries.com/
2222
- `API_BASE_URL`: the base url to the API server to get project/user info
23+
- `API_URL_PROJECTS`: `API_BASE_URL` path accessed by this project
24+
- `API_URL_MEMBERS`: `API_BASE_URL` path accessed by this project
25+
- `API_URL_USERS`: `API_BASE_URL` path accessed by this project
26+
- `API_URL_AUTHORIZATIONS`: `API_BASE_URL` path accessed by this project
27+
- `API_URL_TOPICS`: `API_BASE_URL` path accessed by this project
2328
- `DISABLE_DELAY_EXCHANGE`: Disable exchage type delay and use 'direct' instead(Note: after changing this delete existing delay exchange )
2429
- `TC_SLACK_WEBHOOK_URL`: slack webhook url
2530
- `SLACK_ICON_URL`: slack webhook icon url

config/default.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ module.exports = {
3434
// The base url to the project/user API server
3535
API_BASE_URL: 'http://localhost:3001',
3636

37+
// The different paths of API_BASE_URL accessed by this project
38+
API_URL_PROJECTS: '/v4/projects',
39+
API_URL_MEMBERS: '/v3/members',
40+
API_URL_USERS: '/v3/users',
41+
API_URL_AUTHORIZATIONS: '/v3/authorizations',
42+
API_URL_TOPICS: '/v5/topics',
43+
3744
// Disable delay exchange and use direct instead ( delete existing delay exchnge after changing)
3845
DISABLE_DELAY_EXCHANGE: false,
3946

src/handlers/util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const createProjectDiscourseNotification = Promise.coroutine(
6060
return Promise.reject(new Error('Error retrieving system token'));
6161
}
6262
const options = {
63-
url: `${config.get('API_BASE_URL')}/v5/topics/create`,
63+
url: `${config.get('API_BASE_URL')}${config.get('API_URL_TOPICS')}/create`,
6464
method: 'POST',
6565
headers: {
6666
Authorization: `Bearer ${token}`,
@@ -138,7 +138,7 @@ function* getProjectById(id) {
138138
return Promise.reject(new Error('Error retrieving system token'));
139139
}
140140
return yield requestPromise({
141-
url: `${config.get('API_BASE_URL')}/v4/projects/${id}`,
141+
url: `${config.get('API_BASE_URL')}${config.get('API_URL_PROJECTS')}/${id}`,
142142
headers: {
143143
Authorization: `Bearer ${token}`,
144144
},
@@ -159,7 +159,7 @@ function* getUserById(id) { // eslint-disable-line require-yield
159159
}
160160
return reject(new Error('user not found'));
161161
};
162-
return requestPromise({ url: `${config.get('API_BASE_URL')}/v3/members/_search/?query=userId:${id}` }, cb);
162+
return requestPromise({ url: `${config.get('API_BASE_URL')}${config.get('API_URL_MEMBERS')}/_search/?query=userId:${id}` }, cb);
163163
}
164164

165165

src/test/app.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,33 +172,33 @@ describe('app', () => {
172172
// Stub the calls to API server
173173
stub = sinon.stub(request, 'get');
174174
const stubArgs = {
175-
url: `${config.API_BASE_URL}/v4/projects/1`,
175+
url: `${config.API_BASE_URL}${config.API_URL_PROJECTS}/1`,
176176
};
177177
stub.withArgs(sinon.match.has('url', stubArgs.url))
178178
.yields(null, { statusCode: 200 }, sampleProjects.project1);
179179

180-
stubArgs.url = `${config.API_BASE_URL}/v4/projects/1000`;
180+
stubArgs.url = `${config.API_BASE_URL}${config.API_URL_PROJECTS}/1000`;
181181
stub.withArgs(sinon.match.has('url', stubArgs.url))
182182
.yields(null, { statusCode: 404 });
183183

184-
stubArgs.url = `${config.API_BASE_URL}/v3/members/_search/?query=userId:1`;
184+
stubArgs.url = `${config.API_BASE_URL}${config.API_URL_MEMBERS}/_search/?query=userId:1`;
185185
stub.withArgs(sinon.match.has('url', stubArgs.url))
186186
.yields(null, { statusCode: 200 }, sampleUsers.user1);
187187

188-
stubArgs.url = `${config.API_BASE_URL}/v3/users/1000`;
188+
stubArgs.url = `${config.API_BASE_URL}${config.API_URL_USERS}/1000`;
189189
stub.withArgs(sinon.match.has('url', stubArgs.url))
190190
.yields(null, { statusCode: 404 });
191191

192-
stubArgs.url = `${config.API_BASE_URL}/v3/members/_search/?query=userId:40051331`;
192+
stubArgs.url = `${config.API_BASE_URL}${config.API_URL_MEMBERS}/_search/?query=userId:40051331`;
193193
stub.withArgs(sinon.match.has('url', stubArgs.url))
194194
.yields(null, { statusCode: 200 }, sampleUsers.user1);
195195

196-
stubArgs.url = `${config.API_BASE_URL}/v3/members/_search/?query=userId:50051333`;
196+
stubArgs.url = `${config.API_BASE_URL}${config.API_URL_MEMBERS}/_search/?query=userId:50051333`;
197197
stub.withArgs(sinon.match.has('url', stubArgs.url))
198198
.yields(null, { statusCode: 200 }, sampleUsers.user1);
199199

200200
postStub = sinon.stub(request, 'post');
201-
postStub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}/v3/authorizations/`))
201+
postStub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}${config.API_URL_AUTHORIZATIONS}/`))
202202
.yields(null, { statusCode: 200 }, sampleAuth);
203203

204204
postStub.withArgs(sinon.match.has('url', config.TC_SLACK_WEBHOOK_URL))
@@ -256,7 +256,7 @@ describe('app', () => {
256256
const callbackCount = 1;
257257
request.get.restore();
258258
stub = sinon.stub(request, 'get');
259-
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}/v3/members/_search/?query=userId:8547900`))
259+
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}${config.API_URL_MEMBERS}/_search/?query=userId:8547900`))
260260
.yields(null, { statusCode: 200 }, sampleUsers.user1);
261261

262262
sendTestEvent(sampleEvents.updatedInReview, 'project.updated');
@@ -285,7 +285,7 @@ describe('app', () => {
285285
it('should create `Project.Reviewed` and `Project.AvailableToClaim` and copilot slack notifications and repost after delay till TTL', (done) => {
286286
request.get.restore();
287287
stub = sinon.stub(request, 'get');
288-
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}/v4/projects/1`))
288+
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}${config.API_URL_PROJECTS}/1`))
289289
.yields(null, { statusCode: 200 }, sampleProjects.projectTest);
290290

291291
let assertCount = 0;
@@ -372,9 +372,9 @@ describe('app', () => {
372372
it('should create `Project.Member.CopilotJoined` notification and slack copilot joined notification', (done) => {
373373
request.get.restore();
374374
stub = sinon.stub(request, 'get');
375-
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}/v4/projects/1`))
375+
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}${config.API_URL_PROJECTS}/1`))
376376
.yields(null, { statusCode: 200 }, sampleProjects.projectTest);
377-
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}/v3/members/_search/?query=userId:40051331`))
377+
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}${config.API_URL_MEMBERS}/_search/?query=userId:40051331`))
378378
.yields(null, { statusCode: 200 }, sampleUsers.user1);
379379

380380
sendTestEvent(sampleEvents.memberAddedCopilot, 'project.member.added');

0 commit comments

Comments
 (0)