Skip to content

Commit f19b54a

Browse files
committedJun 4, 2016
Support testcase for push service handle
Update manifest to allow getting push from podio
1 parent 303f60b commit f19b54a

File tree

10 files changed

+119
-6
lines changed

10 files changed

+119
-6
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"chrome-storage-local": "^0.1.5",
9393
"classnames": "^2.2.5",
9494
"crossmessaging": "^0.2.0",
95+
"faye": "^1.1.2",
9596
"moment": "^2.13.0",
9697
"podio-js": "^1.4.2",
9798
"react": "^0.14.7 || ^15.0.0",

‎src/app/containers/task/action-task.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export function filterPanel({ status, category, assignee }) {
2727

2828
let _assignee;
2929
if (assignee) {
30-
_assignee = assignee.map(item => (item === 'me' ? getState().app.myAccount.data.id : item));
30+
_assignee = assignee.map(item => (item === 'me' ? getState().app.myAccount.data.profileId : item));
3131
}
32+
3233
return getRepo({})
3334
.then(api => api.task.filterList({ status, assignee: _assignee, category }))
3435
.then(data => {

‎src/app/struct/contact.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const Contact = t.struct({
99
avatar: t.maybe(t.String),
1010
avatarThumbnail: t.maybe(t.String),
1111
name: t.String,
12+
profileId: t.Number
1213
});
1314

1415
export default Contact;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Created by phucpnt on 6/4/16.
3+
*/
4+
5+
import faye from 'faye';
6+
7+
export default function createPushService(podio, { workspaceId, messageHandle }) {
8+
9+
10+
return podio.request('GET', `/space/${workspaceId}`).then(response => {
11+
return new Promise((resolve, reject) => {
12+
// Initialize faye client
13+
const fayeClient = new faye.Client('https://push.podio.com/faye');
14+
15+
// Simple push object for handling a subscription
16+
const push = {
17+
subscription: null,
18+
channel: null,
19+
messageReceived(message) {
20+
messageHandle(message);
21+
},
22+
addSubscription(channel) {
23+
this.channel = channel;
24+
this.subscription = fayeClient.subscribe(this.channel.channel, this.messageReceived);
25+
26+
this.subscription.then(function () {
27+
console.log('Subscription is now active');
28+
resolve(fayeClient);
29+
}, function (error) {
30+
console.error('Subscription failed: ', error.message, error);
31+
reject(error);
32+
});
33+
}
34+
};
35+
36+
// Extend faye client with signature and timestamp used for authentication
37+
fayeClient.addExtension({
38+
outgoing: function (message, callback) {
39+
message.ext = message.ext || {};
40+
message.ext = {
41+
private_pub_signature: push.channel.signature,
42+
private_pub_timestamp: push.channel.timestamp
43+
};
44+
callback(message);
45+
}
46+
});
47+
push.addSubscription(response.push);
48+
49+
});
50+
});
51+
}

‎src/browser/extension/connect/podio/helper/podio-id-list.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ export const DevTaskField = {
2222

2323
export const ContactField = {
2424
id: 'profile.user_id',
25+
profileId: 'profile.profile_id',
2526
name: 'profile.name',
2627
link: 'profile.link',
2728
avatar: 'profile.image.link',
2829
avatarThumbnail: 'profile.image.thumbnail_link',
2930
type: 'profile.type',
30-
role: 'role'
31+
role: 'role',
3132
};

‎src/browser/extension/connect/podio/repo-podio.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isConnected } from './connect-podio';
22
import taskOps from './task';
33
import contactOps from './contact';
44
import { DevTaskField } from './helper/podio-id-list';
5+
import createPushServicePodio from './create-push-service';
56

67
export default function getApi({
78
workspaceId = 4555999,
@@ -11,13 +12,21 @@ export default function getApi({
1112
taskAppId=15818250,
1213
}) {
1314

15+
const updateCallbacks = [];
16+
1417
const api = podio => ({
1518
task: taskOps(podio, { appId: taskAppId, appField: DevTaskField }),
16-
contact: contactOps(podio, { workspaceId })
19+
contact: contactOps(podio, { workspaceId }),
20+
addListenerForUpdates(callback) {
21+
updateCallbacks.push(callback);
22+
}
1723
});
1824

25+
const createPushService = podio => {
26+
return podio;
27+
};
1928

20-
return isConnected().then(api).catch(err => {
29+
return isConnected().then(createPushService).then(api).catch(err => {
2130
throw err;
2231
});
2332
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/**
2+
* Created by phucpnt on 6/4/16.
3+
*/

‎src/browser/extension/manifest.dev.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
"webRequest",
2424
"webRequestBlocking"
2525
],
26-
"content_security_policy": "default-src 'self'; script-src 'self' http://localhost:3000 'unsafe-eval' 'unsafe-inline'; connect-src http://localhost:3000 ws://localhost:3000 ws://localhost:35729 http://*/ https://*/; style-src 'self' data: chrome-extension-resource: blob: 'unsafe-inline'; img-src 'self' data: http://*/ https://*/; frame-src 'self' http://*/ https://*/;"
26+
"content_security_policy": "default-src 'self'; script-src 'self' https://*.podio.com/ http://localhost:3000 'unsafe-eval' 'unsafe-inline'; connect-src http://localhost:3000 ws://localhost:3000 ws://localhost:35729 http://*/ https://*/ wss://*/; style-src 'self' data: chrome-extension-resource: blob: 'unsafe-inline'; img-src 'self' data: http://*/ https://*/; frame-src 'self' http://*/ https://*/;"
2727
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Created by phucpnt on 6/4/16.
3+
*/
4+
5+
import { expect } from 'chai';
6+
import { spy } from 'sinon';
7+
import moment from 'moment';
8+
9+
import createPushService from '../../../../src/browser/extension/connect/podio/create-push-service';
10+
import taskOps from '../../../../src/browser/extension/connect/podio/task';
11+
import connectPodio, { getAppTaskDetails } from '../../helper/connect-podio';
12+
13+
const TEST_WORKSPACE_ID = 4572579;
14+
15+
connectPodio(podio => {
16+
const testTaskApp = getAppTaskDetails();
17+
const apiTask = taskOps(podio, { appId: testTaskApp.appId, appField: testTaskApp.appFields });
18+
describe.only('Podio Push Service', () => {
19+
20+
const fakeHandle = spy();
21+
before(done => {
22+
createPushService(podio, {
23+
workspaceId: TEST_WORKSPACE_ID,
24+
messageHandle: (...args) => {
25+
console.log(args);
26+
fakeHandle(...args);
27+
},
28+
}).then(() => done());
29+
});
30+
31+
it('it should receive message when new task is created', (done) => {
32+
apiTask.create({ subject: 'Test App', startDate: moment().format('YYYY-MM-DD HH:mm:ss') }).then(task => {
33+
console.log(task);
34+
setTimeout(() => {
35+
expect(fakeHandle.called).to.be.true;
36+
const pushedData = fakeHandle.getCall(0).args[0];
37+
expect(pushedData).to.have.deep.property('data.data.context_ref');
38+
expect(pushedData).to.have.deep.property('data.data.data_ref');
39+
expect(pushedData.data.data.context_ref.id).to.equal(task.id);
40+
done();
41+
}, 1000);
42+
});
43+
});
44+
});
45+
46+
});

‎test/inbrowser/connect/podio/task.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ connectPodio((podio) => {
3737

3838
const task = taskOps(podio, { appId, appField });
3939

40-
describe.only('Task App Podio', () => {
40+
describe('Task App Podio', () => {
4141
const taskApi = taskOps(podio, { appId: 15818250, appField });
4242
it('it support getting app setup', done => {
4343
taskApi.getAppSetup().then(response => {

0 commit comments

Comments
 (0)
Please sign in to comment.