<commit_before>'use strict';

require('./lib/test-env.js');

const expect = require('chai').expect;
const request = require('superagent');
const Profile = require('../model/profile.js');
const User = require('../model/user.js');
const awsMocks = require('./lib/aws-mocks.js');

require('../model/profile.js');
require('../model/user.js');

const serverToggle = require('./lib/server-toggle.js');
const server = require('server.js');

const url = `http://localhost:${process.env.PORT}`;

const exampleProfile = {
  name: 'example name',
  bio: 'example bio',
  image: `${__dirname}/data/nobody_image.jpg`
};

const exampleUser = {
  username: 'example username',
  password: '<PASSWORD>',
  email: 'example email'
};

describe('Profile Routes', function () {
  before (done => {
    serverToggle.serverOn(server, done);
  });
  after (done => {
    serverToggle.serverOff(server, done);
  });
  afterEach(done => {
    Promise.all([
      User.remove({}),
      Profile.remove({})
    ])
    .then( () => done())
    .catch(done);
  });

  describe('POST: /api/profile/', function () {
    before(done => {
      new User(exampleUser)
      .generatePasswordHash(exampleUser.password)
      .then( user => user.save())
      .then( user => {
        this.tempUser = user;
        return user.generateToken();
      })
      .then( token => {
        this.tempToken = token;
        done();
      })
      .catch(done);
    });
    it('should return a profile', done => {
      request.post(`${url}/api/profile`)
      .set({
        Authorization: `Bearer ${this.tempToken}`
      })
      .field('name', exampleProfile.name)
      .field('bio', exampleProfile.bio)
      .attatch('image', exampleProfile.image)
      .end((err, res) => {
        if(err) return done(err);
        expect(res.status).to.equal(200, 'upload worked');
        expect(res.body.name).to.equal(exampleProfile.name);
        expect(res.body.bio).to.equal(exampleProfile.bio);
        expect(res.body.userID).to.be.a('string');
        expect(res.body.imageURI).to.equal(awsMocks.uploadMock.Location);
        done();
      });
    });
  });

  describe('without an image', function() {
    before(done => {
      new User(exampleUser)
      .generatePasswordHash(<PASSWORD>)
      .then ( user => user.save())
      .then( user => {
        this.tempUser = user;
        return user.generateToken();
      })
      .then( token => {
        this.tempToken = token;
        done();
      })
      .catch(done);
    });
    it('shoudl return a profie', done => {
      request.post(`${url}/api/profile`)
      .set({
        Authorization: `Bearer ${this.tempToken}`
      })
      .field('name', exampleProfile.name)
      .field('bio', exampleProfile.bio)
      .end((err, res) => {
        expect(res.status).to.equal(400, 'upload worked');
        done();
      });
    });
  });
  describe('with a wrong image file path', function() {
    before(done => {
      new User(exampleUser)
      .generatePasswordHash(<PASSWORD>)
      .then( user => user.save())
      .then( user => {
        this.tempUser = user;
        return user.generateToken();
      })
      .then( token => {
        this.tempToken = token;
        done();
      })
      .catch(done);
    });
    it('should return a profile', done => {
      request.post(`${url}/api/profile`)
      .set({
        Authorization: `Bearer ${this.tempToken}`
      })
      .field('name', exampleProfile.name)
      .field('bio', exampleProfile.bio)
      .attatch('wrongImage', exampleProfile.image)
      .end((err, res) => {
        expect(res.status).to.equal(500, 'upload worked');
        done();
      });
    });
  });
});<commit_msg>almost done with get test<commit_after>'use strict';

require('./lib/test-env.js');

const expect = require('chai').expect;
const request = require('superagent');
const Profile = require('../model/profile.js');
const User = require('../model/user.js');
const awsMocks = require('./lib/aws-mocks.js');

require('../model/profile.js');
require('../model/user.js');

const serverToggle = require('./lib/server-toggle.js');
const server = require('server.js');

const url = `http://localhost:${process.env.PORT}`;

const exampleProfile = {
  name: 'example name',
  bio: 'example bio',
  image: `${__dirname}/data/nobody_image.jpg`
};

const exampleUser = {
  username: 'example username',
  password: '<PASSWORD>',
  email: 'example email'
};

describe('Profile Routes', function () {
  before (done => {
    serverToggle.serverOn(server, done);
  });
  after (done => {
    serverToggle.serverOff(server, done);
  });
  afterEach(done => {
    Promise.all([
      User.remove({}),
      Profile.remove({})
    ])
    .then( () => done())
    .catch(done);
  });

  describe('POST: /api/profile/', function () {
    before(done => {
      new User(exampleUser)
      .generatePasswordHash(exampleUser.password)
      .then( user => user.save())
      .then( user => {
        this.tempUser = user;
        return user.generateToken();
      })
      .then( token => {
        this.tempToken = token;
        done();
      })
      .catch(done);
    });
    it('should return a profile', done => {
      request.post(`${url}/api/profile`)
      .set({
        Authorization: `Bearer ${this.tempToken}`
      })
      .field('name', exampleProfile.name)
      .field('bio', exampleProfile.bio)
      .attatch('image', exampleProfile.image)
      .end((err, res) => {
        if(err) return done(err);
        expect(res.status).to.equal(200, 'upload worked');
        expect(res.body.name).to.equal(exampleProfile.name);
        expect(res.body.bio).to.equal(exampleProfile.bio);
        expect(res.body.userID).to.be.a('string');
        expect(res.body.imageURI).to.equal(awsMocks.uploadMock.Location);
        done();
      });
    });
  });

  describe('without an image', function() {
    before(done => {
      new User(exampleUser)
      .generatePasswordHash(exampleUser.password)
      .then ( user => user.save())
      .then( user => {
        this.tempUser = user;
        return user.generateToken();
      })
      .then( token => {
        this.tempToken = token;
        done();
      })
      .catch(done);
    });
    it('shoudl return a profie', done => {
      request.post(`${url}/api/profile`)
      .set({
        Authorization: `Bearer ${this.tempToken}`
      })
      .field('name', exampleProfile.name)
      .field('bio', exampleProfile.bio)
      .end((err, res) => {
        expect(res.status).to.equal(400, 'upload worked');
        done();
      });
    });
  });
  describe('with a wrong image file path', function() {
    before(done => {
      new User(exampleUser)
      .generatePasswordHash(<PASSWORD>)
      .then( user => user.save())
      .then( user => {
        this.tempUser = user;
        return user.generateToken();
      })
      .then( token => {
        this.tempToken = token;
        done();
      })
      .catch(done);
    });
    it('should return a profile', done => {
      request.post(`${url}/api/profile`)
      .set({
        Authorization: `Bearer ${this.tempToken}`
      })
      .field('name', exampleProfile.name)
      .field('bio', exampleProfile.bio)
      .attatch('wrongImage', exampleProfile.image)
      .end((err, res) => {
        expect(res.status).to.equal(500, 'upload worked');
        done();
      });
    });
  });

  describe('GET: /api/profile/:id', function(){
    describe('with a valid id', function(){
      before(done => {
        new User(exampleUser)
        .generatePasswordHash(<PASSWORD>User.password)
        .then( user => user.save())
        .then( user => {
          this.tempUser = user;
          return user.generateToken();
        })
        .then(token => {
          this.tempToken = token;
          done();
        });
        .catch(done);
      });
      before(done => {
        exampleProfile.userID = this.tempUser._id;
        exampleProfile.imageURI = 'fake string';
        exampleProfile.objectKey = 'fake object key string';
        new Profile (exampleProfile).save()
        .then(profile => {
          this.tempProfile = profile;
          done();
        })
        .catch(done);
      });
      it('should return a profile', done => {
        request.get(`${url}/api/profile/${this.tempProfile._id}`)
        .set({
          Authorization: `Bearer ${this.tempToken}`
        })
        .end((err, res) => {
          if(err) return done(err);
          let date = new Date(res.body.created).toString();
          expect(res.status).to.equal(200);
          expect(res.body.name).to.equal('example name');
          expect(res.body.bio).to.equal('example bio');
          expect(res.body.userID).to.be.a('string');
          expect(date).to.not.equal('Invalid Date');
          done();
        });
      });
    });

    
  });
});
{'fraction_non_alphanumeric': 0.18312570781426954, 'fraction_numerical': 0.0023782559456398643, 'mean_word_length': 2.3136960600375236, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 61, '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': '1523295', 'n_tokens_mistral': 2718, 'n_tokens_neox': 2698, 'n_words': 495}