Skip to content

Commit 7a48f94

Browse files
authored
Merge pull request #26 from marcel-devdude/copilot/sub-pr-25
Fix makeRequest to return Promise for proper async chaining
2 parents 1dcf7c2 + f3b566c commit 7a48f94

3 files changed

Lines changed: 44 additions & 43 deletions

File tree

lib/mite-api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = function(options) {
4545

4646
var body = response.data;
4747
var statusCode = response.status;
48-
var method = (response.config?.method || 'GET').toUpperCase();
48+
var method = (response.config && response.config.method || 'GET').toUpperCase();
4949

5050
switch (method) {
5151
case 'GET':
@@ -90,7 +90,7 @@ module.exports = function(options) {
9090
requestOptions.headers['X-MiteApiKey'] = options.apiKey;
9191
}
9292

93-
options.request(requestOptions)
93+
return options.request(requestOptions)
9494
.then(function(response) {
9595
handleResponse(null, response, done);
9696
})

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Configuration', function() {
1111
mite = miteApi();
1212
mite.getOption('account').should.be.false;
1313
mite.getOption('apiKey').should.be.false;
14-
return mite.getOption('applicationName').should.be.false;
14+
mite.getOption('applicationName').should.be.false;
1515
});
1616
return it('should be overwrite default options', function() {
1717
var mite;
@@ -22,7 +22,7 @@ describe('Configuration', function() {
2222
});
2323
mite.getOption('account').should.be.equal('account');
2424
mite.getOption('apiKey').should.be.equal('apikey');
25-
return mite.getOption('applicationName').should.be.equal('applicationname');
25+
mite.getOption('applicationName').should.be.equal('applicationname');
2626
});
2727
});
2828

@@ -34,7 +34,7 @@ describe('URL', function() {
3434
apiKey: 'apikey',
3535
applicationName: 'applicationname'
3636
});
37-
return mite.getUrl('services').should.equal('https://account.mite.de/services.json');
37+
mite.getUrl('services').should.equal('https://account.mite.de/services.json');
3838
});
3939
it('should be a valid API-URL with an api_key query-parameter', function() {
4040
var mite;
@@ -44,7 +44,7 @@ describe('URL', function() {
4444
applicationName: 'applicationname',
4545
query: true
4646
});
47-
return mite.getUrl('services').should.equal('https://account.mite.de/services.json?api_key=apikey');
47+
mite.getUrl('services').should.equal('https://account.mite.de/services.json?api_key=apikey');
4848
});
4949
it('should be a valid API-URL with a filter query-parameter', function() {
5050
var mite;
@@ -53,7 +53,7 @@ describe('URL', function() {
5353
apiKey: 'apikey',
5454
applicationName: 'applicationname'
5555
});
56-
return mite.getUrl('services', {
56+
mite.getUrl('services', {
5757
limit: 50,
5858
page: 2
5959
}).should.equal('https://account.mite.de/services.json?limit=50&page=2');
@@ -65,7 +65,7 @@ describe('URL', function() {
6565
apiKey: 'apikey',
6666
applicationName: 'applicationname'
6767
});
68-
return mite.getUrl('dailyDate', {
68+
mite.getUrl('dailyDate', {
6969
year: 2013,
7070
month: 1,
7171
day: 1
@@ -97,7 +97,7 @@ describe('API', function() {
9797
request: getAccountRequestMock
9898
});
9999
return it('when not found calls the callback with an error object', function(done) {
100-
return mite.getAccount(function(err) {
100+
mite.getAccount(function(err) {
101101
err.should.be.an.instanceOf(Error);
102102
err.message.should.equal('Whoops! We couldn\'t find your account');
103103
return done();
@@ -127,7 +127,7 @@ describe('API', function() {
127127
request: deleteProjectRequestMock
128128
});
129129
return it('calls done with rror when project was not found', function(done) {
130-
return mite.deleteProject(21, function(err) {
130+
mite.deleteProject(21, function(err) {
131131
err.should.be.an.instanceOf(Error);
132132
err.message.should.equal('Der Datensatz ist nicht vorhanden');
133133
return done();
@@ -143,7 +143,7 @@ describe('API', function() {
143143
request: axiosMock
144144
});
145145
it('should be get all services', function(done) {
146-
return mite.getServices(function(err, services) {
146+
mite.getServices(function(err, services) {
147147
services.should.have.length(1);
148148
services[0].service.should.have.property('billable');
149149
services[0].service.should.have.property('created_at');
@@ -157,7 +157,7 @@ describe('API', function() {
157157
});
158158
});
159159
it('should be get all archived services', function(done) {
160-
return mite.getArchivedServices(function(err, services) {
160+
mite.getArchivedServices(function(err, services) {
161161
services.should.have.length(1);
162162
services[0].service.should.have.property('billable');
163163
services[0].service.should.have.property('created_at');
@@ -171,7 +171,7 @@ describe('API', function() {
171171
});
172172
});
173173
it('should be get one service', function(done) {
174-
return mite.getService(1, function(err, service) {
174+
mite.getService(1, function(err, service) {
175175
service.service.should.have.property('billable');
176176
service.service.should.have.property('created_at');
177177
service.service.should.have.property('hourly_rate');
@@ -184,7 +184,7 @@ describe('API', function() {
184184
});
185185
});
186186
it('should be able to add new service', function(done) {
187-
return mite.addService({
187+
mite.addService({
188188
name: 'Service'
189189
}, function(err, service) {
190190
service.service.should.have.property('billable');
@@ -199,7 +199,7 @@ describe('API', function() {
199199
});
200200
});
201201
it('should be able to update service', function(done) {
202-
return mite.updateService(1, {
202+
mite.updateService(1, {
203203
name: 'Service'
204204
}, function(err, service) {
205205
service.service.should.have.property('billable');
@@ -214,7 +214,7 @@ describe('API', function() {
214214
});
215215
});
216216
return it('should be able to delete service', function(done) {
217-
return mite.deleteService(1, function() {
217+
mite.deleteService(1, function() {
218218
return done();
219219
});
220220
});
@@ -228,7 +228,7 @@ describe('API', function() {
228228
request: axiosMock
229229
});
230230
it('should be get all customers', function(done) {
231-
return mite.getCustomers(function(err, customers) {
231+
mite.getCustomers(function(err, customers) {
232232
customers.should.have.length(1);
233233
customers[0].customer.should.have.property('created_at');
234234
customers[0].customer.should.have.property('hourly_rate');
@@ -243,7 +243,7 @@ describe('API', function() {
243243
});
244244
});
245245
it('should be get all archived customers', function(done) {
246-
return mite.getArchivedCustomers(function(err, customers) {
246+
mite.getArchivedCustomers(function(err, customers) {
247247
customers.should.have.length(1);
248248
customers[0].customer.should.have.property('created_at');
249249
customers[0].customer.should.have.property('hourly_rate');
@@ -258,7 +258,7 @@ describe('API', function() {
258258
});
259259
});
260260
it('should be get one customer', function(done) {
261-
return mite.getCustomer(1, function(err, customer) {
261+
mite.getCustomer(1, function(err, customer) {
262262
customer.customer.should.have.property('created_at');
263263
customer.customer.should.have.property('hourly_rate');
264264
customer.customer.should.have.property('id');
@@ -272,7 +272,7 @@ describe('API', function() {
272272
});
273273
});
274274
it('should be able to add new customer', function(done) {
275-
return mite.addCustomer({
275+
mite.addCustomer({
276276
name: 'Customer'
277277
}, function(err, customer) {
278278
customer.customer.should.have.property('created_at');
@@ -288,7 +288,7 @@ describe('API', function() {
288288
});
289289
});
290290
it('should be able to update customer', function(done) {
291-
return mite.updateCustomer(1, {
291+
mite.updateCustomer(1, {
292292
name: 'Customer'
293293
}, function(err, customer) {
294294
customer.customer.should.have.property('created_at');
@@ -304,7 +304,7 @@ describe('API', function() {
304304
});
305305
});
306306
return it('should be able to delete customer', function(done) {
307-
return mite.deleteCustomer(1, function() {
307+
mite.deleteCustomer(1, function() {
308308
return done();
309309
});
310310
});
@@ -318,7 +318,7 @@ describe('API', function() {
318318
request: axiosMock
319319
});
320320
it('should be get all projects', function(done) {
321-
return mite.getProjects(function(err, projects) {
321+
mite.getProjects(function(err, projects) {
322322
projects.should.have.length(1);
323323
projects[0].project.should.have.property('budget');
324324
projects[0].project.should.have.property('budget_type');
@@ -337,7 +337,7 @@ describe('API', function() {
337337
});
338338
});
339339
it('should be get all archived projects', function(done) {
340-
return mite.getArchivedProjects(function(err, projects) {
340+
mite.getArchivedProjects(function(err, projects) {
341341
projects.should.have.length(1);
342342
projects[0].project.should.have.property('budget');
343343
projects[0].project.should.have.property('budget_type');
@@ -356,7 +356,7 @@ describe('API', function() {
356356
});
357357
});
358358
it('should be get one project', function(done) {
359-
return mite.getProject(1, function(err, project) {
359+
mite.getProject(1, function(err, project) {
360360
project.project.should.have.property('budget');
361361
project.project.should.have.property('budget_type');
362362
project.project.should.have.property('created_at');
@@ -374,7 +374,7 @@ describe('API', function() {
374374
});
375375
});
376376
it('should be able to add new project', function(done) {
377-
return mite.addProject({
377+
mite.addProject({
378378
name: 'Project'
379379
}, function(err, project) {
380380
project.project.should.have.property('budget');
@@ -394,7 +394,7 @@ describe('API', function() {
394394
});
395395
});
396396
it('should be able to update project', function(done) {
397-
return mite.updateProject(1, {
397+
mite.updateProject(1, {
398398
name: 'Project'
399399
}, function(err, project) {
400400
project.project.should.have.property('budget');
@@ -414,7 +414,7 @@ describe('API', function() {
414414
});
415415
});
416416
return it('should be able to delete project', function(done) {
417-
return mite.deleteProject(1, function() {
417+
mite.deleteProject(1, function() {
418418
return done();
419419
});
420420
});
@@ -428,7 +428,7 @@ describe('API', function() {
428428
request: axiosMock
429429
});
430430
it('should be get all users', function(done) {
431-
return mite.getUsers(function(err, users) {
431+
mite.getUsers(function(err, users) {
432432
users.should.have.length(1);
433433
users[0].user.should.have.property('created_at');
434434
users[0].user.should.have.property('email');
@@ -443,7 +443,7 @@ describe('API', function() {
443443
});
444444
});
445445
it('should be get all archived users', function(done) {
446-
return mite.getArchivedUsers(function(err, users) {
446+
mite.getArchivedUsers(function(err, users) {
447447
users.should.have.length(1);
448448
users[0].user.should.have.property('created_at');
449449
users[0].user.should.have.property('email');
@@ -458,7 +458,7 @@ describe('API', function() {
458458
});
459459
});
460460
it('should be get one user', function(done) {
461-
return mite.getUser(1, function(err, user) {
461+
mite.getUser(1, function(err, user) {
462462
user.user.should.have.property('created_at');
463463
user.user.should.have.property('email');
464464
user.user.should.have.property('id');
@@ -472,7 +472,7 @@ describe('API', function() {
472472
});
473473
});
474474
it('should be get myself', function(done) {
475-
return mite.getMyself(function(err, user) {
475+
mite.getMyself(function(err, user) {
476476
user.user.should.have.property('created_at');
477477
user.user.should.have.property('email');
478478
user.user.should.have.property('id');
@@ -486,7 +486,7 @@ describe('API', function() {
486486
});
487487
});
488488
return it('should be get the account', function(done) {
489-
return mite.getAccount(function(err, account) {
489+
mite.getAccount(function(err, account) {
490490
account.account.should.have.property('created_at');
491491
account.account.should.have.property('currency');
492492
account.account.should.have.property('id');
@@ -506,7 +506,7 @@ describe('API', function() {
506506
request: axiosMock
507507
});
508508
it('should be get all daily time entries', function(done) {
509-
return mite.getDailyTimeEntries(2013, 1, 1, function(err, entries) {
509+
mite.getDailyTimeEntries(2013, 1, 1, function(err, entries) {
510510
entries.should.have.length(1);
511511
entries[0].time_entry.should.have.property('billable');
512512
entries[0].time_entry.should.have.property('created_at');
@@ -529,7 +529,7 @@ describe('API', function() {
529529
});
530530
});
531531
it('should be get all time entries', function(done) {
532-
return mite.getTimeEntries(function(err, entries) {
532+
mite.getTimeEntries(function(err, entries) {
533533
entries.should.have.length(1);
534534
entries[0].time_entry.should.have.property('billable');
535535
entries[0].time_entry.should.have.property('created_at');
@@ -552,7 +552,7 @@ describe('API', function() {
552552
});
553553
});
554554
it('should be get one time entry', function(done) {
555-
return mite.getTimeEntry(1, function(err, entry) {
555+
mite.getTimeEntry(1, function(err, entry) {
556556
entry.time_entry.should.have.property('billable');
557557
entry.time_entry.should.have.property('created_at');
558558
entry.time_entry.should.have.property('date_at');
@@ -574,7 +574,7 @@ describe('API', function() {
574574
});
575575
});
576576
it('should be able to add new time entry', function(done) {
577-
return mite.addTimeEntry({
577+
mite.addTimeEntry({
578578
name: 'TimeEntry'
579579
}, function(err, entry) {
580580
entry.time_entry.should.have.property('billable');
@@ -598,7 +598,7 @@ describe('API', function() {
598598
});
599599
});
600600
it('should be able to update time entry', function(done) {
601-
return mite.updateTimeEntry(1, {
601+
mite.updateTimeEntry(1, {
602602
name: 'TimeEntry'
603603
}, function(err, entry) {
604604
entry.time_entry.should.have.property('billable');
@@ -622,7 +622,7 @@ describe('API', function() {
622622
});
623623
});
624624
return it('should be able to delete time entry', function(done) {
625-
return mite.deleteTimeEntry(1, function() {
625+
mite.deleteTimeEntry(1, function() {
626626
return done();
627627
});
628628
});

0 commit comments

Comments
 (0)