Permalink
Browse files

Added test for addComment and deleteComment

Actually, the deleteComment test is invoked by the addComment
(chaining). The test posts a comment to a checkin and immediately
removes it. Please note that in order to post a comment to a checkin
you first have to be a friend of the user the checkin belongs to.
  • Loading branch information...
1 parent 949c49c commit cacbe5812e88762cd857d7bdf0b902a32ba9e0b8 @matteoagosti committed Jun 28, 2012
Showing with 49 additions and 0 deletions.
  1. +49 −0 test/node-foursquare-test.js
@@ -148,6 +148,7 @@ function TestSuite(accessToken) {
});
};
+
Tests.Users.getFriends = function() {
var test = "Foursquare.Users.getFriends(self)";
Foursquare.Users.getFriends(null, null, accessToken, function (error, data) {
@@ -475,6 +476,54 @@ function TestSuite(accessToken) {
}
});
};
+
+ Tests.Checkins.addCommentToCheckin = function(commentId) {
+ var self = this;
+ var test = "Foursquare.Checkins.addCommentToCheckin(4fc1f24ee4b06f6d23627a50, {text: 'Hello world!'})";
+ Foursquare.Checkins.addCommentToCheckin("4fc1f24ee4b06f6d23627a50", {text: "Hello world!"}, accessToken, function (error, data) {
+ if(error) {
+ reportError(test, error.message);
+ }
+ else {
+ try {
+ logger.trace(sys.inspect(data));
+ assert.ok(data.comment);
+ assert.ok(data.comment.id);
+ assert.equal(data.comment.text, "Hello world!");
+ ok(test);
+
+ // Executes the deleteCommentFromCheckin test by removing the just-added comment
+ self.Tests.Checkins.deleteCommentFromCheckin("4fc1f24ee4b06f6d23627a50", data.comment.id);
+ } catch (error) {
+ reportError(test, error);
+ }
+ }
+ });
+ };
+
+ Tests.Checkins.deleteCommentFromCheckin = function(checkinId, commentId) {
+ // Executes only when called from addCommentToCheckin
+ if(!checkinId || !commentId) return;
+
+ var test = "Foursquare.Checkins.deleteCommentFromCheckin(" + checkinId + ", {commentId: '" + commentId +"'})";
+ logger.debug("Running: " + test);
+ Foursquare.Checkins.deleteCommentFromCheckin(checkinId, {commentId: commentId}, accessToken, function (error, data) {
+ if(error) {
+ reportError(test, error.message);
+ }
+ else {
+ try {
+ logger.trace(sys.inspect(data));
+ assert.ok(data.checkin);
+ assert.equal(data.checkin.id, checkinId);
+ assert.equal(data.checkin.type, "checkin");
+ ok(test);
+ } catch (error) {
+ reportError(test, error);
+ }
+ }
+ });
+ };
Tests.Tips.getTip = function() {
var test = "Foursquare.Tips.getTip(4b5e662a70c603bba7d790b4)";

0 comments on commit cacbe58

Please sign in to comment.