|
@@ -148,4 +148,62 @@ describe('Category', () => {
|
|
|
res.body.should.contain.an.item.with.property('name', 'another_category')
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ describe('GET /category/:category', () => {
|
|
|
+ before(async () => {
|
|
|
+ let agent = chai.request.agent(server)
|
|
|
+
|
|
|
+ await agent
|
|
|
+ .post('/api/v1/user/adminaccount/login')
|
|
|
+ .set('content-type', 'application/json')
|
|
|
+ .send({ password: 'password' })
|
|
|
+
|
|
|
+ await agent
|
|
|
+ .post('/api/v1/thread')
|
|
|
+ .set('content-type', 'application/json')
|
|
|
+ .send({ name: 'thread', category: 'category' })
|
|
|
+
|
|
|
+ await agent
|
|
|
+ .post('/api/v1/thread')
|
|
|
+ .set('content-type', 'application/json')
|
|
|
+ .send({ name: 'another_thread', category: 'category' })
|
|
|
+
|
|
|
+ await agent
|
|
|
+ .post('/api/v1/post')
|
|
|
+ .set('content-type', 'application/json')
|
|
|
+ .send({ content: 'content here', threadId: 1 })
|
|
|
+
|
|
|
+ await agent
|
|
|
+ .post('/api/v1/post')
|
|
|
+ .set('content-type', 'application/json')
|
|
|
+ .send({ content: 'content here', threadId: 2 })
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should return all threads in a category', async () => {
|
|
|
+ let res = await chai.request(server)
|
|
|
+ .get('/api/v1/category/category')
|
|
|
+
|
|
|
+ res.should.be.json
|
|
|
+ res.should.have.status(200)
|
|
|
+ res.body.should.have.property('name', 'category')
|
|
|
+ res.body.Threads.should.have.property('length', 2)
|
|
|
+ res.body.Threads.should.contain.an.item.with.deep.property('User.username', 'adminaccount')
|
|
|
+ res.body.Threads.should.contain.an.item.with.deep.property('Posts.0.content', '<p>content here</p>\n')
|
|
|
+ res.body.Threads.should.contain.an.item.with.deep.property('Posts.0.User.username', 'adminaccount')
|
|
|
+ })
|
|
|
+ it('should return an error if category does not exist', async () => {
|
|
|
+ try {
|
|
|
+ let res = await chai.request(server)
|
|
|
+ .get('/api/v1/category/not_real')
|
|
|
+
|
|
|
+ res.should.be.json
|
|
|
+ res.should.have.status(400)
|
|
|
+ res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('id', 'thread does not exist'))
|
|
|
+ } catch (res) {
|
|
|
+ let body = JSON.parse(res.response.text)
|
|
|
+ res.should.have.status(400)
|
|
|
+ body.errors.should.contain.something.that.deep.equals(Errors.invalidParameter('id', 'thread does not exist'))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|