<commit_before>request      = require 'supertest'
assert       = require 'assert'
should       = require 'should'
async        = require 'async'
mongoose     = require 'mongoose'
App          = require '../../app'

fixtures     = require 'pow-mongoose-fixtures'
fixturesData = require '../../fixtures/test.coffee'

User = require '../../model/user'

describe '/profile', ->
  fakeUser = {}
  requestTest = {}

  describe '** Logged in **', ->
    before (done) ->
      async.series [(callback) ->
        fixtures.load fixturesData.testUser, mongoose.connection, callback
      , (callback) ->
        User.findById fixturesData.testUser.User.fakeUser._id, (err, user) ->
          fakeUser = user
          requestTest = request(new App(fakeUser))
          callback()
      ], done

    describe 'GET', ->
      it 'should return 200', (done) ->
        requestTest.get('/profile').expect(200).end (err, res) ->
          should.not.exist err
          done()

    describe 'POST', ->
      it 'should not delete already saved params', (done) ->
        newFirstName = 'Titi'
        requestTest.post('/profile').send(firstName: newFirstName).expect(302).end (err, res) ->
          return done(err) if err
          res.header['location'].should.include('/profile')
          User.findOne firstName: newFirstName, (err, modifiedUser) ->
            should.not.exist(err)
            assert.equal fakeUser.lastName, modifiedUser.lastName
            done()<commit_msg>check cannot access profile when logged out<commit_after>request      = require 'supertest'
assert       = require 'assert'
should       = require 'should'
async        = require 'async'
mongoose     = require 'mongoose'
App          = require '../../app'

fixtures     = require 'pow-mongoose-fixtures'
fixturesData = require '../../fixtures/test.coffee'

User = require '../../model/user'

describe '/profile', ->
  fakeUser = {}
  requestTest = {}

  describe '** Logged in **', ->
    before (done) ->
      async.series [(callback) ->
        fixtures.load fixturesData.testUser, mongoose.connection, callback
      , (callback) ->
        User.findById fixturesData.testUser.User.fakeUser._id, (err, user) ->
          fakeUser = user
          requestTest = request(new App(fakeUser))
          callback()
      ], done

    describe 'GET', ->
      it 'should return 200', (done) ->
        requestTest.get('/profile').expect(200).end (err, res) ->
          should.not.exist err
          done()

    describe 'POST', ->
      it 'should not delete already saved params', (done) ->
        newFirstName = 'Titi'
        requestTest.post('/profile').send(firstName: newFirstName).expect(302).end (err, res) ->
          return done(err) if err
          res.header['location'].should.include('/profile')
          User.findOne firstName: newFirstName, (err, modifiedUser) ->
            should.not.exist(err)
            assert.equal fakeUser.lastName, modifiedUser.lastName
            done()

  describe '** Logged out **', ->
    describe 'GET', ->
      it 'should return 302', (done) ->
        request(new App()).get('/profile').expect(302).end (err, res) ->
          should.not.exist err
          done()
{'fraction_non_alphanumeric': 0.14666248824819805, 'fraction_numerical': 0.007521153243497336, 'mean_word_length': 2.2671443193449337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7640595', 'n_tokens_mistral': 921, 'n_tokens_neox': 898, 'n_words': 219}