<commit_before>import chai, { expect } from 'chai';
import chaiHttp from 'chai-http';
import log from 'npmlog';
import app from '../../../server';
import fakeData from '../helpers/FakeData';
import db from '../../models';
import SeedData from '../helpers/SeedData';


chai.use(chaiHttp);
const request = chai.request(app),
  privateDocument = fakeData.document2,
  adminUser = fakeData.validAdmin,
  validRegularUser1 = fakeData.validRegularUser1;

let adminToken, regular1Token;

describe('Routes : Search', () => {
  before((done) => {
    SeedData.init().then(() => {
      request
        .post('/login')
        .send({ loginID: adminUser.email, password: <PASSWORD> })
        .end((err, res) => {
          adminToken = res.body.token;
        });
      request
        .post('/login')
        .send({ loginID: validRegularUser1.email,
          password: <PASSWORD> })
        .end((err, res) => {
          regular1Token = res.body.token;
          done();
        });
    });
  });
  after((done) => {
    log.info('message :  ', 'resseting Database.......');
    db.sequelize.sync({ force: true }).then(() => {
      log.info('message :  ', 'Database reset succesful');
      done();
    });
  });
  describe('GET /search/documents/?q={}', () => {
    it('it should allow users search for documents', (done) => {
      request
        .get('/search/documents/?q=a')
        .set({ 'x-access-token': regular1Token })
        .end((err, res) => {
          expect(res).to.have.status(200);
          expect(res.body.document).to.be.an('array');
          done();
        });
    });
    it('it should not allow users search for other users private document ',
    (done) => {
      request
        .get(`/search/documents/?q=${privateDocument.title}`)
        .set({ 'x-access-token': regular1Token })
        .end((err, res) => {
          expect(res).to.have.status(200);
          expect(res.body.document).to.be.an('array');
          const searchDoc = res.body.document.filter((document) => {
            if (document.title === privateDocument.title) {
              return document;
            }
            return undefined;
          });
          expect(searchDoc).to.eql([]); // deeply equal
          done();
        });
    });
    it('it should allow Admin search for private document', (done) => {
      request
        .get(`/search/documents/?q=${privateDocument.title}`)
        .set({ 'x-access-token': adminToken })
        .end((err, res) => {
          expect(res).to.have.status(200);
          expect(res.body.document).to.be.an('array');<commit_msg>update test<commit_after>import chai, { expect } from 'chai';
import chaiHttp from 'chai-http';
import log from 'npmlog';
import app from '../../../server';
import fakeData from '../helpers/FakeData';
import db from '../../models';
import SeedData from '../helpers/SeedData';


chai.use(chaiHttp);
const request = chai.request(app),
  privateDocument = fakeData.document2,
  adminUser = fakeData.validAdmin,
  validRegularUser1 = fakeData.validRegularUser1;

let adminToken, regular1Token;

describe('Routes : Search', () => {
  before((done) => {
    SeedData.init().then(() => {
      request
        .post('/login')
        .send({ loginID: adminUser.email, password: <PASSWORD> })
        .end((err, res) => {
          adminToken = res.body.token;
        });
      request
        .post('/login')
        .send({ loginID: validRegularUser1.email,
          password: <PASSWORD> })
        .end((err, res) => {
          regular1Token = res.body.token;
          done();
        });
    });
  });
  after((done) => {
    log.info('message :  ', 'resseting Database.......');
    db.sequelize.sync({ force: true }).then(() => {
      log.info('message :  ', 'Database reset succesful');
      done();
    });
  });
  describe('GET /search/documents/?q={}', () => {
    it('it should allow users search for documents', (done) => {
      request
        .get('/search/documents/?q=a')
        .set({ 'x-access-token': regular1Token })
        .end((err, res) => {
          expect(res).to.have.status(200);
          expect(res.body.document).to.be.an('array');
          done();
        });
    });
    it('it should allow Admin search for private document', (done) => {
      request
        .get(`/search/documents/?q=${privateDocument.title}`)
        .set({ 'x-access-token': adminToken })
        .end((err, res) => {
          expect(res).to.have.status(200);
          expect(res.body.document).to.be.an('array');
{'fraction_non_alphanumeric': 0.1870838881491345, 'fraction_numerical': 0.006657789613848202, 'mean_word_length': 2.3018315018315016, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 34, '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': '5199720', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1368, 'n_words': 275}