<commit_before>'use strict';

const supertest = require('supertest');
const req = supertest(require('../../').app);

const github = require('../../lib/github');

const owner = process.env.TEST_APP_NAME.split('/')[0];
const repo = process.env.TEST_APP_NAME.split('/')[1];

beforeEach(function beforeEach() {
  github.client().repos = {
    getCommits: function gitHubGetCommitsMock() {
      throw new Error('github.repos.getCommits() is not implemented');
    },
    getCommit: function gitHubGetCommitMock() {
      throw new Error('github.repos.getCommit() is not implemented');
    },
  };

  github.client().statuses = {
    get: function gitHubGetStatusMock(msg, cb) {
      process.nextTick(cb.bind(null, null, []));
    },
  };
});


describe('GET /app', function describe() {
  const url = `/app`;

  it('redirects to login for unauthenticated user', function it(done) {
    req.get(url)
     .expect(302)
     .expect('Location', '/login', done);
  });

  it('returns my applications', function it(done) {
    req.get(url)
      .set('Cookie', process.env.SESS_COOKIE)
      .expect(200, done);
  });
});


describe('ALL /app/new', function describe() {
  const url = `/app/new`;

  before(function before() {
    github.client().getAllRepos = function getAllReposMock(cb) {
      process.nextTick(cb.bind(null, null, [
        'foo/bar',
        'for/baz',
        'bar/foo',
      ]));
    };
  });

  it('redirects to login for unauthenticated user', function it(done) {
    req.get(url)
     .expect(302)
     .expect('Location', '/login', done);
  });

  it('returns new application form', function it(done) {
    req.get(url)
      .set('Cookie', process.env.SESS_COOKIE)
      .expect(200, done);
  });
});

describe('GET /app/:owner/:repo', function describe() {
  const url = `/app/${owner}/${repo}`;

  it('redirects to login for unauthenticated user', function it(done) {
    req.get(url)
     .expect(302)
     .expect('Location', '/login', done);
  });

  it('redirects to my apps for unautorized user');

  it('returns application', function it(done) {
    github.client().repos.getCommits = function gitHubGetCommitsSpy(msg, cb) {
      cb(null, [{
        sha: '28f497509b8e2f7ff75d48de83303dcc969cd6de',
        commit: {
          author: null,
          commiter: null,
          message: 'Foobar',
          tree: null,
          url: '',
          comment_count: 0,
        },
        parents: [null],<commit_msg>test(app): fix name of github commit mock function<commit_after>'use strict';

const supertest = require('supertest');
const req = supertest(require('../../').app);

const github = require('../../lib/github');

const owner = process.env.TEST_APP_NAME.split('/')[0];
const repo = process.env.TEST_APP_NAME.split('/')[1];

beforeEach(function beforeEach() {
  github.client().repos = {
    getCommits: function gitHubGetCommitsMock() {
      throw new Error('github.repos.getCommits() is not implemented');
    },
    getCommit: function gitHubGetCommitMock() {
      throw new Error('github.repos.getCommit() is not implemented');
    },
  };

  github.client().statuses = {
    get: function gitHubGetStatusMock(msg, cb) {
      process.nextTick(cb.bind(null, null, []));
    },
  };
});


describe('GET /app', function describe() {
  const url = `/app`;

  it('redirects to login for unauthenticated user', function it(done) {
    req.get(url)
     .expect(302)
     .expect('Location', '/login', done);
  });

  it('returns my applications', function it(done) {
    req.get(url)
      .set('Cookie', process.env.SESS_COOKIE)
      .expect(200, done);
  });
});


describe('ALL /app/new', function describe() {
  const url = `/app/new`;

  before(function before() {
    github.client().getAllRepos = function getAllReposMock(cb) {
      process.nextTick(cb.bind(null, null, [
        'foo/bar',
        'for/baz',
        'bar/foo',
      ]));
    };
  });

  it('redirects to login for unauthenticated user', function it(done) {
    req.get(url)
     .expect(302)
     .expect('Location', '/login', done);
  });

  it('returns new application form', function it(done) {
    req.get(url)
      .set('Cookie', process.env.SESS_COOKIE)
      .expect(200, done);
  });
});

describe('GET /app/:owner/:repo', function describe() {
  const url = `/app/${owner}/${repo}`;

  it('redirects to login for unauthenticated user', function it(done) {
    req.get(url)
     .expect(302)
     .expect('Location', '/login', done);
  });

  it('redirects to my apps for unautorized user');

  it('returns application', function it(done) {
    github.client().repos.getCommits = function gitHubGetCommitsMock(msg, cb) {
      cb(null, [{
        sha: '28f497509b8e2f7ff75d48de83303dcc969cd6de',
        commit: {
          author: null,
          commiter: null,
          message: 'Foobar',
          tree: null,
          url: '',
          comment_count: 0,
        },
        parents: [null],
{'fraction_non_alphanumeric': 0.17160844841592202, 'fraction_numerical': 0.017059301380991064, 'mean_word_length': 2.965378421900161, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3706252', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1601, 'n_words': 342}