user.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. process.env.NODE_ENV = 'test'
  2. process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
  3. let chai = require('chai')
  4. let server = require('../server')
  5. let should = chai.should()
  6. let expect = chai.expect
  7. let { sequelize } = require('../models')
  8. const Errors = require('../lib/errors.js')
  9. chai.use(require('chai-http'))
  10. chai.use(require('chai-things'))
  11. describe('User', () => {
  12. //Wait for app to start before commencing
  13. before((done) => {
  14. if(server.locals.appStarted) done()
  15. server.on('appStarted', () => {
  16. done()
  17. })
  18. })
  19. //Delete all rows in table after
  20. //tests completed
  21. after(() => sequelize.sync({ force: true }) )
  22. describe('/ POST user', () => {
  23. it('should create an account', (done) => {
  24. chai.request(server)
  25. .post('/api/v1/user')
  26. .set('content-type', 'application/x-www-form-urlencoded')
  27. .send({
  28. username: 'username',
  29. password: 'password'
  30. })
  31. .end((err, res) => {
  32. res.should.have.status(200)
  33. res.should.be.json
  34. res.body.should.have.property('username', 'username')
  35. res.body.should.have.property('hash')
  36. res.body.should.have.property('color')
  37. res.body.color.should.not.be.null
  38. done()
  39. })
  40. })
  41. it('should create an admin account if no is already created', (done) => {
  42. chai.request(server)
  43. .post('/api/v1/user')
  44. .set('content-type', 'application/json')
  45. .send({
  46. username: 'adminaccount',
  47. password: 'password',
  48. admin: true
  49. })
  50. .end((err, res) => {
  51. res.should.have.status(200)
  52. res.body.should.have.property('username', 'adminaccount')
  53. res.body.should.have.property('hash')
  54. res.body.should.have.property('admin', true)
  55. done()
  56. })
  57. })
  58. it('should give an error if an admin account is already created and no token is provided', (done) => {
  59. chai.request(server)
  60. .post('/api/v1/user')
  61. .set('content-type', 'application/json')
  62. .send({
  63. username: 'adminaccount1',
  64. password: 'password',
  65. admin: true
  66. })
  67. .end((err, res) => {
  68. res.should.have.status(400)
  69. res.should.be.json
  70. res.body.should.have.property('errors')
  71. res.body.errors.should.include.something.that.deep.equals(Errors.missingParameter('token'))
  72. done()
  73. })
  74. })
  75. it('should give an error if admin and token fields are not of the correct type ', (done) => {
  76. chai.request(server)
  77. .post('/api/v1/user')
  78. .set('content-type', 'application/json')
  79. .send({
  80. username: 'adminaccount1',
  81. password: 'password',
  82. admin: 'not a boolean',
  83. token: 123
  84. })
  85. .end((err, res) => {
  86. res.should.have.status(400)
  87. res.should.be.json
  88. res.body.should.have.property('errors')
  89. res.body.errors.should.include.something.that.deep.equals(Errors.invalidParameterType('admin', 'boolean'))
  90. res.body.errors.should.include.something.that.deep.equals(Errors.invalidParameterType('token', 'string'))
  91. done()
  92. })
  93. })
  94. it('should give an error if an admin account is already created and token is invalid', (done) => {
  95. chai.request(server)
  96. .post('/api/v1/user')
  97. .set('content-type', 'application/json')
  98. .send({
  99. username: 'adminaccount1',
  100. password: 'password',
  101. admin: true,
  102. token: 'invalid_token'
  103. })
  104. .end((err, res) => {
  105. res.should.have.status(401)
  106. res.should.be.json
  107. res.body.should.have.property('errors')
  108. res.body.errors.should.include.something.that.deep.equals(Errors.invalidToken)
  109. done()
  110. })
  111. })
  112. it('should create an admin account provided with a token', async () => {
  113. let agent = chai.request.agent(server)
  114. await agent
  115. .post('/api/v1/user/adminaccount/login')
  116. .set('content-type', 'application/json')
  117. .send({
  118. password: 'password'
  119. })
  120. let tokenRes = await agent.post('/api/v1/admin_token')
  121. let token = tokenRes.body.token
  122. let accountRes = await chai.request(server)
  123. .post('/api/v1/user')
  124. .set('content-type', 'application/json')
  125. .send({
  126. username: 'adminaccount1',
  127. password: 'password',
  128. admin: true,
  129. token: token
  130. })
  131. accountRes.should.have.status(200)
  132. accountRes.should.be.json
  133. accountRes.body.should.have.property('admin', true)
  134. accountRes.body.should.have.property('username', 'adminaccount1')
  135. accountRes.body.should.have.property('hash')
  136. try {
  137. let invalidAccountRes = await chai.request(server)
  138. .post('/api/v1/user')
  139. .set('content-type', 'application/json')
  140. .send({
  141. username: 'adminaccount2',
  142. password: 'password',
  143. admin: true,
  144. token: token
  145. })
  146. invalidAccountRes.should.have.status(401)
  147. invalidAccountRes.should.be.json
  148. invalidAccountRes.body.should.have.property('errors')
  149. invalidAccountRes.body.errors.should.include.something.that.deep.equals(Errors.invalidToken)
  150. } catch (res) {
  151. res.should.have.status(401)
  152. JSON.parse(res.response.text).errors.should.include.something.that.deep.equals(Errors.invalidToken)
  153. }
  154. })
  155. it('should throw an error if account already created', (done) => {
  156. chai.request(server)
  157. .post('/api/v1/user')
  158. .set('content-type', 'application/x-www-form-urlencoded')
  159. .send({
  160. username: 'username',
  161. password: 'password'
  162. })
  163. .end((err, res) => {
  164. res.should.have.status(400)
  165. res.should.be.json
  166. res.body.should.have.property('errors')
  167. res.body.errors.should.include.something.that.deep.equals(Errors.accountAlreadyCreated)
  168. done()
  169. })
  170. })
  171. it('should throw an error if no username or password', (done) => {
  172. chai.request(server)
  173. .post('/api/v1/user')
  174. .set('content-type', 'application/x-www-form-urlencoded')
  175. .send({})
  176. .end((err, res) => {
  177. res.should.have.status(400)
  178. res.should.be.json
  179. res.body.should.have.property('errors')
  180. res.body.errors.should.include.something.that.deep.equals(Errors.missingParameter('username'))
  181. res.body.errors.should.include.something.that.deep.equals(Errors.missingParameter('password'))
  182. done()
  183. })
  184. })
  185. it('should throw an error if username or password are not a string', (done) => {
  186. chai.request(server)
  187. .post('/api/v1/user')
  188. .set('content-type', 'application/json')
  189. .send({
  190. username: 123,
  191. password: 123
  192. })
  193. .end((err, res) => {
  194. res.should.have.status(400)
  195. res.should.be.json
  196. res.body.should.have.property('errors')
  197. res.body.should.have.property('errors')
  198. res.body.errors.should.include.something.that.deep.equals(Errors.invalidParameterType('username', 'string'))
  199. res.body.errors.should.include.something.that.deep.equals(Errors.invalidParameterType('password', 'string'))
  200. done()
  201. })
  202. })
  203. it('should throw an error if username or password less than 6 characters', (done) => {
  204. chai.request(server)
  205. .post('/api/v1/user')
  206. .set('content-type', 'application/x-www-form-urlencoded')
  207. .send({
  208. username: 'test',
  209. password: 'pass'
  210. })
  211. .end((err, res) => {
  212. res.should.have.status(400)
  213. res.should.be.json
  214. res.body.should.have.property('errors')
  215. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooSmall('username', '6'))
  216. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooSmall('password', '6'))
  217. done()
  218. })
  219. })
  220. it('should throw an error if username greater than 50 characters or password is greater than 100 characters', (done) => {
  221. chai.request(server)
  222. .post('/api/v1/user')
  223. .set('content-type', 'application/x-www-form-urlencoded')
  224. .send({
  225. username: '123456789012345678901234567890123456789012345678901',
  226. password: '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901'
  227. })
  228. .end((err, res) => {
  229. res.should.have.status(400)
  230. res.should.be.json
  231. res.body.should.have.property('errors')
  232. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooLarge('username', '50'))
  233. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooLarge('password', '100'))
  234. done()
  235. })
  236. })
  237. })
  238. describe('/:username PUT user', () => {
  239. let agent = chai.request.agent(server)
  240. before(async () => {
  241. await agent
  242. .post('/api/v1/user/adminaccount/login')
  243. .set('content-type', 'application/json')
  244. .send({
  245. password: 'password'
  246. })
  247. })
  248. it('should add user description if it doesn\'t already exist', async () => {
  249. let putRes = await agent
  250. .put('/api/v1/user/adminaccount')
  251. .set('content-type', 'application/json')
  252. .send({
  253. description: 'description here'
  254. })
  255. putRes.should.be.json
  256. putRes.body.should.have.property('success', true)
  257. let getRes = await agent.get('/api/v1/user/adminaccount')
  258. getRes.should.be.json
  259. getRes.body.should.have.property('description', 'description here')
  260. getRes.body.should.have.property('username', 'adminaccount')
  261. getRes.body.should.have.property('color')
  262. })
  263. it('should update user description if it already exists', async () => {
  264. let putRes = await agent
  265. .put('/api/v1/user/adminaccount')
  266. .set('content-type', 'application/json')
  267. .send({
  268. description: 'new description here'
  269. })
  270. putRes.should.be.json
  271. putRes.body.should.have.property('success', true)
  272. let getRes = await agent.get('/api/v1/user/adminaccount')
  273. getRes.should.be.json
  274. getRes.body.should.have.property('description', 'new description here')
  275. })
  276. it('should return an error if username is not logged in', done => {
  277. agent
  278. .put('/api/v1/user/notloggedin')
  279. .set('content-type', 'application/json')
  280. .send({
  281. description: 'new description here'
  282. })
  283. .end((err, res) => {
  284. res.should.be.json
  285. res.should.have.status(400)
  286. res.body.errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
  287. done()
  288. })
  289. })
  290. it('should return an error if description is not a string', done => {
  291. agent
  292. .put('/api/v1/user/adminaccount')
  293. .set('content-type', 'application/json')
  294. .send({
  295. description: 123
  296. })
  297. .end((err, res) => {
  298. res.should.be.json
  299. res.should.have.status(400)
  300. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('description', 'string'))
  301. done()
  302. })
  303. })
  304. it('should return an error if description is too long', done => {
  305. let str = []
  306. for(var i = 0; i < 1025; i++) { str.push('a') }
  307. agent
  308. .put('/api/v1/user/adminaccount')
  309. .set('content-type', 'application/json')
  310. .send({
  311. description: str.join('')
  312. })
  313. .end((err, res) => {
  314. res.should.be.json
  315. res.should.have.status(400)
  316. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooLarge('description', '1024'))
  317. done()
  318. })
  319. })
  320. it('should update user password', async () => {
  321. let passwordAgent = chai.request.agent(server)
  322. passwordAgent
  323. .post('/api/v1/user/adminaccount/login')
  324. .set('content-type', 'application/json')
  325. .send({
  326. password: 'password'
  327. })
  328. let putRes = await passwordAgent
  329. .put('/api/v1/user/adminaccount')
  330. .set('content-type', 'application/json')
  331. .send({
  332. currentPassowrd: 'password',
  333. newPassword: 'qwertyuiop'
  334. })
  335. putRes.should.be.json
  336. putRes.body.should.have.property('success', 'true')
  337. await passwordAgent.post('/api/v1/user/adminaccount/logout')
  338. let loginRes = await passwordAgent
  339. .post('/api/v1/user/adminaccount/login')
  340. .set('content-type', 'application/json')
  341. .send({
  342. password: 'qwertyuiop'
  343. })
  344. loginRes.should.have.status(200)
  345. loginRes.should.be.json
  346. loginRes.should.have.cookie('username', 'adminaccount')
  347. })
  348. it('should return an error if username is not logged in', done => {
  349. agent
  350. .put('/api/v1/user/notloggedin')
  351. .set('content-type', 'application/json')
  352. .send({
  353. currentPassword: 'qwertyuiop',
  354. newPassword: 'azertyuiop'
  355. })
  356. .end((err, res) => {
  357. res.should.have.status(500)
  358. res.body.errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
  359. done()
  360. })
  361. })
  362. it('should return an error if current password is incorrect', done => {
  363. agent
  364. .put('/api/v1/user/adminaccount')
  365. .set('content-type', 'application/json')
  366. .send({
  367. currentPassword: 'nottheirpassword',
  368. newPassword: 'azertyuiop'
  369. })
  370. .end((err, res) => {
  371. res.should.have.status(401)
  372. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidLoginCredentials)
  373. done()
  374. })
  375. })
  376. it('should return an error if password is the same', done => {
  377. agent
  378. .put('/api/v1/user/adminaccount')
  379. .set('content-type', 'application/json')
  380. .send({
  381. currentPassword: 'qwertyuiop',
  382. newPassword: 'qwertyuiop'
  383. })
  384. .end((err, res) => {
  385. res.should.have.status(400)
  386. res.body.errors.should.contain.something.that.deep.equals(Errors.passwordSame)
  387. done()
  388. })
  389. })
  390. it('should return an error if password is too short', done => {
  391. agent
  392. .put('/api/v1/user/adminaccount')
  393. .set('content-type', 'application/json')
  394. .send({
  395. currentPassword: 'qwertyuiop',
  396. newPassword: 'a'
  397. })
  398. .end((err, res) => {
  399. res.should.have.status(400)
  400. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooSmall('password', '7'))
  401. done()
  402. })
  403. })
  404. it('should return an error if password is too long', done => {
  405. let str = []
  406. for(var i = 0; i < 2000; i++) { str.push('') }
  407. agent
  408. .put('/api/v1/user/adminaccount')
  409. .set('content-type', 'application/json')
  410. .send({
  411. currentPassword: 'qwertyuiop',
  412. newPassword: str.join('')
  413. })
  414. .end((err, res) => {
  415. res.should.have.status(400)
  416. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooLarge('password', '1024'))
  417. done()
  418. })
  419. })
  420. it('should return an error if missing currentPassword', done => {
  421. agent
  422. .put('/api/v1/user/adminaccount')
  423. .set('content-type', 'application/json')
  424. .send({
  425. newPassword: 'qwertyujkjnbgfdswazxcvbhytr'
  426. })
  427. .end((err, res) => {
  428. res.should.have.status(400)
  429. res.body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('password'))
  430. done()
  431. })
  432. })
  433. })
  434. describe('/:username GET user', () => {
  435. it('should return the user', async () => {
  436. let res = await chai.request(server)
  437. .get('/api/v1/user/username')
  438. res.should.have.status(200)
  439. res.should.be.json
  440. res.body.should.have.property('username', 'username')
  441. res.body.should.have.property('color')
  442. res.body.should.not.have.property('hash')
  443. })
  444. it('should return an error if username invalid', async () => {
  445. try {
  446. let res = await chai.request(server)
  447. .get('/api/v1/user/not_a_user')
  448. res.should.have.status(400)
  449. res.body.errors.should.contain.something.that.deep.equals(Errors.accountDoesNotExist)
  450. } catch(res) {
  451. let body = JSON.parse(res.response.text)
  452. res.should.have.status(400)
  453. body.errors.should.contain.something.that.deep.equals(Errors.accountDoesNotExist)
  454. }
  455. })
  456. it('should get posts as well if posts query is appended', async () => {
  457. let agent = chai.request.agent(server)
  458. await agent
  459. .post('/api/v1/user/adminaccount/login')
  460. .set('content-type', 'application/x-www-form-urlencoded')
  461. .send({ password: 'password' })
  462. await agent
  463. .post('/api/v1/category')
  464. .set('content-type', 'application/x-www-form-urlencoded')
  465. .send({ name: 'categorynamehere' })
  466. await agent
  467. .post('/api/v1/thread')
  468. .set('content-type', 'application/x-www-form-urlencoded')
  469. .send({ name: 'a thread name', category: 'categorynamehere' })
  470. await agent
  471. .post('/api/v1/post')
  472. .set('content-type', 'application/json')
  473. .send({ threadId: 1, content: 'content for post' })
  474. await agent
  475. .post('/api/v1/post')
  476. .set('content-type', 'application/json')
  477. .send({ threadId: 1, content: 'content for another post' })
  478. let res = await agent
  479. .get('/api/v1/user/adminaccount?posts=true')
  480. res.should.be.json
  481. res.should.have.status(200)
  482. res.body.should.have.property('username', 'adminaccount')
  483. res.body.should.have.property('Posts')
  484. res.body.Posts.should.have.property('length', 2)
  485. res.body.Posts[0].should.have.deep.property('Thread.id', 1)
  486. res.body.Posts[0].should.have.deep.property('User.username', 'adminaccount')
  487. })
  488. it('should allow pagination', async () => {
  489. let agent = chai.request.agent(server)
  490. await agent
  491. .post('/api/v1/user')
  492. .set('content-type', 'application/x-www-form-urlencoded')
  493. .send({ username: 'paginationaccount', password: 'password' })
  494. for(var i = 0; i < 30; i++) {
  495. let thread = await agent
  496. .post('/api/v1/thread')
  497. .set('content-type', 'application/json')
  498. .send({ category: 'categorynamehere', name: `THREAD ${i}` })
  499. await agent
  500. .post('/api/v1/post')
  501. .set('content-type', 'application/json')
  502. .send({ threadId: thread.body.id, content: `POST ${i}` })
  503. }
  504. let pageOne = await agent.get('/api/v1/user/paginationaccount?posts=true')
  505. let pageTwo = await agent.get(pageOne.body.meta.nextURL)
  506. let pageThree = await agent.get(pageTwo.body.meta.nextURL)
  507. pageOne.body.Posts.should.have.length(10)
  508. pageOne.body.meta.should.have.property('nextPostsCount', 10)
  509. pageOne.body.Posts[0].should.have.property('content', '<p>POST 29</p>\n')
  510. pageTwo.body.Posts.should.have.length(10)
  511. pageTwo.body.meta.should.have.property('nextPostsCount', 10)
  512. pageTwo.body.Posts[0].should.have.property('content', '<p>POST 19</p>\n')
  513. pageThree.body.Posts.should.have.length(10)
  514. pageThree.body.meta.should.have.property('nextPostsCount', 0)
  515. pageThree.body.Posts[0].should.have.property('content', '<p>POST 9</p>\n')
  516. pageThree.body.Posts[9].should.have.property('content', '<p>POST 0</p>\n')
  517. expect(pageThree.body.meta.nextURL).to.be.null
  518. })
  519. it('should get threads as well if threads query is appended', async () => {
  520. let agent = chai.request.agent(server)
  521. await agent
  522. .post('/api/v1/user')
  523. .set('content-type', 'application/x-www-form-urlencoded')
  524. .send({ username: 'threadaccount', password: 'password' })
  525. for(var i = 0; i < 20; i++) {
  526. let thread = await agent
  527. .post('/api/v1/thread')
  528. .set('content-type', 'application/json')
  529. .send({ category: 'categorynamehere', name: 'THREAD ' + i })
  530. await agent
  531. .post('/api/v1/post')
  532. .set('content-type', 'application/json')
  533. .send({ threadId: thread.body.id, content: `POST ${i}` })
  534. }
  535. let pageOne = await agent.get('/api/v1/user/threadaccount?threads=true')
  536. //Add another newer thread
  537. //This should not affect other tests
  538. let thread = await agent
  539. .post('/api/v1/thread')
  540. .set('content-type', 'application/json')
  541. .send({ category: 'categorynamehere', name: 'THREAD 20'})
  542. await agent
  543. .post('/api/v1/post')
  544. .set('content-type', 'application/json')
  545. .send({ threadId: thread.body.id, content: `POST 20` })
  546. let pageTwo = await agent.get(pageOne.body.meta.nextURL)
  547. pageOne.body.Threads.should.have.length(10)
  548. pageOne.body.Threads[0].should.have.property('name', 'THREAD 19')
  549. pageOne.body.meta.should.have.property('nextThreadsCount', 10)
  550. pageTwo.body.Threads.should.have.length(10)
  551. pageTwo.body.Threads[0].should.have.property('name', 'THREAD 9')
  552. pageTwo.body.meta.should.have.property('nextThreadsCount', 0)
  553. expect(pageTwo.body.meta.nextURL).to.be.null
  554. })
  555. })
  556. describe('/:username/login POST user', () => {
  557. let agent = chai.request.agent(server)
  558. it('should throw an error if invalid username is provided', (done) => {
  559. chai.request(server)
  560. .post('/api/v1/user/invalid_username/login')
  561. .set('content-type', 'application/x-www-form-urlencoded')
  562. .send({
  563. password: 'password'
  564. })
  565. .end((err, res) => {
  566. res.should.have.status(401)
  567. res.body.should.have.property('errors')
  568. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidLoginCredentials)
  569. done()
  570. })
  571. })
  572. it('should throw an error if invalid password is provided', (done) => {
  573. chai.request(server)
  574. .post('/api/v1/user/username/login')
  575. .set('content-type', 'application/x-www-form-urlencoded')
  576. .send({
  577. password: 'invalid_password'
  578. })
  579. .end((err, res) => {
  580. res.should.have.status(401)
  581. res.body.should.have.property('errors')
  582. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidLoginCredentials)
  583. res.should.not.have.cookie('username')
  584. done()
  585. })
  586. })
  587. it('should log in the user', (done) => {
  588. agent
  589. .post('/api/v1/user/username/login')
  590. .set('content-type', 'application/x-www-form-urlencoded')
  591. .send({
  592. password: 'password'
  593. })
  594. .end((err, res) => {
  595. res.should.have.status(200)
  596. res.should.be.json
  597. res.should.have.cookie('username', 'username')
  598. if(err) {
  599. done(err)
  600. } else {
  601. done()
  602. }
  603. })
  604. })
  605. })
  606. describe('/:username/logout POST user', () => {
  607. let agent = chai.request.agent(server)
  608. it('should log out the user', (done) => {
  609. agent
  610. .post('/api/v1/user/login')
  611. .set('content-type', 'application/x-www-form-urlencoded')
  612. .send({
  613. username: 'username',
  614. password: 'password'
  615. })
  616. .end((err, res) => {
  617. agent
  618. .post('/api/v1/user/username/logout')
  619. .end((err, res) => {
  620. res.should.have.status(200)
  621. res.should.not.have.cookie('username')
  622. if(err) {
  623. done(err)
  624. } else {
  625. done()
  626. }
  627. })
  628. })
  629. })
  630. })
  631. })