<commit_before>var Code = require('code'),
    Lab = require('lab'),
    lab = exports.lab = Lab.script(),
    describe = lab.experiment,
    before = lab.before,
    after = lab.after,
    it = lab.test,
    expect = Code.expect,
    nock = require("nock"),
    cheerio = require("cheerio"),
    users = require('../../fixtures').users;

var server;

before(function (done) {
  require('../../mocks/server')(function (obj) {
    server = obj;
    done();
  });
});

after(function (done) {
  server.stop(done);
});

describe('GET /~bob for a user other than bob', function () {
  var $
  var resp
  var context
  var name = 'bob';
  var mock = nock("https://user-api-example.com")
    .get('/user/bob')
    .reply(200, users.bob)
    .get('/user/bob/package?per_page=9999')
    .reply(200, users.packages)
    .get('/user/bob/stars')
    .reply(200, users.stars);

  before(function(done) {
    server.inject('/~bob', function (response) {
      resp = response;
      $ = cheerio.load(resp.result)
      context = resp.request.response.source.context;
      mock.done();
      done();
    });
  });

  it("renders a list of bob's packages", function(done){
    expect($("ul.collaborated-packages > li").length).to.equal(18);
    expect($("ul.collaborated-packages > li > a[href='/package/googalytics']").length).to.equal(1);
    done()
  })

  it("truncates package names longer than 50 characters", function(done){
    expect($("a[href='/package/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz']").text())
      .to.equal("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx...");
    done()
  })

  it("renders a list of packages starred by bob", function(done){
    expect($("ul.starred-packages > li").length).to.equal(4);
    expect($("ul.starred-packages > li > a[href='/package/jade']").length).to.equal(1);
    done()
  })

  it("renders a link to bob's github profile", function(done){
    expect($("a[href='https://github.com/bob']").length).to.equal(1);
    done()
  })

  it("renders a link to bob's twitter profile", function(done){
    expect($("a[href='https://twitter.com/twob']").length).to.equal(1);
    done()
  })

  it("renders bob's full name", function(done){
    expect($("h2.fullname").text()).to.equal("<NAME>");
    done()
  })

  it("renders bob's obfuscated email address", function(done){
    expect($("li.email a[data-email]").length).to.equal(1);
    done()
  })

});

describe('GET /~bob for logged-in bob', function () {
  var $
  var resp
  var context
  var name = 'bob';
  var mock = nock("https://user-api-example.com")
    .get('/user/bob')
    .reply(200, users.bob)
    .get('/user/bob/package?per_page=9999')
    .reply(200, users.packages)
    .get('/user/bob/stars')
    .reply(200, users.stars);

  before(function(done) {
    server.inject({url:'/~bob', credentials: users.bob}, function (response) {
      resp = response;
      $ = cheerio.load(resp.result)
      context = resp.request.response.source.context;
      mock.done();<commit_msg>change mock scopes. why?<commit_after>var Code = require('code'),
    Lab = require('lab'),
    lab = exports.lab = Lab.script(),
    describe = lab.experiment,
    before = lab.before,
    after = lab.after,
    it = lab.test,
    expect = Code.expect,
    nock = require("nock"),
    cheerio = require("cheerio"),
    users = require('../../fixtures').users;

var server;

before(function (done) {
  require('../../mocks/server')(function (obj) {
    server = obj;
    done();
  });
});

after(function (done) {
  server.stop(done);
});

describe('GET /~bob for a user other than bob', function () {
  var $
  var resp
  var context

  before(function(done) {

    var mock = nock("https://user-api-example.com")
      .get('/user/bob')
      .reply(200, users.bob)
      .get('/user/bob/package?per_page=9999')
      .reply(200, users.packages)
      .get('/user/bob/stars')
      .reply(200, users.stars);

    server.inject('/~bob', function (response) {
      resp = response;
      $ = cheerio.load(resp.result)
      context = resp.request.response.source.context;
      mock.done();
      done();
    });
  });

  it("renders a list of bob's packages", function(done){
    expect($("ul.collaborated-packages > li").length).to.equal(18);
    expect($("ul.collaborated-packages > li > a[href='/package/googalytics']").length).to.equal(1);
    done()
  })

  it("truncates package names longer than 50 characters", function(done){
    expect($("a[href='/package/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz']").text())
      .to.equal("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx...");
    done()
  })

  it("renders a list of packages starred by bob", function(done){
    expect($("ul.starred-packages > li").length).to.equal(4);
    expect($("ul.starred-packages > li > a[href='/package/jade']").length).to.equal(1);
    done()
  })

  it("renders a link to bob's github profile", function(done){
    expect($("a[href='https://github.com/bob']").length).to.equal(1);
    done()
  })

  it("renders a link to bob's twitter profile", function(done){
    expect($("a[href='https://twitter.com/twob']").length).to.equal(1);
    done()
  })

  it("renders bob's full name", function(done){
    expect($("h2.fullname").text()).to.equal("<NAME>");
    done()
  })

  it("renders bob's obfuscated email address", function(done){
    expect($("li.email a[data-email]").length).to.equal(1);
    done()
  })

});

describe('GET /~bob for logged-in bob', function () {
  var $
  var resp
  var context
  var name = 'bob';

  before(function(done) {
    var mock = nock("https://user-api-example.com")
      .get('/user/bob')
      .reply(200, users.bob)
      .get('/user/bob/package?per_page=9999')
      .reply(200, users.packages)
      .get('/user/bob/stars')
      .reply(200, users.stars);

    server.inject({url:'/~bob', credentials: users.bob}, function (response) {
      resp = response;
      $ = cheerio.load(resp.result)
      context = resp.request.response.source.context;
      mock.done();
{'fraction_non_alphanumeric': 0.19620884602593947, 'fraction_numerical': 0.012304622547389425, 'mean_word_length': 3.2359154929577465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 8, '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': '5976305', 'n_tokens_mistral': 2183, 'n_tokens_neox': 2042, 'n_words': 377}