<commit_before>/* Tester for App */

var clientenv = require('../helpers/helper.spec.js'),
    should = require('should'),
    sinon = require('sinon');

describe('userModel', function() {

  var User;

  beforeEach(function(done) {
    clientenv.setup(function() {
      UserModel = require(appDir + 'users/userModel.js');

      fbStub = sinon.stub(global, 'Firebase');
      loginStub = sinon.stub(global, 'FirebaseSimpleLogin');

      // Fake mixpanel object
      global.mixpanel = {
        identify: sinon.stub().returns('123'),
        people: {
          set: function(data) {
            return(data);
          }
        }
      };

      done();
    });
  });

  afterEach(function() {
    fbStub.restore();
    loginStub.restore();
  });

  describe('loads the model', function() {
    it('without errors', function() {
      should.exist(UserModel);

      userModel = new UserModel();
      should.exist(userModel);
    });
  });

  describe('connects to Firebase', function() {
    it('loads Firebase with a URL', function() {
      app.fbUrl = 'http://blah.com';
      
      fbStub.calledOnce.should.be.false;
      userModel = new UserModel();

      fbStub.calledOnce.should.be.true;
      fbStub.getCall(0).args[0].should.equal(app.fbUrl);  // Firebsae has been called w/ URL
    });

    it('loads Firebase-Simple-Login', function() {
      loginStub.calledOnce.should.be.false;
      userModel = new UserModel();
      loginStub.calledOnce.should.be.true;  // Auth has been called
    });

  });

  describe('User signed out', function() {
    it('User can login', function() {
    });
  });

  describe('User signed in', function() {
    it('Should remain logged in', function() {
      // Input
      var input = {
        displayName: '<NAME>',
        profile_image_url_https: 'http://blah.com/img.jpg',
        lastLogin: new Date(),
        username: 'username',
        loggedIn: true
      };

      loginStub.yields(null, input);  // FirebaseSimpleLogin will generate a callback which contains these two parameters

      userModel = new UserModel();

      input.displayName.should.equal(userModel.get('displayName'));
      input.profile_image_url_https.should.equal(userModel.get('profileImage'));
      should.exist(userModel.get('lastLogin')); // Time is not always synced
      input.username.should.equal(userModel.get('username'));
      input.loggedIn.should.equal(userModel.get('loggedIn'));
    });

    it('User can log out', function() {

      // stub out app.auth.logout
      loginStub.prototype.logout = function() {
        // Fake out logout actions (wipe user)
        console.log('got here');
      };
      // logout should trigger FirebaseSimpleLogin constructor again
      // expect model to be empty
      userModel = new UserModel();
      userModel.logout();

    });
  });<commit_msg>Gave up on testing logout for now :x<commit_after>/* Tester for App */

var clientenv = require('../helpers/helper.spec.js'),
    should = require('should'),
    sinon = require('sinon');

describe('userModel', function() {

  var User;

  beforeEach(function(done) {
    clientenv.setup(function() {
      UserModel = require(appDir + 'users/userModel.js');

      fbStub = sinon.stub(global, 'Firebase');
      loginStub = sinon.stub(global, 'FirebaseSimpleLogin');

      // Fake mixpanel object
      global.mixpanel = {
        identify: sinon.stub().returns('123'),
        people: {
          set: function(data) {
            return(data);
          }
        }
      };

      done();
    });
  });

  afterEach(function() {
    fbStub.restore();
    loginStub.restore();
  });

  describe('loads the model', function() {
    it('without errors', function() {
      should.exist(UserModel);

      userModel = new UserModel();
      should.exist(userModel);
    });
  });

  describe('connects to Firebase', function() {
    it('loads Firebase with a URL', function() {
      app.fbUrl = 'http://blah.com';
      
      fbStub.calledOnce.should.be.false;
      userModel = new UserModel();

      fbStub.calledOnce.should.be.true;
      fbStub.getCall(0).args[0].should.equal(app.fbUrl);  // Firebsae has been called w/ URL
    });

    it('loads Firebase-Simple-Login', function() {
      loginStub.calledOnce.should.be.false;
      userModel = new UserModel();
      loginStub.calledOnce.should.be.true;  // Auth has been called
    });

  });

  describe('User signed out', function() {
    it('User can login', function() {
    });
  });

  describe('User signed in', function() {
    it('Should remain logged in', function() {
      // Input
      var input = {
        displayName: '<NAME>',
        profile_image_url_https: 'http://blah.com/img.jpg',
        lastLogin: new Date(),
        username: 'username',
        loggedIn: true
      };

      loginStub.yields(null, input);  // FirebaseSimpleLogin will generate a callback which contains these two parameters

      userModel = new UserModel();

      input.displayName.should.equal(userModel.get('displayName'));
      input.profile_image_url_https.should.equal(userModel.get('profileImage'));
      should.exist(userModel.get('lastLogin')); // Time is not always synced
      input.username.should.equal(userModel.get('username'));
      input.loggedIn.should.equal(userModel.get('loggedIn'));
    });

    it('User can log out', function() {
      // userModel.logout successfully triggers FirebaseSimpleLogin.logout()

      // stub out app.auth.logout
      loginStub.prototype.logout = function() {
        // Fake out logout actions (wipe user)
      };
      
      //Input
      var input = {
        displayName: '<NAME>',
        profile_image_url_https: 'http://blah.com/img.jpg',
        lastLogin: new Date(),
        username: 'username',
        loggedIn: true
      };

      // Create a new model as if we were logged in
      userModel = new UserModel(input);

      logoutSpy = sinon.spy(loginStub);

      userModel.logout();
      // slogoutSpy.calledOnce.should.equal(true);
    });
  });
{'fraction_non_alphanumeric': 0.1477366937489637, 'fraction_numerical': 0.00165809981760902, 'mean_word_length': 2.556603773584906, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '2854526', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1811, 'n_words': 379}