thread_post.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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('Thread and post', () => {
  10. let userAgent
  11. //Wait for app to start before commencing
  12. before((done) => {
  13. if(server.locals.appStarted) createUser()
  14. server.on('appStarted', () => {
  15. createUser()
  16. })
  17. function createUser() {
  18. userAgent = chai.request.agent(server)
  19. userAgent
  20. .post('/api/v1/user')
  21. .set('content-type', 'application/json')
  22. .send({
  23. username: 'username',
  24. password: 'password',
  25. })
  26. .then(() => {
  27. done()
  28. })
  29. .catch(done)
  30. }
  31. })
  32. //Delete all rows in table after
  33. //tests completed
  34. after(() => {
  35. sequelize.sync({ force: true })
  36. })
  37. describe('POST /thread', () => {
  38. it('should create a thread if logged in', async () => {})
  39. it('should return an error if not logged in', async () => {})
  40. it('should return an error if missing parameters', async () => {})
  41. it('should return an error if invalid types', async () => {})
  42. it('should return an error if category does not exist', async () => {})
  43. })
  44. describe('GET /thread/:id', () => {
  45. it('should return the thread and corresponding posts', async () => {})
  46. it('should return an error if :id is invalid', async () => {})
  47. })
  48. describe('POST /post', () => {
  49. it('should create a post if logged in', async () => {})
  50. it('should return an error if not logged in', async () => {})
  51. it('should return an error if missing parameters', async () => {})
  52. it('should return an error if invalid types', async () => {})
  53. it('should return an error if thread id does not exist', async () => {})
  54. it('should be able to reply to a post', async () => {})
  55. it('should return an error if reply id does not exist', async () => {})
  56. it('should return an error if post reply not in same thread', async () => {})
  57. })
  58. describe('GET /post/:id', () => {
  59. it('should return the post', async () => {})
  60. it('should return an error if invalid post id', async () => {})
  61. })
  62. })