{"size": 2558, "ext": "js", "max_stars_repo_path": "job_manager/nmpi-job-manager-app/nmpi/user/model.spec.js", "max_stars_repo_name": "msenoville/hbp_neuromorphic_platform", "max_stars_repo_stars_event_min_datetime": "2017-09-03T19:57:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-17T11:25:28.000Z", "max_issues_repo_path": "job_manager/nmpi-job-manager-app/nmpi/user/model.spec.js", "max_issues_repo_name": "msenoville/hbp_neuromorphic_platform", "max_issues_repo_issues_event_min_datetime": "2017-06-27T08:36:41.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T16:04:32.000Z", "max_forks_repo_path": "job_manager/nmpi-job-manager-app/nmpi/user/model.spec.js", "max_forks_repo_name": "msenoville/hbp_neuromorphic_platform", "max_forks_repo_forks_event_min_datetime": "2017-06-11T20:16:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-05T12:49:01.000Z"}
{"max_stars_count": 13, "max_issues_count": 30, "max_forks_count": 6, "avg_line_length": 29.7441860465, "max_line_length": 109, "alphanum_fraction": 0.6204065676}
// Be descriptive with titles here. The describe and it titles combined read like a sentence.
describe('User factory', function() {
  // it('has a dummy spec to test 2 + 2', function() {
  //   // An intentionally failing test. No code within expect() will never equal 4.
  //   expect(2 + 2).toEqual(4);
  // });

  var User;
  var user_url = "https://services.humanbrainproject.eu/idm/v1/api/user/";
  var $httpBackend;
  var testUser = {
    "id" : "304621",
    "updatedAt" : "2017-07-05T08:28:51",
    "username" : "jduperrier02",
    "givenName" : "DUPERRIER",
    "familyName" : "Jonathan",
    "displayName" : "DUPERRIER Jonathan",
    "title" : null,
    "profile" : null,
    "picture" : null,
    "emails" : [ {
      "value" : "jonathan.duperrier@gmail.com",
      "primary" : true,
      "verified" : true
    } ],
    "phones" : [ ],
    "institutions" : [ {
      "name" : "Centre National de la Recherche Scientifique",
      "department" : null,
      "postalAddress" : null,
      "title" : null,
      "primary" : true
    } ],
    "ims" : [ ]
  };

  //The single user we expect to receive when calling findById('2')
  var singleUser = {
    id: '2',
    username: 'jo',
    is_superuser: '1',
  };  
  // Before each test load our api.users module
  beforeEach(angular.mock.module('nmpi'));

  // Before each test set our injected User factory (_User_) to our local User variable
  beforeEach(inject(function(_User_, _$httpBackend_) {
    User = _User_;
    $httpBackend = _$httpBackend_;
  }));

  beforeEach(function() {
    // Initialize our local result object to an empty object before each test
    result = {};
    
    // Spy and force the return value when UsersFactory.all() is called
    spyOn(User, 'get').and.callThrough();
  });

  // A simple test to verify the nmpi module exists
  it('should exist User Factory', function() {
    expect(User).toBeDefined();
  });

  it('should exist User.get', function() {
    expect(User.get).toBeDefined();
  });

  it('test result User.get', function() {
    console.log("user_url : " + user_url);
    console.log("testuser : " + JSON.stringify(testUser));
    $httpBackend.expectGET("https://services.humanbrainproject.eu/idm/v1/api/user/304621").respond(testUser);

    expect(User.get).not.toHaveBeenCalled();

    rs = User.get({id:'304621'}, function(result){
      console.log("User.get function");
      usr = result;
    });
    $httpBackend.flush();

    expect(User.get).toHaveBeenCalledWith({id:'304621'}, jasmine.any(Function));
    expect(usr).toBeDefined();
  });

});