Skip to content

Commit 5e01254

Browse files
author
Igor Drobiazko
committed
More logs + reformatted code
1 parent 1446a1c commit 5e01254

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

lib/actions/createEvent.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ function getCalendars(cfg, cb) {
3030
function processAction(msg, cfg) {
3131

3232
const self = this;
33-
const apiCall = `/me/calendars/${cfg.calendarId}/events`;
33+
const calendarId = cfg.calendarId;
34+
console.log(`About to create event in calendar with id=${calendarId}`);
35+
36+
const apiCall = `/me/calendars/${calendarId}/events`;
3437

3538
const instance = new ApiClient(cfg);
3639

@@ -46,6 +49,7 @@ function processAction(msg, cfg) {
4649
const messageBody = _.omitBy(data, (value, key) => key.startsWith('@odata.'));
4750
messageBody.calendarId = cfg.calendarId;
4851
console.log('Emitting data ...');
52+
console.log('%s', messageBody);
4953
self.emit('data', messages.newMessageWithBody(messageBody));
5054
}
5155

@@ -61,9 +65,9 @@ function processAction(msg, cfg) {
6165

6266

6367
let promise = processEventData(cfg, msg.body)
64-
.then(createEvent)
65-
.then(emitData)
66-
.fail(emitError);
68+
.then(createEvent)
69+
.then(emitData)
70+
.fail(emitError);
6771

6872
return promise.finally(emitEnd);
6973

lib/triggers/contacts.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@ function processAction(msg, cfg, snapshot) {
2121

2222
// Main loop
2323
co(function* mainLoop() {
24-
console.log('Refreshing an OAuth Token');
25-
const newToken = yield rp({
26-
method: 'POST',
27-
uri: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
28-
json: true,
29-
form: {
30-
refresh_token: cfg.oauth.refresh_token,
31-
scope: cfg.oauth.scope,
32-
grant_type: 'refresh_token',
33-
client_id: process.env.MSAPP_CLIENT_ID,
34-
client_secret: process.env.MSAPP_CLIENT_SECRET
35-
}
36-
});
37-
console.log('Updating token');
38-
this.emit('updateKeys', { oauth: newToken });
24+
console.log('Refreshing an OAuth Token');
25+
const newToken = yield rp({
26+
method: 'POST',
27+
uri: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
28+
json: true,
29+
form: {
30+
refresh_token: cfg.oauth.refresh_token,
31+
scope: cfg.oauth.scope,
32+
grant_type: 'refresh_token',
33+
client_id: process.env.MSAPP_CLIENT_ID,
34+
client_secret: process.env.MSAPP_CLIENT_SECRET
35+
}
36+
});
37+
console.log('Updating token');
38+
this.emit('updateKeys', {
39+
oauth: newToken
40+
});
3941

4042
const client = MicrosoftGraph.init({
4143
defaultVersion: 'v1.0',

spec/dynamic_selector_functions/getCalendars.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('Outlook Get Calendars', function test() {
1616
it('should return calendar info on success get request', done => {
1717
nock(refreshTokenUri).post(refreshTokenApi)
1818
.reply(200, {
19-
access_token: 1
20-
});
19+
access_token: 1
20+
});
2121

2222
nock(microsoftGraphUri).get(microsoftGraphApi)
2323
.reply(200, jsonOut);
@@ -37,7 +37,7 @@ describe('Outlook Get Calendars', function test() {
3737
it('should return errors on refresh token failure ', done => {
3838
nock(refreshTokenUri).post(refreshTokenApi)
3939
.reply(401, {
40-
access_token: 1
40+
access_token: 1
4141
});
4242

4343
nock(microsoftGraphUri).get(microsoftGraphApi)

0 commit comments

Comments
 (0)