thread_post.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. process.env.NODE_ENV = 'test'
  2. let chai = require('chai')
  3. let server = require('../server')
  4. let should = chai.should()
  5. let expect = chai.expect
  6. let { sequelize } = require('../models')
  7. const Errors = require('../lib/errors.js')
  8. let PAGINATION_THREAD_ID
  9. chai.use(require('chai-http'))
  10. chai.use(require('chai-things'))
  11. describe('Thread and post', () => {
  12. let userAgent, replyAgent
  13. //Wait for app to start before commencing
  14. before((done) => {
  15. if(server.locals.appStarted) mockData()
  16. server.on('appStarted', () => {
  17. mockData()
  18. })
  19. function mockData() {
  20. userAgent = chai.request.agent(server)
  21. replyAgent = chai.request.agent(server)
  22. userAgent
  23. .post('/api/v1/user')
  24. .set('content-type', 'application/json')
  25. .send({
  26. username: 'username',
  27. password: 'password',
  28. admin: true
  29. })
  30. .then(() => {
  31. userAgent
  32. .post('/api/v1/category')
  33. .set('content-type', 'application/json')
  34. .send({ name: 'category_name' })
  35. .then(() => {
  36. return userAgent
  37. .post('/api/v1/category')
  38. .set('content-type', 'application/json')
  39. .send({ name: 'category with spaces' })
  40. })
  41. .then(() => { done() })
  42. .catch(done)
  43. })
  44. .catch(done)
  45. }
  46. })
  47. //Delete all rows in table after
  48. //tess completed
  49. after(() => {
  50. sequelize.sync({ force: true })
  51. })
  52. describe('POST /thread', () => {
  53. it('should create a thread if logged in', async () => {
  54. let res = await userAgent
  55. .post('/api/v1/thread')
  56. .set('content-type', 'application/json')
  57. .send({
  58. name: 'thread',
  59. category: 'CATEGORY_NAME'
  60. })
  61. res.should.have.status(200)
  62. res.should.be.json
  63. res.body.should.have.property('name', 'thread')
  64. res.body.should.have.property('postsCount', 0)
  65. res.body.should.have.property('slug', 'thread')
  66. res.body.should.have.deep.property('User.username', 'username')
  67. res.body.should.have.deep.property('Category.name', 'category_name')
  68. })
  69. it('should create a thread for a category with spaces in', async () => {
  70. let res = await userAgent
  71. .post('/api/v1/thread')
  72. .set('content-type', 'application/json')
  73. .send({
  74. name: 'thread123',
  75. category: 'CATEGORY_WITH_SPACES'
  76. })
  77. res.should.have.status(200)
  78. res.should.be.json
  79. res.body.should.have.property('name', 'thread123')
  80. res.body.should.have.property('postsCount', 0)
  81. res.body.should.have.property('slug', 'thread123')
  82. res.body.should.have.deep.property('User.username', 'username')
  83. res.body.should.have.deep.property('Category.name', 'category with spaces')
  84. })
  85. it('should add a slug from the thread name', async () => {
  86. let res = await userAgent
  87. .post('/api/v1/thread')
  88. .set('content-type', 'application/json')
  89. .send({
  90. name: ' à long thrËad, with lØts of àccents!!! ',
  91. category: 'CATEGORY_NAME'
  92. })
  93. res.should.have.status(200)
  94. res.should.be.json
  95. res.body.should.have.property('name', ' à long thrËad, with lØts of àccents!!! ')
  96. res.body.should.have.property('slug', 'a-long-thread-with-lots-of-accents')
  97. res.body.should.have.deep.property('User.username', 'username')
  98. res.body.should.have.deep.property('Category.name', 'category_name')
  99. })
  100. it('should return an error if not logged in', async () => {
  101. try {
  102. let res = await chai.request(server)
  103. .post('/api/v1/thread')
  104. .set('content-type', 'application/json')
  105. .send({
  106. name: 'thread',
  107. category: 'CATEGORY_NAME'
  108. })
  109. res.should.be.json
  110. res.should.have.status(401)
  111. res.body.errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
  112. } catch (res) {
  113. res.should.have.status(401)
  114. JSON.parse(res.response.text).errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
  115. }
  116. })
  117. it('should return an error if missing parameters', async () => {
  118. try {
  119. let res = await userAgent
  120. .post('/api/v1/thread')
  121. res.should.be.json
  122. res.should.have.status(400)
  123. res.body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('name'))
  124. res.body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('category'))
  125. } catch (res) {
  126. let body = JSON.parse(res.response.text)
  127. res.should.have.status(400)
  128. body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('name'))
  129. body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('category'))
  130. }
  131. })
  132. it('should return an error if name has no length', done => {
  133. userAgent
  134. .post('/api/v1/thread')
  135. .set('content-type', 'application/json')
  136. .send({
  137. name: '',
  138. category: 'CATEGORY_NAME'
  139. })
  140. .end((err, res) => {
  141. res.should.be.json
  142. res.should.have.status(400)
  143. res.body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('name'))
  144. done()
  145. })
  146. })
  147. it('should return an error if invalid types', async () => {
  148. try {
  149. let res = await userAgent
  150. .post('/api/v1/thread')
  151. .set('content-type', 'application/json')
  152. .send({
  153. name: 123,
  154. category: 123
  155. })
  156. res.should.be.json
  157. res.should.have.status(400)
  158. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('name', 'string'))
  159. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('category', 'string'))
  160. } catch (res) {
  161. let body = JSON.parse(res.response.text)
  162. res.should.have.status(400)
  163. body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('name', 'string'))
  164. body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('category', 'string'))
  165. }
  166. })
  167. it('should return an error if category does not exist', async () => {
  168. try {
  169. let res = await userAgent
  170. .post('/api/v1/thread')
  171. .set('content-type', 'application/json')
  172. .send({
  173. name: 'thread1',
  174. category: 'non-existent'
  175. })
  176. res.should.be.json
  177. res.should.have.status(400)
  178. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidCategory)
  179. } catch (res) {
  180. res.should.have.status(400)
  181. JSON.parse(res.response.text).errors.should.contain.something.that.deep.equals(Errors.invalidCategory)
  182. }
  183. })
  184. })
  185. describe('PUT /thread', () => {
  186. it('should lock the thread', async () => {
  187. let res = await userAgent
  188. .put('/api/v1/thread/1')
  189. .set('content-type', 'application/json')
  190. .send({
  191. locked: true
  192. })
  193. res.should.be.json
  194. res.should.have.status(200)
  195. res.body.should.have.property('success', true)
  196. let thread = await userAgent.get('/api/v1/thread/1')
  197. thread.body.should.have.status('locked', true)
  198. })
  199. it('should unlock the thread', async () => {
  200. let res = await userAgent
  201. .put('/api/v1/thread/1')
  202. .set('content-type', 'application/json')
  203. .send({
  204. locked: false
  205. })
  206. res.should.be.json
  207. res.should.have.status(200)
  208. res.body.should.have.property('success', true)
  209. let thread = await userAgent.get('/api/v1/thread/1')
  210. thread.body.should.have.status('locked', false)
  211. })
  212. it('should return an error if thread does not exist', done => {
  213. chai.request(server)
  214. .put('/api/v1/thread/not_a_thread')
  215. .set('content-type', 'application/json')
  216. .send({
  217. locked: false
  218. })
  219. .end((err, res) => {
  220. res.should.be.json
  221. res.should.have.status(400)
  222. res.body.errors.should.include.something.that.deep.equals(Errors.invalidParameter('threadId', 'thread does not exist'))
  223. done()
  224. })
  225. })
  226. it('should return an error if not logged in', done => {
  227. chai.request(server)
  228. .put('/api/v1/thread/1')
  229. .set('content-type', 'application/json')
  230. .send({
  231. locked: false
  232. })
  233. .end((err, res) => {
  234. res.should.be.json
  235. res.should.have.status(401)
  236. res.body.errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
  237. done()
  238. })
  239. })
  240. it('should not allow new posts if locked', done => {
  241. userAgent
  242. .post('/api/v1/post')
  243. .set('content-type', 'application/json')
  244. .send({
  245. content: 'new post',
  246. threadId: 1
  247. })
  248. .end((err, res) => {
  249. res.should.be.json
  250. res.should.have.status(401)
  251. res.body.errors.should.contain.something.that.deep.equals(Errors.threadLocked)
  252. done()
  253. })
  254. })
  255. })
  256. describe('POST /post', () => {
  257. it('should create a post if logged in', async () => {
  258. let res = await userAgent
  259. .post('/api/v1/post')
  260. .set('content-type', 'application/json')
  261. .send({
  262. content: 'content',
  263. threadId: 1
  264. })
  265. res.should.be.json
  266. res.should.have.status(200)
  267. res.body.should.have.property('content', '<p>content</p>\n')
  268. res.body.should.have.property('postNumber', 0)
  269. res.body.should.have.deep.property('User.username', 'username')
  270. res.body.should.have.deep.property('Thread.name', 'thread')
  271. res.body.should.have.deep.property('Thread.postsCount', 1)
  272. })
  273. it('should return an error if not logged in', async () => {
  274. try {
  275. let res = await chai.request(server)
  276. .post('/api/v1/post')
  277. .set('content-type', 'application/json')
  278. .send({
  279. content: 'content',
  280. threadId: 1
  281. })
  282. res.should.be.json
  283. res.should.have.status(401)
  284. res.body.errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
  285. } catch (res) {
  286. res.should.have.status(401)
  287. JSON.parse(res.response.text).errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
  288. }
  289. })
  290. it('should return an error if missing parameters', async () => {
  291. try {
  292. let res = await userAgent
  293. .post('/api/v1/post')
  294. res.should.be.json
  295. res.should.have.status(400)
  296. res.body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('content'))
  297. res.body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('threadId'))
  298. } catch (res) {
  299. let body = JSON.parse(res.response.text)
  300. res.should.have.status(400)
  301. body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('content'))
  302. body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('threadId'))
  303. }
  304. })
  305. it('should return an error if invalid types', async () => {
  306. try {
  307. let res = await userAgent
  308. .post('/api/v1/post')
  309. .set('content-type', 'application/json')
  310. .send({
  311. content: 123,
  312. threadId: 'string',
  313. replyingToId: 'string'
  314. })
  315. res.should.be.json
  316. res.should.have.status(400)
  317. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('content', 'string'))
  318. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('threadId', 'integer'))
  319. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('replyingToId', 'integer'))
  320. } catch (res) {
  321. let body = JSON.parse(res.response.text)
  322. res.should.have.status(400)
  323. body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('content', 'string'))
  324. body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('threadId', 'integer'))
  325. body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('replyingToId', 'integer'))
  326. }
  327. })
  328. it('should return an error if thread id does not exist', async () => {
  329. try {
  330. let res = await userAgent
  331. .post('/api/v1/post')
  332. .set('content-type', 'application/json')
  333. .send({
  334. content: 'content',
  335. threadId: 10
  336. })
  337. res.should.be.json
  338. res.should.have.status(400)
  339. res.body.errors.should.include.something.that.deep.equals(Errors.invalidParameter('threadId', 'thread does not exist'))
  340. } catch (res) {
  341. let body = JSON.parse(res.response.text)
  342. res.should.have.status(400)
  343. body.errors.should.include.something.that.deep.equals(Errors.invalidParameter('threadId', 'thread does not exist'))
  344. }
  345. })
  346. it('should be able to reply to a post', async () => {
  347. await replyAgent
  348. .post('/api/v1/user')
  349. .set('content-type', 'application/json')
  350. .send({
  351. username: 'username1',
  352. password: 'password'
  353. })
  354. let res = await replyAgent
  355. .post('/api/v1/post')
  356. .set('content-type', 'application/json')
  357. .send({
  358. content: 'another post',
  359. threadId: 1,
  360. replyingToId: 1
  361. })
  362. res.should.be.json
  363. res.should.have.status(200)
  364. res.body.should.have.property('postNumber', 1)
  365. res.body.should.have.property('content', '<p>another post</p>\n')
  366. res.body.should.have.deep.property('User.username', 'username1')
  367. res.body.should.have.deep.property('Thread.name', 'thread')
  368. res.body.should.have.deep.property('Thread.postsCount', 2)
  369. res.body.should.have.property('replyingToUsername', 'username')
  370. res.body.should.have.property('Replies').that.deep.equals([])
  371. })
  372. it('should return any replies to a post', async () => {
  373. let res = await replyAgent.get('/api/v1/post/1')
  374. res.should.be.json
  375. res.should.have.status(200)
  376. res.body.should.have.deep.property('replyingToUsername', null)
  377. res.body.should.have.deep.property('Replies.0.content', '<p>another post</p>\n')
  378. })
  379. it('should return an error if reply id does not exist', async () => {
  380. try {
  381. let res = await replyAgent
  382. .post('/api/v1/post')
  383. .set('content-type', 'application/json')
  384. .send({
  385. content: 'yet another post',
  386. threadId: 1,
  387. replyingToId: 10
  388. })
  389. res.should.have.status(400)
  390. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('replyingToId', 'post does not exist'))
  391. } catch (res) {
  392. let body = JSON.parse(res.response.text)
  393. res.should.have.status(400)
  394. body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('replyingToId', 'post does not exist'))
  395. }
  396. })
  397. it('should return an error if post reply not in same thread', async () => {
  398. try {
  399. let threadId = (await replyAgent
  400. .post('/api/v1/thread')
  401. .set('content-type', 'application/json')
  402. .send({
  403. name: 'another thread',
  404. category: 'CATEGORY_NAME'
  405. })).body.id
  406. let res = await replyAgent
  407. .post('/api/v1/post')
  408. .set('content-type', 'application/json')
  409. .send({
  410. content: 'yet another post',
  411. threadId: threadId,
  412. replyingToId: 1
  413. })
  414. res.should.have.status(400)
  415. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('replyingToId', 'replies must be in same thread'))
  416. } catch (res) {
  417. let body = JSON.parse(res.response.text)
  418. res.should.have.status(400)
  419. body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('replyingToId', 'replies must be in same thread'))
  420. }
  421. })
  422. })
  423. describe('GET /thread/:id', () => {
  424. it('should return the thread and corresponding posts', async () => {
  425. let res = await chai.request(server).get('/api/v1/thread/1')
  426. res.should.have.status(200)
  427. res.should.be.json
  428. res.body.should.have.property('name', 'thread')
  429. res.body.should.have.deep.property('Category.name', 'category_name')
  430. res.body.should.have.deep.property('User.username', 'username')
  431. res.body.should.have.property('Posts')
  432. res.body.Posts.should.have.property('length', 2)
  433. res.body.Posts.should.contain.something.that.has.property('content', '<p>content</p>\n')
  434. res.body.Posts.should.contain.something.that.has.deep.property('User.username', 'username')
  435. res.body.Posts.should.contain.something.that.has.property('content', '<p>another post</p>\n')
  436. res.body.Posts.should.contain.something.that.has.deep.property('User.username', 'username1')
  437. })
  438. it('should allow pagination', async () => {
  439. let thread = await userAgent
  440. .post('/api/v1/thread')
  441. .set('content-type', 'application/json')
  442. .send({ category: 'CATEGORY_NAME', name: 'pagination' })
  443. let threadOther = await userAgent
  444. .post('/api/v1/thread')
  445. .set('content-type', 'application/json')
  446. .send({ category: 'CATEGORY_NAME', name: 'pagination_other' })
  447. PAGINATION_THREAD_ID = thread.body.id
  448. for(var i = 0; i < 30; i++) {
  449. let post = await userAgent
  450. .post('/api/v1/post')
  451. .set('content-type', 'application/json')
  452. .send({ threadId: thread.body.id, content: `POST ${i}` })
  453. if(i === 3) {
  454. await userAgent
  455. .post('/api/v1/post')
  456. .set('content-type', 'application/json')
  457. .send({ threadId: threadOther.body.id, content: `POST OTHER ${i}` })
  458. }
  459. }
  460. let pageOne = await userAgent.get('/api/v1/thread/' + thread.body.id)
  461. let pageTwo = await userAgent.get(pageOne.body.meta.nextURL)
  462. let pageThree = await userAgent.get(pageTwo.body.meta.nextURL)
  463. let pageInvalid = await userAgent.get('/api/v1/thread/' + thread.body.id + '?from=' + 100)
  464. pageOne.body.Posts.should.have.length(10)
  465. pageOne.body.meta.should.have.property('postsRemaining', 20)
  466. pageOne.body.meta.should.have.property('previousPostsCount', 0)
  467. pageOne.body.meta.should.have.property('nextPostsCount', 10)
  468. pageOne.body.Posts[0].should.have.property('content', '<p>POST 0</p>\n')
  469. pageTwo.body.Posts.should.have.length(10)
  470. pageTwo.body.meta.should.have.property('postsRemaining', 10)
  471. pageTwo.body.meta.should.have.property('previousPostsCount', 10)
  472. pageTwo.body.meta.should.have.property('nextPostsCount', 10)
  473. pageTwo.body.Posts[0].should.have.property('content', '<p>POST 10</p>\n')
  474. pageTwo.body.meta.should.have.property('previousURL')
  475. pageThree.body.Posts.should.have.length(10)
  476. pageThree.body.meta.should.have.property('postsRemaining', 0)
  477. pageThree.body.meta.should.have.property('previousPostsCount', 10)
  478. pageThree.body.meta.should.have.property('nextPostsCount', 0)
  479. pageThree.body.Posts[0].should.have.property('content', '<p>POST 20</p>\n')
  480. pageThree.body.Posts[9].should.have.property('content', '<p>POST 29</p>\n')
  481. expect(pageThree.body.meta.nextURL).to.be.null
  482. pageInvalid.body.Posts.should.have.length(0)
  483. })
  484. it('should allow you to get an individual and surrounding posts', async () => {
  485. let http = chai.request(server)
  486. let pageOne = await http.get(`/api/v1/thread/${PAGINATION_THREAD_ID}?postNumber=15`)
  487. let pageZero = await http.get(pageOne.body.meta.previousURL)
  488. let pageTwo = await http.get(pageOne.body.meta.nextURL)
  489. pageOne.body.Posts.should.have.length(10)
  490. pageOne.body.Posts[0].should.have.property('content', '<p>POST 11</p>\n')
  491. pageOne.body.Posts[4].should.have.property('content', '<p>POST 15</p>\n')
  492. pageOne.body.Posts[9].should.have.property('content', '<p>POST 20</p>\n')
  493. pageOne.body.meta.should.have.property('postsRemaining', 9)
  494. pageOne.body.meta.should.have.property('previousPostsCount', 10)
  495. pageOne.body.meta.should.have.property('nextPostsCount', 9)
  496. pageTwo.body.Posts.should.have.length(9)
  497. pageTwo.body.Posts[0].should.have.property('content', '<p>POST 21</p>\n')
  498. pageTwo.body.Posts[8].should.have.property('content', '<p>POST 29</p>\n')
  499. pageTwo.body.meta.should.have.property('nextURL', null)
  500. pageTwo.body.meta.should.have.property('postsRemaining', 0)
  501. pageTwo.body.meta.should.have.property('previousPostsCount', 10)
  502. pageTwo.body.meta.should.have.property('nextPostsCount', 0)
  503. pageZero.body.Posts.should.have.length(10)
  504. pageZero.body.Posts[0].should.have.property('content', '<p>POST 1</p>\n')
  505. pageZero.body.Posts[9].should.have.property('content', '<p>POST 10</p>\n')
  506. pageZero.body.meta.should.have.property('postsRemaining', 19)
  507. pageZero.body.meta.should.have.property('previousPostsCount', 1)
  508. pageZero.body.meta.should.have.property('nextPostsCount', 10)
  509. let pageFirst = await http.get(pageZero.body.meta.previousURL)
  510. pageFirst.body.Posts[0].should.have.property('content', '<p>POST 0</p>\n')
  511. pageFirst.body.meta.should.have.property('previousURL', null)
  512. pageFirst.body.meta.should.have.property('postsRemaining', 29)
  513. pageFirst.body.meta.should.have.property('previousPostsCount', 0)
  514. })
  515. it('should return an error if :id is invalid', async () => {
  516. try {
  517. let res = await chai.request(server).get('/api/v1/thread/invalid')
  518. res.should.have.status(400)
  519. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('id', 'thread does not exist'))
  520. } catch (res) {
  521. let body = JSON.parse(res.response.text)
  522. res.should.have.status(400)
  523. body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('id', 'thread does not exist'))
  524. }
  525. })
  526. })
  527. describe('GET /post/:id', () => {
  528. it('should return the post', async () => {
  529. let res = await chai.request(server).get('/api/v1/post/1')
  530. res.should.have.status(200)
  531. res.should.be.json
  532. res.body.should.have.property('content', '<p>content</p>\n')
  533. res.body.should.have.deep.property('User.username', 'username')
  534. res.body.should.have.deep.property('Thread.name', 'thread')
  535. res.body.should.have.deep.property('Thread.Category.name', 'category_name')
  536. res.body.should.have.deep.property('Replies.0.User.username', 'username1')
  537. })
  538. it('should return an error if invalid post id', async () => {
  539. try {
  540. let res = await chai.request(server).get('/api/v1/post/invalid')
  541. res.should.have.status(400)
  542. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('id', 'post does not exist'))
  543. } catch (res) {
  544. let body = JSON.parse(res.response.text)
  545. res.should.have.status(400)
  546. body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('id', 'post does not exist'))
  547. }
  548. })
  549. })
  550. })