Skip to content

Commit

Permalink
feat(IBotRequest location): add location title that we receive from f…
Browse files Browse the repository at this point in the history
…acebook to ILocation
  • Loading branch information
Aco Mitevski committed Jun 20, 2016
1 parent 414ae02 commit 2b3bc5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/facebook/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ export class FacebookBot {
this.botController.imageMessage(imageMessage, reply) || null;
break;
case FB_ATTACHMENT_TYPE.LOCATION:
let location = {
let location: IBotRequest = {
user, location: {coordinates: attachment.payload.coordinates}, type: BOT_REQUEST_TYPE.FACEBOOK
};
if (attachment.title) {
location.location.title = attachment.title;
}
(this.botController.locationMessage) ? this.botController.locationMessage(location, reply) : null;
break;
case FB_ATTACHMENT_TYPE.FALLBACK:
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface ICoordinates {
long: number;
}
export interface ILocation {
title?: string;
coordinates: ICoordinates;
}

Expand Down
14 changes: 12 additions & 2 deletions tests/bot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DummyController implements IBotController {
imageMessage: 0,
linkMessage: 0,
locationMessage: 0,
location: {},
delivered: 0,
catchAll: 0,
}
Expand All @@ -20,7 +21,7 @@ class DummyController implements IBotController {
textMessage(msg: IBotRequest, reply: IBotReply) {console.log('got new textMessage'); this.cc.textMessage++;}
imageMessage(image: IBotRequest, reply: IBotReply) {console.log('got new imageMessage'); this.cc.imageMessage++;}
linkMessage(msg: IBotRequest, reply: IBotReply) {console.log('got linkMessage'); this.cc.linkMessage++;}
locationMessage(msg: IBotRequest, reply: IBotReply) {console.log('got locationMessage'); this.cc.locationMessage++;}
locationMessage(msg: IBotRequest, reply: IBotReply) {console.log('got locationMessage'); this.cc.locationMessage++; this.cc.location = msg.location;}
delivered(msg: IBotRequest, reply: IBotReply) {console.log('got delivered'); this.cc.delivered++;}
catchAll(msg: IBotRequest, reply: IBotReply) {console.log('got catchAll'); this.cc.catchAll++;}
}
Expand Down Expand Up @@ -63,10 +64,19 @@ describe('FacebookBot', () => {
expect(ctrl.cc.imageMessage).to.eql(1);
expect(ctrl.cc.locationMessage).to.eql(1);
done();
})
});

// just console.log testing for now :(
// if anyone knows a good mocking library for typescript youre welcome :)
});

it('should get location title', (done) => {
bot.receiveMessage(fakeMessageMixed())
.then( dispatchResults => {
expect(ctrl.cc.location['title']).to.eql(`Aco's Location`);
done();
});
});

});
describe('dispatchSingleMessage', () => {
Expand Down

0 comments on commit 2b3bc5e

Please sign in to comment.