浏览代码

Fix test where it was not correctly tested if non-admin user could lock threads (admin privillege)

sbkwgh 8 年之前
父节点
当前提交
b9313f6547
共有 1 个文件被更改,包括 25 次插入0 次删除
  1. 25 0
      test/thread_post.js

+ 25 - 0
test/thread_post.js

@@ -205,6 +205,7 @@ describe('Thread and post', () => {
 
 	describe('PUT /thread', () => {
 		let threadId
+		let normalUserAgent = chai.request.agent(server)
 
 		before(done => {
 			userAgent
@@ -217,6 +218,15 @@ describe('Thread and post', () => {
 				.then(res => {
 					threadId = res.body.id
 
+					return normalUserAgent
+						.post('/api/v1/user')
+						.set('content-type', 'application/json')
+						.send({
+							username: 'normaluseragent',
+							password: 'password'
+						})
+				})
+				.then(_ => {
 					done()
 				})
 				.catch(done)
@@ -285,6 +295,21 @@ describe('Thread and post', () => {
 					done()
 				})
 		})
+		it('should return an error if not an administrator', done => {
+			normalUserAgent
+				.put('/api/v1/thread/' + threadId)
+				.set('content-type', 'application/json')
+				.send({
+					locked: false
+				})
+				.end((err, res) => {
+					res.should.be.json
+					res.should.have.status(401)
+					res.body.errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
+
+					done()
+				})
+		})
 		it('should not allow new posts if locked', done => {
 			userAgent
 				.put('/api/v1/thread/' + threadId)