Skip to content

Commit 4721c0f

Browse files
author
Igor Drobiazko
authored
Merge pull request #7 from Nazar910/bugfix
Bugfix
2 parents c95a635 + 7135032 commit 4721c0f

File tree

3 files changed

+158
-3
lines changed

3 files changed

+158
-3
lines changed

lib/triggers/contacts.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const messages = require('elasticio-node').messages;
44
const co = require('co');
55
const MicrosoftGraph = require('msgraph-sdk-javascript');
66
const rp = require('request-promise');
7+
const _ = require('lodash');
78

89
/**
910
* This method will be called from elastic.io platform providing following data
@@ -56,10 +57,11 @@ function processAction(msg, cfg, snapshot) {
5657
const values = contacts.value;
5758
console.log('Found %s contacts', values.length);
5859
if (values.length > 0) {
59-
const message = messages.newMessageWithBody({
60-
contacts: values
60+
values.forEach((elem)=> {
61+
const messageBody = _.omitBy(elem, (value, key) => key.startsWith('@odata.'));
62+
messageBody.calendarId = cfg.calendarId;
63+
this.emit('data', messages.newMessageWithBody(messageBody));
6164
});
62-
this.emit('data', message);
6365
let lmdate = new Date(values[values.length - 1].lastModifiedDateTime);
6466
// The output value has always 0 milliseconds
6567
// we need to set the milliseconds value to 999 in order not to see

spec/data/getContact_test.out.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[
2+
{
3+
"@odata.etag": "W/\"EQAAABYAAAAPk/xXi/m8SpOJXtHI8EVyAAAAADMd\"",
4+
"otherAddress": {},
5+
"businessAddress": {},
6+
"homeAddress": {},
7+
"emailAddresses": [],
8+
"children": [],
9+
"personalNotes": null,
10+
"spouseName": null,
11+
"businessPhones": [],
12+
"mobilePhone": null,
13+
"homePhones": [],
14+
"manager": null,
15+
"assistantName": null,
16+
"businessHomePage": null,
17+
"profession": null,
18+
"officeLocation": null,
19+
"department": null,
20+
"companyName": null,
21+
"jobTitle": null,
22+
"imAddresses": [],
23+
"generation": null,
24+
"yomiCompanyName": null,
25+
"yomiSurname": null,
26+
"yomiGivenName": null,
27+
"title": null,
28+
"surname": "LastName",
29+
"nickName": null,
30+
"middleName": null,
31+
"initials": null,
32+
"givenName": "Contact1",
33+
"displayName": "Contact1 LastName",
34+
"fileAs": "LastName, Contact1",
35+
"birthday": null,
36+
"parentFolderId": "AQMkADAwATMwMAItY2ZmADktNjM4OAAtMDACLTAwCgAuAAADsOSavd0-LEaQVsombMCNegEAO2Hd7H7x9USxohZwL5iAFQAAAgEOAAAA",
37+
"categories": [],
38+
"changeKey": "EQAAABYAAAA7Yd3sfvH1RLGiFnAvmIAVAACGnyqI",
39+
"lastModifiedDateTime": "2017-03-13T14:27:23Z",
40+
"createdDateTime": "2017-03-13T14:17:05Z",
41+
"id": "AQMkADAwATMwMAItY2ZmADktNjM4OAAtMDACLTAwCgBGAAADsOSavd0-LEaQVsombMCNegcAO2Hd7H7x9USxohZwL5iAFQAAAgEOAAAAO2Hd7H7x9USxohZwL5iAFQAAAIaR-vMAAAA="
42+
},
43+
{
44+
"@odata.etag": "W/\"EQAAABYAAAAPk/xXi/m8SpOJXtHI8EVyAAAAADMe\"",
45+
"otherAddress": {},
46+
"businessAddress": {},
47+
"homeAddress": {},
48+
"emailAddresses": [],
49+
"children": [],
50+
"personalNotes": null,
51+
"spouseName": null,
52+
"businessPhones": [],
53+
"mobilePhone": null,
54+
"homePhones": [],
55+
"manager": null,
56+
"assistantName": null,
57+
"businessHomePage": null,
58+
"profession": null,
59+
"officeLocation": null,
60+
"department": null,
61+
"companyName": null,
62+
"jobTitle": null,
63+
"imAddresses": [],
64+
"generation": null,
65+
"yomiCompanyName": null,
66+
"yomiSurname": null,
67+
"yomiGivenName": null,
68+
"title": null,
69+
"surname": "LastName2",
70+
"nickName": null,
71+
"middleName": null,
72+
"initials": null,
73+
"givenName": "contact2",
74+
"displayName": "contact2 LastName2",
75+
"fileAs": "LastName2, contact2",
76+
"birthday": null,
77+
"parentFolderId": "AQMkADAwATMwMAItY2ZmADktNjM4OAAtMDACLTAwCgAuAAADsOSavd0-LEaQVsombMCNegEAO2Hd7H7x9USxohZwL5iAFQAAAgEOAAAA",
78+
"categories": [],
79+
"changeKey": "EQAAABYAAAA7Yd3sfvH1RLGiFnAvmIAVAACGnyqK",
80+
"lastModifiedDateTime": "2017-03-13T15:22:32Z",
81+
"createdDateTime": "2017-03-13T15:16:17Z",
82+
"id": "AQMkADAwATMwMAItY2ZmADktNjM4OAAtMDACLTAwCgBGAAADsOSavd0-LEaQVsombMCNegcAO2Hd7H7x9USxohZwL5iAFQAAAgEOAAAAO2Hd7H7x9USxohZwL5iAFQAAAIaR-vQAAAA="
83+
}
84+
]

spec/triggers/getContacts.spec.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
describe('Outlook Contacts', function test() {
4+
5+
const nock = require('nock');
6+
const _ = require('lodash');
7+
const trigger = require('../../lib/triggers/contacts');
8+
9+
const cfg = require('../data/configuration.in.json');
10+
const jsonOut = {
11+
value: require('../data/getContact_test.out.json')
12+
};
13+
14+
const refreshTokenUri = 'https://login.microsoftonline.com';
15+
const refreshTokenApi = '/common/oauth2/v2.0/token';
16+
const microsoftGraphUri = 'https://graph.microsoft.com/v1.0';
17+
const microsoftGraphApi = '/me/contacts';
18+
19+
20+
var self;
21+
beforeEach(function createSpy() {
22+
self = jasmine.createSpyObj('self', ['emit']);
23+
});
24+
25+
it('should emit data without @oauth property - case: http 200', done => {
26+
const scope1 = nock(refreshTokenUri).post(refreshTokenApi)
27+
.reply(200, {
28+
access_token: 1
29+
});
30+
31+
const scope2 = nock(microsoftGraphUri).get(microsoftGraphApi)
32+
.query({
33+
$orderby: 'lastModifiedDateTime asc',
34+
$top: 900,
35+
$filter: 'lastModifiedDateTime gt 1970-01-01T00:00:00.000Z'
36+
})
37+
.reply(200, jsonOut);
38+
39+
function checkResults() {
40+
let calls = self.emit.calls;
41+
expect(calls.count()).toEqual(4);
42+
expect(calls.argsFor(0)[0]).toEqual('updateKeys');
43+
const [firstEvent, firstEmitData] = calls.argsFor(1);
44+
expect(firstEvent).toBe('data');
45+
expect(firstEmitData.body).toEqual(Object.assign(
46+
_.omit(jsonOut.value[0], '@odata.etag'),
47+
{
48+
calendarId: cfg.calendarId
49+
}
50+
));
51+
const [secondEvent, secondEmitData] = calls.argsFor(2);
52+
expect(secondEvent).toBe('data');
53+
expect(secondEmitData.body).toEqual(Object.assign(
54+
_.omit(jsonOut.value[1], '@odata.etag'),
55+
{
56+
calendarId: cfg.calendarId
57+
}
58+
));
59+
expect(scope1.isDone()).toBeTruthy();
60+
expect(scope2.isDone()).toBeTruthy();
61+
}
62+
63+
trigger.process.call(self, {}, cfg, {})
64+
.then(checkResults)
65+
.then(done)
66+
.catch(done.fail);
67+
});
68+
69+
});

0 commit comments

Comments
 (0)