/test/update-object-e2e-test.js

https://gitlab.com/pump.io/pump.io · JavaScript · 218 lines · 191 code · 9 blank · 18 comment · 8 complexity · 9e7614f35b2b969b047fbb38bec654fa MD5 · raw file

  1. // update-object-e2e-test.js
  2. //
  3. // Test that updated data is reflected in earlier activities
  4. //
  5. // Copyright 2013, E14N https://e14n.com/
  6. //
  7. // Licensed under the Apache License, Version 2.0 (the "License");
  8. // you may not use this file except in compliance with the License.
  9. // You may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS,
  15. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. // See the License for the specific language governing permissions and
  17. // limitations under the License.
  18. "use strict";
  19. var assert = require("assert"),
  20. vows = require("vows"),
  21. Step = require("step"),
  22. _ = require("lodash"),
  23. http = require("http"),
  24. version = require("../lib/version").version,
  25. urlparse = require("url").parse,
  26. httputil = require("./lib/http"),
  27. oauthutil = require("./lib/oauth"),
  28. apputil = require("./lib/app"),
  29. actutil = require("./lib/activity"),
  30. withAppSetup = apputil.withAppSetup,
  31. register = oauthutil.register,
  32. newClient = oauthutil.newClient,
  33. newPair = oauthutil.newPair,
  34. newCredentials = oauthutil.newCredentials,
  35. validActivityObject = actutil.validActivityObject;
  36. var suite = vows.describe("Update object test");
  37. var makeCred = function(cl, pair) {
  38. return {
  39. consumer_key: cl.client_id,
  40. consumer_secret: cl.client_secret,
  41. token: pair.token,
  42. token_secret: pair.token_secret
  43. };
  44. };
  45. // A batch for testing that updated information is updated
  46. suite.addBatch(
  47. withAppSetup({
  48. "and we get more information about an object": {
  49. topic: function() {
  50. var callback = this.callback,
  51. cl,
  52. pair1,
  53. pair2,
  54. liked1,
  55. liked2;
  56. Step(
  57. function() {
  58. newClient(this);
  59. },
  60. function(err, results) {
  61. if (err) throw err;
  62. cl = results;
  63. newPair(cl, "pault", "dont*get*drunk", this.parallel());
  64. newPair(cl, "ebans", "jazzy*rascal", this.parallel());
  65. },
  66. function(err, results1, results2) {
  67. var act;
  68. if (err) throw err;
  69. pair1 = results1;
  70. pair2 = results2;
  71. act = {
  72. verb: "like",
  73. object: {
  74. id: "urn:uuid:484e5278-8675-11e2-bd8f-70f1a154e1aa",
  75. links: {
  76. self: {
  77. href: "http://somewhereelse.example/note/1"
  78. }
  79. },
  80. objectType: "note"
  81. }
  82. };
  83. httputil.postJSON("http://localhost:4815/api/user/pault/feed",
  84. makeCred(cl, pair1),
  85. act,
  86. this);
  87. },
  88. function(err, results1) {
  89. var act;
  90. if (err) throw err;
  91. liked1 = results1;
  92. act = {
  93. verb: "like",
  94. object: {
  95. id: "urn:uuid:484e5278-8675-11e2-bd8f-70f1a154e1aa",
  96. links: {
  97. self: {
  98. href: "http://somewhereelse.example/note/1"
  99. }
  100. },
  101. objectType: "note",
  102. content: "Hello, world!"
  103. }
  104. };
  105. httputil.postJSON("http://localhost:4815/api/user/ebans/feed",
  106. makeCred(cl, pair2),
  107. act,
  108. this);
  109. },
  110. function(err, results2) {
  111. if (err) throw err;
  112. liked2 = results2;
  113. httputil.getJSON(liked1.links.self.href,
  114. makeCred(cl, pair1),
  115. this);
  116. },
  117. function(err, results1, response) {
  118. callback(err, results1);
  119. }
  120. );
  121. },
  122. "it works": function(err, act) {
  123. assert.ifError(err);
  124. assert.isObject(act);
  125. },
  126. "object has been updated": function(err, act) {
  127. assert.ifError(err);
  128. assert.isObject(act);
  129. assert.isObject(act.object);
  130. assert.equal(act.object.content, "Hello, world!");
  131. }
  132. },
  133. "and we get more information about a locally-created object": {
  134. topic: function() {
  135. var callback = this.callback,
  136. cl,
  137. pair1,
  138. pair2,
  139. posted,
  140. liked;
  141. Step(
  142. function() {
  143. newClient(this);
  144. },
  145. function(err, results) {
  146. if (err) throw err;
  147. cl = results;
  148. newPair(cl, "johnc", "i-heart-dragets", this.parallel());
  149. newPair(cl, "johnl", "jwbooth4life", this.parallel());
  150. },
  151. function(err, results1, results2) {
  152. var act;
  153. if (err) throw err;
  154. pair1 = results1;
  155. pair2 = results2;
  156. act = {
  157. verb: "post",
  158. object: {
  159. objectType: "note",
  160. content: "Hello, world."
  161. }
  162. };
  163. httputil.postJSON("http://localhost:4815/api/user/johnc/feed",
  164. makeCred(cl, pair1),
  165. act,
  166. this);
  167. },
  168. function(err, results1) {
  169. var act;
  170. if (err) throw err;
  171. posted = results1;
  172. act = {
  173. verb: "like",
  174. object: {
  175. id: posted.object.id,
  176. objectType: posted.object.objectType,
  177. content: "Hello, buttheads."
  178. }
  179. };
  180. httputil.postJSON("http://localhost:4815/api/user/johnl/feed",
  181. makeCred(cl, pair2),
  182. act,
  183. this);
  184. },
  185. function(err, results2) {
  186. if (err) throw err;
  187. liked = results2;
  188. httputil.getJSON(posted.object.links.self.href,
  189. makeCred(cl, pair1),
  190. this);
  191. },
  192. function(err, results1, response) {
  193. callback(err, results1);
  194. }
  195. );
  196. },
  197. "it works": function(err, note) {
  198. assert.ifError(err);
  199. assert.isObject(note);
  200. },
  201. "object has not been updated": function(err, note) {
  202. assert.ifError(err);
  203. validActivityObject(note);
  204. assert.equal(note.content, "Hello, world.");
  205. }
  206. }
  207. })
  208. );
  209. suite["export"](module);