like.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. process.env.NODE_ENV = 'test'
  2. let chai = require('chai')
  3. let server = require('../server')
  4. let should = chai.should()
  5. let { sequelize } = require('../models')
  6. const Errors = require('../lib/errors.js')
  7. chai.use(require('chai-http'))
  8. chai.use(require('chai-things'))
  9. describe('Like', () => {
  10. let admin = chai.request.agent(server)
  11. let user = chai.request.agent(server)
  12. //Wait for app to start before commencing
  13. before((done) => {
  14. function serverStarted () {
  15. admin
  16. .post('/api/v1/user')
  17. .set('content-type', 'application/json')
  18. .send({
  19. username: 'adminaccount',
  20. password: 'password',
  21. admin: true
  22. })
  23. .then(() => {
  24. return user
  25. .post('/api/v1/user')
  26. .set('content-type', 'application/json')
  27. .send({
  28. username: 'useraccount',
  29. password: 'password',
  30. })
  31. })
  32. .then(() => {
  33. return admin
  34. .post('/api/v1/category')
  35. .set('content-type', 'application/json')
  36. .send({ name: 'category' })
  37. })
  38. .then(() => {
  39. return admin
  40. .post('/api/v1/thread')
  41. .set('content-type', 'application/json')
  42. .send({ category: 'CATEGORY', name: 'thread' })
  43. })
  44. .then(() => {
  45. return admin
  46. .post('/api/v1/post')
  47. .set('content-type', 'application/json')
  48. .send({ threadId: 1, content: 'POST 1' })
  49. })
  50. .then(() => {
  51. return admin
  52. .post('/api/v1/post')
  53. .set('content-type', 'application/json')
  54. .send({ threadId: 1, content: 'POST 2' })
  55. })
  56. .then(() => {
  57. return user
  58. .post('/api/v1/post')
  59. .set('content-type', 'application/json')
  60. .send({ threadId: 1, content: 'POST 3' })
  61. })
  62. .then(done)
  63. .catch(done)
  64. }
  65. if(server.locals.appStarted) serverStarted()
  66. server.on('appStarted', () => {
  67. serverStarted()
  68. })
  69. })
  70. after(() => sequelize.sync({ force: true }))
  71. })