user.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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('description', 'description here')
  257. let getRes = await agent.get('/api/v1/user/adminaccount')
  258. getRes.should.be.json
  259. getRes.should.have.property('description', 'description here')
  260. })
  261. it('should update user description if it already exists', async () => {
  262. let putRes = await agent
  263. .put('/api/v1/user/adminaccount')
  264. .set('content-type', 'application/json')
  265. .send({
  266. description: 'new description here'
  267. })
  268. putRes.should.be.json
  269. putRes.body.should.have.property('description', 'new description here')
  270. let getRes = await agent.get('/api/v1/user/adminaccount')
  271. getRes.should.be.json
  272. getRes.should.have.property('description', 'new description here')
  273. })
  274. it('should return an error if username is not logged in', done => {
  275. agent
  276. .put('/api/v1/user/notloggedin')
  277. .set('content-type', 'application/json')
  278. .send({
  279. description: 'new description here'
  280. })
  281. .end((err, res) => {
  282. res.should.be.json
  283. res.should.have.status(400)
  284. res.body.errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
  285. done()
  286. })
  287. })
  288. it('should return an error if description is not a string', done => {
  289. agent
  290. .put('/api/v1/user/adminaccount')
  291. .set('content-type', 'application/json')
  292. .send({
  293. description: 123
  294. })
  295. .end((err, res) => {
  296. res.should.be.json
  297. res.should.have.status(400)
  298. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidParameterType('description', 'string'))
  299. done()
  300. })
  301. })
  302. it('should return an error if description is too long', done => {
  303. let str = []
  304. for(var i = 0; i < 2000; i++) { str.push('') }
  305. agent
  306. .put('/api/v1/user/adminaccount')
  307. .set('content-type', 'application/json')
  308. .send({
  309. description: str.join('')
  310. })
  311. .end((err, res) => {
  312. res.should.be.json
  313. res.should.have.status(400)
  314. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooLarge('description', '1024'))
  315. done()
  316. })
  317. })
  318. it('should update user password', async () => {
  319. let passwordAgent = chai.request.agent(server)
  320. passwordAgent
  321. .post('/api/v1/user/adminaccount/login')
  322. .set('content-type', 'application/json')
  323. .send({
  324. password: 'password'
  325. })
  326. let putRes = await passwordAgent
  327. .put('/api/v1/user/adminaccount')
  328. .set('content-type', 'application/json')
  329. .send({
  330. currentPassowrd: 'password',
  331. newPassword: 'qwertyuiop'
  332. })
  333. putRes.should.be.json
  334. putRes.body.should.have.property('success', 'true')
  335. await passwordAgent.post('/api/v1/user/adminaccount/logout')
  336. let loginRes = await passwordAgent
  337. .post('/api/v1/user/adminaccount/login')
  338. .set('content-type', 'application/json')
  339. .send({
  340. password: 'qwertyuiop'
  341. })
  342. loginRes.should.have.status(200)
  343. loginRes.should.be.json
  344. loginRes.should.have.cookie('username', 'adminaccount')
  345. })
  346. it('should return an error if username is not logged in', done => {
  347. agent
  348. .put('/api/v1/user/notloggedin')
  349. .set('content-type', 'application/json')
  350. .send({
  351. currentPassword: 'qwertyuiop',
  352. newPassword: 'azertyuiop'
  353. })
  354. .end((err, res) => {
  355. res.should.have.status(500)
  356. res.body.errors.should.contain.something.that.deep.equals(Errors.requestNotAuthorized)
  357. done()
  358. })
  359. })
  360. it('should return an error if current password is incorrect', done => {
  361. agent
  362. .put('/api/v1/user/adminaccount')
  363. .set('content-type', 'application/json')
  364. .send({
  365. currentPassword: 'nottheirpassword',
  366. newPassword: 'azertyuiop'
  367. })
  368. .end((err, res) => {
  369. res.should.have.status(401)
  370. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidLoginCredentials)
  371. done()
  372. })
  373. })
  374. it('should return an error if password is the same', done => {
  375. agent
  376. .put('/api/v1/user/adminaccount')
  377. .set('content-type', 'application/json')
  378. .send({
  379. currentPassword: 'qwertyuiop',
  380. newPassword: 'qwertyuiop'
  381. })
  382. .end((err, res) => {
  383. res.should.have.status(400)
  384. res.body.errors.should.contain.something.that.deep.equals(Errors.passwordSame)
  385. done()
  386. })
  387. })
  388. it('should return an error if password is too short', done => {
  389. agent
  390. .put('/api/v1/user/adminaccount')
  391. .set('content-type', 'application/json')
  392. .send({
  393. currentPassword: 'qwertyuiop',
  394. newPassword: 'a'
  395. })
  396. .end((err, res) => {
  397. res.should.have.status(400)
  398. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooSmall('password', '7'))
  399. done()
  400. })
  401. })
  402. it('should return an error if password is too long', done => {
  403. let str = []
  404. for(var i = 0; i < 2000; i++) { str.push('') }
  405. agent
  406. .put('/api/v1/user/adminaccount')
  407. .set('content-type', 'application/json')
  408. .send({
  409. currentPassword: 'qwertyuiop',
  410. newPassword: str.join('')
  411. })
  412. .end((err, res) => {
  413. res.should.have.status(400)
  414. res.body.errors.should.contain.something.that.deep.equals(Errors.parameterLengthTooLarge('password', '1024'))
  415. done()
  416. })
  417. })
  418. it('should return an error if missing currentPassword', done => {
  419. agent
  420. .put('/api/v1/user/adminaccount')
  421. .set('content-type', 'application/json')
  422. .send({
  423. newPassword: 'qwertyujkjnbgfdswazxcvbhytr'
  424. })
  425. .end((err, res) => {
  426. res.should.have.status(400)
  427. res.body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('password'))
  428. done()
  429. })
  430. })
  431. })
  432. describe('/:username GET user', () => {
  433. it('should return the user', async () => {
  434. let res = await chai.request(server)
  435. .get('/api/v1/user/username')
  436. res.should.have.status(200)
  437. res.should.be.json
  438. res.body.should.have.property('username', 'username')
  439. res.body.should.have.property('color')
  440. res.body.should.not.have.property('hash')
  441. })
  442. it('should return an error if username invalid', async () => {
  443. try {
  444. let res = await chai.request(server)
  445. .get('/api/v1/user/not_a_user')
  446. res.should.have.status(400)
  447. res.body.errors.should.contain.something.that.deep.equals(Errors.accountDoesNotExist)
  448. } catch(res) {
  449. let body = JSON.parse(res.response.text)
  450. res.should.have.status(400)
  451. body.errors.should.contain.something.that.deep.equals(Errors.accountDoesNotExist)
  452. }
  453. })
  454. it('should get posts as well if posts query is appended', async () => {
  455. let agent = chai.request.agent(server)
  456. await agent
  457. .post('/api/v1/user/adminaccount/login')
  458. .set('content-type', 'application/x-www-form-urlencoded')
  459. .send({ password: 'password' })
  460. await agent
  461. .post('/api/v1/category')
  462. .set('content-type', 'application/x-www-form-urlencoded')
  463. .send({ name: 'categorynamehere' })
  464. await agent
  465. .post('/api/v1/thread')
  466. .set('content-type', 'application/x-www-form-urlencoded')
  467. .send({ name: 'a thread name', category: 'categorynamehere' })
  468. await agent
  469. .post('/api/v1/post')
  470. .set('content-type', 'application/json')
  471. .send({ threadId: 1, content: 'content for post' })
  472. await agent
  473. .post('/api/v1/post')
  474. .set('content-type', 'application/json')
  475. .send({ threadId: 1, content: 'content for another post' })
  476. let res = await agent
  477. .get('/api/v1/user/adminaccount?posts=true')
  478. res.should.be.json
  479. res.should.have.status(200)
  480. res.body.should.have.property('username', 'adminaccount')
  481. res.body.should.have.property('Posts')
  482. res.body.Posts.should.have.property('length', 2)
  483. res.body.Posts[0].should.have.deep.property('Thread.id', 1)
  484. res.body.Posts[0].should.have.deep.property('User.username', 'adminaccount')
  485. })
  486. it('should allow pagination', async () => {
  487. let agent = chai.request.agent(server)
  488. await agent
  489. .post('/api/v1/user')
  490. .set('content-type', 'application/x-www-form-urlencoded')
  491. .send({ username: 'paginationaccount', password: 'password' })
  492. for(var i = 0; i < 30; i++) {
  493. let thread = await agent
  494. .post('/api/v1/thread')
  495. .set('content-type', 'application/json')
  496. .send({ category: 'categorynamehere', name: `THREAD ${i}` })
  497. await agent
  498. .post('/api/v1/post')
  499. .set('content-type', 'application/json')
  500. .send({ threadId: thread.body.id, content: `POST ${i}` })
  501. }
  502. let pageOne = await agent.get('/api/v1/user/paginationaccount?posts=true')
  503. let pageTwo = await agent.get(pageOne.body.meta.nextURL)
  504. let pageThree = await agent.get(pageTwo.body.meta.nextURL)
  505. pageOne.body.Posts.should.have.length(10)
  506. pageOne.body.meta.should.have.property('nextPostsCount', 10)
  507. pageOne.body.Posts[0].should.have.property('content', '<p>POST 29</p>\n')
  508. pageTwo.body.Posts.should.have.length(10)
  509. pageTwo.body.meta.should.have.property('nextPostsCount', 10)
  510. pageTwo.body.Posts[0].should.have.property('content', '<p>POST 19</p>\n')
  511. pageThree.body.Posts.should.have.length(10)
  512. pageThree.body.meta.should.have.property('nextPostsCount', 0)
  513. pageThree.body.Posts[0].should.have.property('content', '<p>POST 9</p>\n')
  514. pageThree.body.Posts[9].should.have.property('content', '<p>POST 0</p>\n')
  515. expect(pageThree.body.meta.nextURL).to.be.null
  516. })
  517. it('should get threads as well if threads query is appended', async () => {
  518. let agent = chai.request.agent(server)
  519. await agent
  520. .post('/api/v1/user')
  521. .set('content-type', 'application/x-www-form-urlencoded')
  522. .send({ username: 'threadaccount', password: 'password' })
  523. for(var i = 0; i < 20; i++) {
  524. let thread = await agent
  525. .post('/api/v1/thread')
  526. .set('content-type', 'application/json')
  527. .send({ category: 'categorynamehere', name: 'THREAD ' + i })
  528. await agent
  529. .post('/api/v1/post')
  530. .set('content-type', 'application/json')
  531. .send({ threadId: thread.body.id, content: `POST ${i}` })
  532. }
  533. let pageOne = await agent.get('/api/v1/user/threadaccount?threads=true')
  534. //Add another newer thread
  535. //This should not affect other tests
  536. let thread = await agent
  537. .post('/api/v1/thread')
  538. .set('content-type', 'application/json')
  539. .send({ category: 'categorynamehere', name: 'THREAD 20'})
  540. await agent
  541. .post('/api/v1/post')
  542. .set('content-type', 'application/json')
  543. .send({ threadId: thread.body.id, content: `POST 20` })
  544. let pageTwo = await agent.get(pageOne.body.meta.nextURL)
  545. pageOne.body.Threads.should.have.length(10)
  546. pageOne.body.Threads[0].should.have.property('name', 'THREAD 19')
  547. pageOne.body.meta.should.have.property('nextThreadsCount', 10)
  548. pageTwo.body.Threads.should.have.length(10)
  549. pageTwo.body.Threads[0].should.have.property('name', 'THREAD 9')
  550. pageTwo.body.meta.should.have.property('nextThreadsCount', 0)
  551. expect(pageTwo.body.meta.nextURL).to.be.null
  552. })
  553. })
  554. describe('/:username/login POST user', () => {
  555. let agent = chai.request.agent(server)
  556. it('should throw an error if invalid username is provided', (done) => {
  557. chai.request(server)
  558. .post('/api/v1/user/invalid_username/login')
  559. .set('content-type', 'application/x-www-form-urlencoded')
  560. .send({
  561. password: 'password'
  562. })
  563. .end((err, res) => {
  564. res.should.have.status(401)
  565. res.body.should.have.property('errors')
  566. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidLoginCredentials)
  567. done()
  568. })
  569. })
  570. it('should throw an error if invalid password is provided', (done) => {
  571. chai.request(server)
  572. .post('/api/v1/user/username/login')
  573. .set('content-type', 'application/x-www-form-urlencoded')
  574. .send({
  575. password: 'invalid_password'
  576. })
  577. .end((err, res) => {
  578. res.should.have.status(401)
  579. res.body.should.have.property('errors')
  580. res.body.errors.should.contain.something.that.deep.equals(Errors.invalidLoginCredentials)
  581. res.should.not.have.cookie('username')
  582. done()
  583. })
  584. })
  585. it('should log in the user', (done) => {
  586. agent
  587. .post('/api/v1/user/username/login')
  588. .set('content-type', 'application/x-www-form-urlencoded')
  589. .send({
  590. password: 'password'
  591. })
  592. .end((err, res) => {
  593. res.should.have.status(200)
  594. res.should.be.json
  595. res.should.have.cookie('username', 'username')
  596. if(err) {
  597. done(err)
  598. } else {
  599. done()
  600. }
  601. })
  602. })
  603. })
  604. describe('/:username/logout POST user', () => {
  605. let agent = chai.request.agent(server)
  606. it('should log out the user', (done) => {
  607. agent
  608. .post('/api/v1/user/login')
  609. .set('content-type', 'application/x-www-form-urlencoded')
  610. .send({
  611. username: 'username',
  612. password: 'password'
  613. })
  614. .end((err, res) => {
  615. agent
  616. .post('/api/v1/user/username/logout')
  617. .end((err, res) => {
  618. res.should.have.status(200)
  619. res.should.not.have.cookie('username')
  620. if(err) {
  621. done(err)
  622. } else {
  623. done()
  624. }
  625. })
  626. })
  627. })
  628. })
  629. })