<commit_before>// TODO: Refactor the following into a real test

describe('User Factory', function () {
  var $scope, $rootScope, $location, $window, $httpBackend, User;

  // using angular mocks, we can inject the injector
  // to retrieve our dependencies
  beforeEach(module('services.user'));
  beforeEach(inject(function($injector) {

    // mock out our dependencies
    $rootScope = $injector.get('$rootScope');
    $location = $injector.get('$location');
    $window = $injector.get('$window');
    $httpBackend = $injector.get('$httpBackend');
    User = $injector.get('User');
    $scope = $rootScope.$new();
  }));

  afterEach(function() {
    $httpBackend.verifyNoOutstandingExpectation();
    $httpBackend.verifyNoOutstandingRequest();
    $window.localStorage.removeItem('user.authToken');
    $window.localStorage.removeItem('user.username');
  });

  describe('Authorization', function() {
    var data = {
      username: 'test',
      authToken: '<PASSWORD>'
    };

    it('Should have a signup method', function() {
      expect(User.signup).to.be.a('function');
    });

    it('Should store tokens in localStorage after signup', function() {
      var storage = $window.localStorage;

      // make a 'fake' reques to the server, not really going to our server
      $httpBackend.expectPOST('/api/signup').respond({data: data});
      User.signup();
      $httpBackend.flush();
      expect(storage.getItem('user.authToken')).to.equal(data.authToken);
      expect(storage.getItem('user.username')).to.equal(data.username);
    });

    it('Should have a signin method', function() {
      expect(User.login).to.be.a('function');
    });

    it('Should store token in localStorage after signin', function() {
      var storage = $window.localStorage;

      $httpBackend.expectGET('/api/login').respond({data: data});
      User.login();
      $httpBackend.flush();
      expect(storage.getItem('user.authToken')).to.equal(data.authToken);
      expect(storage.getItem('user.username')).to.equal(data.username);
    });

    it('Should have an isLoggedIn method', function() {
      expect(User.isLoggedIn).to.be.a('function');
    });

    it('Should know if the user is logged in', function() {
      $httpBackend.expectGET('/api/login').respond({data: data});
      User.login();
      $httpBackend.flush();
      
      expect(User.isLoggedIn()).to.be.true;
    });

    it('Should have a logout method', function() {
      expect(User.logout).to.be.a('function');
    });

    it('Should remove tokens on logout', function() {
      var storage = $window.localStorage;

      User.logout();
      expect(storage.getItem('user.authToken')).to.be.null;
      expect(storage.getItem('user.username')).to.be.null;
    });

  });
});

/*

  var mapId = '000000000000000000000010';
  var nodeId = '000000000000000000000100';

  User.followRoadmapById(mapId)
  .then(function (user) {
    console.log('Progress on one', User.getRoadmapProgress(user, mapId) );

    return User.completeNodeById(nodeId)<commit_msg>(test) Add a test for getData<commit_after>// TODO: Refactor the following into a real test

describe('User Factory', function () {
  var $scope, $rootScope, $location, $window, $httpBackend, User;

  // using angular mocks, we can inject the injector
  // to retrieve our dependencies
  beforeEach(module('services.user'));
  beforeEach(inject(function($injector) {

    // mock out our dependencies
    $rootScope = $injector.get('$rootScope');
    $location = $injector.get('$location');
    $window = $injector.get('$window');
    $httpBackend = $injector.get('$httpBackend');
    User = $injector.get('User');
    $scope = $rootScope.$new();
  }));

  afterEach(function() {
    $httpBackend.verifyNoOutstandingExpectation();
    $httpBackend.verifyNoOutstandingRequest();
    $window.localStorage.removeItem('user.authToken');
    $window.localStorage.removeItem('user.username');
  });

  describe('Authorization', function() {
    var data = {
      username: 'test',
      authToken: '<PASSWORD>'
    };

    it('Should have a signup method', function() {
      expect(User.signup).to.be.a('function');
    });

    it('Should store tokens in localStorage after signup', function() {
      var storage = $window.localStorage;

      // make a 'fake' request to the server, not really going to our server
      $httpBackend.expectPOST('/api/signup').respond({data: data});
      User.signup();
      $httpBackend.flush();
      expect(storage.getItem('user.authToken')).to.equal(data.authToken);
      expect(storage.getItem('user.username')).to.equal(data.username);
    });

    it('Should have a signin method', function() {
      expect(User.login).to.be.a('function');
    });

    it('Should store token in localStorage after signin', function() {
      var storage = $window.localStorage;

      $httpBackend.expectGET('/api/login').respond({data: data});
      User.login();
      $httpBackend.flush();
      expect(storage.getItem('user.authToken')).to.equal(data.authToken);
      expect(storage.getItem('user.username')).to.equal(data.username);
    });

    it('Should have an isLoggedIn method', function() {
      expect(User.isLoggedIn).to.be.a('function');
    });

    it('Should know if the user is logged in', function() {
      var storage = $window.localStorage;
      storage.setItem('user.authToken', data.authToken);
      storage.setItem('user.username', data.username);

      expect(User.isLoggedIn()).to.be.true;
    });

    it('Should have a logout method', function() {
      expect(User.logout).to.be.a('function');
    });

    it('Should remove tokens on logout', function() {
      var storage = $window.localStorage;
      storage.setItem('user.authToken', data.authToken);
      storage.setItem('user.username', data.username);

      User.logout();
      expect(storage.getItem('user.authToken')).to.be.null;
      expect(storage.getItem('user.username')).to.be.null;
    });

  });

  describe('User Data Methods', function() {
    var data = {
      username: 'user',
      firstName: 'Guy'
    };

    beforeEach(function() {
      $window.localStorage.setItem('user.username', data.username);
    });

    afterEach(function() {
      $window.localStorage.removeItem('user.username');
    });

    it('Should have a getData method', function() {
      expect(User.getData).to.be.a('function');
    });

    it('Should store tokens in localStorage after signup', function() {
      $httpBackend.expectGET('/api/users/' + data.username).respond({data: data});
      User.getData();
      $httpBackend.flush();
    });

  });
});

/*

  var mapId = '000000000000000000000010';
  var nodeId = '000000000000000000000100';

  User.followRoadmapById(mapId)
  .then(function (user) {
    console.log('Progress on one', User.getRoadmapProgress(user, mapId) );

    return User.completeNodeById(nodeId)
{'fraction_non_alphanumeric': 0.1656245455867384, 'fraction_numerical': 0.013959575396248364, 'mean_word_length': 3.4924885695623775, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '6696042', 'n_tokens_mistral': 2155, 'n_tokens_neox': 2068, 'n_words': 404}