浏览代码

Create and log in user before test

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

+ 21 - 2
test/thread_post.js

@@ -12,13 +12,32 @@ chai.use(require('chai-http'))
 chai.use(require('chai-things'))
 
 describe('Thread and post', () => {
+	let userAgent
+
 	//Wait for app to start before commencing
 	before((done) => {
-		if(server.locals.appStarted) done()
+		if(server.locals.appStarted) createUser()
 
 		server.on('appStarted', () => {
-			done()
+			createUser()
 		})
+
+		function createUser() {
+			userAgent = chai.request.agent(server)
+
+			userAgent
+				.post('/api/v1/user')
+				.set('content-type', 'application/json')
+				.send({
+					username: 'username',
+					password: 'password',
+				})
+				.then(() => {
+					done()
+				})
+				.catch(done)
+		}
+
 	})
 
 	//Delete all rows in table after