<commit_before>function setupMoment(date, anObject) {
  spyOn(anObject, "moment");
  anObject.moment.plan = function () {
    var realMoment = anObject.moment.originalValue;
    // set "now" to a fixed date to enable static expectations
    if (!arguments.length) {
      return realMoment(date);
    }
    return realMoment.apply(null, arguments);
  }
}

describe("Fourth Wall", function () {

  describe("getQueryVariables", function () {
    it("should convert a query string into a params object", function () {
      var query_params = FourthWall.getQueryVariables("?ref=gh-pages&token=<PASSWORD>");
      expect(query_params).toEqual({'ref': 'gh-pages', 'token': '<PASSWORD>'});
    });
    it("should return current location params object if no query string is provided", function() {
      spyOn(FourthWall, '_getLocationSearch').andReturn('?foo=bar&me=you');
      var query_params = FourthWall.getQueryVariables();
      expect(query_params).toEqual({foo: 'bar', me: 'you'});
    });
  });
  describe("getQueryVariable", function () {
    it("should get a query parameter from the provided query string", function () {
      spyOn(FourthWall, '_getLocationSearch').andReturn('?foo=bar');
      var value = FourthWall.getQueryVariable('foo', '?foo=everything');
      expect(value).toEqual('everything');
    });
    it("should get a query parameter from the current location", function () {
      spyOn(FourthWall, '_getLocationSearch').andReturn('?foo=bar');
      var value = FourthWall.getQueryVariable('foo');
      expect(value).toEqual('bar');
    });
  });
  describe("buildQueryString", function () {
    it("should convert a query string into a params object", function () {
      var query_string = FourthWall.buildQueryString({'ref': 'gh-pages', 'token': '<PASSWORD>'});
      expect(query_string).toEqual("?ref=gh-pages&token=<PASSWORD>");
    });
    it("should handle an empty object", function () {
      var query_string = FourthWall.buildQueryString({});
      expect(query_string).toEqual("");
    });
  });

  describe("getToken", function () {
    beforeEach(function () {
      spyOn(FourthWall, 'getQueryVariable');
      FourthWall.getQueryVariable.plan = function(name) {
        return {
          "api.github.com_token": "com-token",
          "token": "default-token",
          "github.gds_token": "gds-token"
        }[name];
      };
    });

    it("returns correct enterprise token", function() {
      expect(FourthWall.getToken('github.gds')).toEqual("gds-token");
    });

    it("returns correct github.com token", function() {
      expect(FourthWall.getToken('api.github.com')).toEqual("com-token");
    });

    it("falls back to default token for github.com", function() {
      FourthWall.getQueryVariable.plan = function(name) {
        return {
          "token": "default-token",
          "github.gds_token": "gds-token"
        }[name];
      };

      expect(FourthWall.getToken('api.github.com')).toEqual("default-token");
    })
  });

  describe("getTokenFromUrl", function() {
    beforeEach(function() {
      spyOn(FourthWall, 'getToken');
    });

    it("extracts github.com hostname", function() {
      FourthWall.getTokenFromUrl("http://api.github.com/foo/bar");
      expect(FourthWall.getToken).toHaveBeenCalledWith("api.github.com");
    });

    it("extracts enterprise github hostname", function() {
      FourthWall.getTokenFromUrl("http://github.gds/foo/bar");
      expect(FourthWall.getToken).toHaveBeenCalledWith("github.gds");
    });
  });

  describe("getTeams", function () {
    it("should return an array of teams", function () {
      spyOn(FourthWall, "getQueryVariables").andReturn({team: "myorg/myteam"});
      var teams = FourthWall.getTeams();

      var expected = {
        org: "myorg",
        team: "myteam",
        hostname: "api.github.com",
        baseUrl: "https://api.github.com"
      };
      expect(teams.length).toBe(1);
      expect(_.isEqual(teams[0], expected)).toEqual(true);
    });

    it("should return an array with a github enterprise team", function () {
      spyOn(FourthWall, "getQueryVariables").andReturn({"github.gds_team": "myorg/myteam"});
      var teams = FourthWall.getTeams();

      expect(teams.length).toBe(1);
      var expected = {
        org: "myorg",
        team: "myteam",
        hostname: "github.gds",
        baseUrl: "https://github.gds/api/v3"
      };
      expect(_.isEqual(teams[0], expected)).toEqual(true);
    });

    it("should return an empty array if no teams are set", function() {
      spyOn(FourthWall, "getQueryVariables").andReturn({"foo": "bar"});
      var teams = FourthWall.getTeams();
      expect(teams).toEqual([]);
    });
  });

  describe("FetchRepos", function () {
    describe("mergeRepoArrays", function () {
      it("should merge two repo arrays", function () {
        var repos1 = [{userName: "example", repo: "example"}],
            repos2 = [{userName: "example", repo: "another"}];

        var result = FourthWall.FetchRepos.mergeRepoArrays(repos1, repos2);

        var expected = [
          {userName: "example", repo: "example"},
          {userName: "example", repo: "another"},<commit_msg>Simplify some assertions in the tests.<commit_after>function setupMoment(date, anObject) {
  spyOn(anObject, "moment");
  anObject.moment.plan = function () {
    var realMoment = anObject.moment.originalValue;
    // set "now" to a fixed date to enable static expectations
    if (!arguments.length) {
      return realMoment(date);
    }
    return realMoment.apply(null, arguments);
  }
}

describe("Fourth Wall", function () {

  describe("getQueryVariables", function () {
    it("should convert a query string into a params object", function () {
      var query_params = FourthWall.getQueryVariables("?ref=gh-pages&token=nonsense");
      expect(query_params).toEqual({'ref': 'gh-pages', 'token': 'nonsense'});
    });
    it("should return current location params object if no query string is provided", function() {
      spyOn(FourthWall, '_getLocationSearch').andReturn('?foo=bar&me=you');
      var query_params = FourthWall.getQueryVariables();
      expect(query_params).toEqual({foo: 'bar', me: 'you'});
    });
  });
  describe("getQueryVariable", function () {
    it("should get a query parameter from the provided query string", function () {
      spyOn(FourthWall, '_getLocationSearch').andReturn('?foo=bar');
      var value = FourthWall.getQueryVariable('foo', '?foo=everything');
      expect(value).toEqual('everything');
    });
    it("should get a query parameter from the current location", function () {
      spyOn(FourthWall, '_getLocationSearch').andReturn('?foo=bar');
      var value = FourthWall.getQueryVariable('foo');
      expect(value).toEqual('bar');
    });
  });
  describe("buildQueryString", function () {
    it("should convert a query string into a params object", function () {
      var query_string = FourthWall.buildQueryString({'ref': 'gh-pages', 'token': '<PASSWORD>'});
      expect(query_string).toEqual("?ref=gh-pages&token=n<PASSWORD>ense");
    });
    it("should handle an empty object", function () {
      var query_string = FourthWall.buildQueryString({});
      expect(query_string).toEqual("");
    });
  });

  describe("getToken", function () {
    beforeEach(function () {
      spyOn(FourthWall, 'getQueryVariable');
      FourthWall.getQueryVariable.plan = function(name) {
        return {
          "api.github.com_token": "com-token",
          "token": "default-token",
          "github.gds_token": "gds-token"
        }[name];
      };
    });

    it("returns correct enterprise token", function() {
      expect(FourthWall.getToken('github.gds')).toEqual("gds-token");
    });

    it("returns correct github.com token", function() {
      expect(FourthWall.getToken('api.github.com')).toEqual("com-token");
    });

    it("falls back to default token for github.com", function() {
      FourthWall.getQueryVariable.plan = function(name) {
        return {
          "token": "default-token",
          "github.gds_token": "gds-token"
        }[name];
      };

      expect(FourthWall.getToken('api.github.com')).toEqual("default-token");
    })
  });

  describe("getTokenFromUrl", function() {
    beforeEach(function() {
      spyOn(FourthWall, 'getToken');
    });

    it("extracts github.com hostname", function() {
      FourthWall.getTokenFromUrl("http://api.github.com/foo/bar");
      expect(FourthWall.getToken).toHaveBeenCalledWith("api.github.com");
    });

    it("extracts enterprise github hostname", function() {
      FourthWall.getTokenFromUrl("http://github.gds/foo/bar");
      expect(FourthWall.getToken).toHaveBeenCalledWith("github.gds");
    });
  });

  describe("getTeams", function () {
    it("should return an array of teams", function () {
      spyOn(FourthWall, "getQueryVariables").andReturn({team: "myorg/myteam"});
      var teams = FourthWall.getTeams();

      var expected = {
        org: "myorg",
        team: "myteam",
        hostname: "api.github.com",
        baseUrl: "https://api.github.com"
      };
      expect(teams.length).toBe(1);
      expect(teams[0]).toEqual(expected);
    });

    it("should return an array with a github enterprise team", function () {
      spyOn(FourthWall, "getQueryVariables").andReturn({"github.gds_team": "myorg/myteam"});
      var teams = FourthWall.getTeams();

      expect(teams.length).toBe(1);
      var expected = {
        org: "myorg",
        team: "myteam",
        hostname: "github.gds",
        baseUrl: "https://github.gds/api/v3"
      };
      expect(teams[0]).toEqual(expected);
    });

    it("should return an empty array if no teams are set", function() {
      spyOn(FourthWall, "getQueryVariables").andReturn({"foo": "bar"});
      var teams = FourthWall.getTeams();
      expect(teams).toEqual([]);
    });
  });

  describe("FetchRepos", function () {
    describe("mergeRepoArrays", function () {
      it("should merge two repo arrays", function () {
        var repos1 = [{userName: "example", repo: "example"}],
            repos2 = [{userName: "example", repo: "another"}];

        var result = FourthWall.FetchRepos.mergeRepoArrays(repos1, repos2);

        var expected = [
          {userName: "example", repo: "example"},
          {userName: "example", repo: "another"},
{'fraction_non_alphanumeric': 0.16412287480680063, 'fraction_numerical': 0.0017387944358578052, 'mean_word_length': 3.33361239012139, 'pattern_counts': {'":': 14, '<': 9, '<?xml version=': 0, '>': 9, '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': '2326397', 'n_tokens_mistral': 3133, 'n_tokens_neox': 3061, 'n_words': 618}