<commit_before>/*global describe, it, assert, Hyperagent, beforeEach, fixtures */
'use strict';
(function () {

  describe('Hyperagent Integration Test', function () {
    // Configure AJAX to return what we tell it to return.
    beforeEach(function () {
      this.ajaxCalls = [];
      this.ajaxResponses = [];

      var ajaxMock = function (options) {
        this.ajaxCalls.push(options);

        // Could potentially re-use RSVP's async module here to get rid of the
        // 4ms delay.
        window.setTimeout(function () {
          options.success(this.ajaxResponses.pop());
        }.bind(this), 0);
      }.bind(this);
      Hyperagent.configure('ajax', ajaxMock);
    });

    it('should successfully parse a sample response', function (done) {
      this.ajaxResponses.push(JSON.stringify(fixtures.fullDoc));

      var agent = new Hyperagent.Resource('https://example.com');
      assert.equal(this.ajaxCalls.length, 0);
      var promise = agent.fetch().then(function (result) {
        assert.equal(agent, result);
        assert.equal(agent.props.welcome, 'Welcome to a haltalk server.');
        assert.equal(agent.embedded['ht:post'].length, 2);
        assert.equal(agent.embedded['ht:post'][0].props.content,
          'having fun w/ the HAL Talk explorer');
      }).then(done, done);

      assert.equal(this.ajaxCalls.length, 1);
      assert.equal(this.ajaxCalls[0].url, 'https://example.com');
    });

    it('should fetch a linked resource on demand', function (done) {
      this.ajaxResponses.push(JSON.stringify(fixtures.subDoc));
      this.ajaxResponses.push(JSON.stringify(fixtures.fullDoc));

      var agent = new Hyperagent.Resource('http://haltalk.herokuapp.com/');
      assert.equal(this.ajaxCalls.length, 0);
      var promise = agent.fetch().then(function (result) {
        return agent.embedded['ht:post'][0].fetch();
      }).then(function (post) {
        assert.equal(this.ajaxCalls.length, 2);
        assert.equal(post.props.content, 'having fun w/ the HAL Talk explorer');
        assert.equal(post.url(), 'http://haltalk.herokuapp.com' + post.links.self.props.href);
        assert.equal(post.links['ht:author'].props.title, '<NAME>');
      }.bind(this)).then(done, done);
    });
  });
}());<commit_msg>Added incomplete regression test for disappearing links<commit_after>/*global describe, it, assert, Hyperagent, beforeEach, fixtures */
'use strict';
(function () {

  describe('Hyperagent Integration Test', function () {
    // Configure AJAX to return what we tell it to return.
    beforeEach(function () {
      this.ajaxCalls = [];
      this.ajaxResponses = [];

      var ajaxMock = function (options) {
        this.ajaxCalls.push(options);

        // Could potentially re-use RSVP's async module here to get rid of the
        // 4ms delay.
        window.setTimeout(function () {
          options.success(this.ajaxResponses.pop());
        }.bind(this), 0);
      }.bind(this);
      Hyperagent.configure('ajax', ajaxMock);
    });

    it('should successfully parse a sample response', function (done) {
      this.ajaxResponses.push(JSON.stringify(fixtures.fullDoc));

      var agent = new Hyperagent.Resource('https://example.com');
      assert.equal(this.ajaxCalls.length, 0);
      var promise = agent.fetch().then(function (result) {
        assert.equal(agent, result);
        assert.equal(agent.props.welcome, 'Welcome to a haltalk server.');
        assert.equal(agent.embedded['ht:post'].length, 2);
        assert.equal(agent.embedded['ht:post'][0].props.content,
          'having fun w/ the HAL Talk explorer');
      }).then(done, done);

      assert.equal(this.ajaxCalls.length, 1);
      assert.equal(this.ajaxCalls[0].url, 'https://example.com');
    });

    it('should fetch a linked resource on demand', function (done) {
      this.ajaxResponses.push(JSON.stringify(fixtures.subDoc));
      this.ajaxResponses.push(JSON.stringify(fixtures.fullDoc));

      var agent = new Hyperagent.Resource('http://haltalk.herokuapp.com/');
      assert.equal(this.ajaxCalls.length, 0);
      var promise = agent.fetch().then(function (result) {
        return agent.embedded['ht:post'][0].fetch();
      }).then(function (post) {
        assert.equal(this.ajaxCalls.length, 2);
        assert.equal(post.props.content, 'having fun w/ the HAL Talk explorer');
        assert.equal(post.url(), 'http://haltalk.herokuapp.com' + post.links.self.props.href);
        assert.equal(post.links['ht:author'].props.title, '<NAME>');
      }.bind(this)).then(done, done);
    });

    it('should not remove links after loading', function () {
      this.ajaxResponses.push(JSON.stringify(fixtures.subDoc));

      this.agent._load({ _links: {
        self: {
          href: 'http://example.com/self'
        },
        users: [
          { href: '/1' },
          { href: '/2' },
          { href: '/3' },
        ]
      }});
      assert.equal(this.agent.links.users.length, 3);
      this.agent.links.users[1].fetch();
      assert.equal(this.agent.links.users.length, 3, 'Should stay at 3 users');
    });
  });
}());
{'fraction_non_alphanumeric': 0.16068275456150677, 'fraction_numerical': 0.00529723366686286, 'mean_word_length': 2.87680608365019, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '7633904', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1511, 'n_words': 312}