<commit_before>import { Devise } from 'ember-simple-auth-devise/authenticators/devise';

describe('Devise', function() {
  beforeEach(function() {
    this.authenticator = Devise.create();
  });

  describe('#restore', function() {
    beforeEach(function() {
      this.xhr                = sinon.useFakeXMLHttpRequest();
      this.server             = sinon.fakeServer.create();
      this.server.autoRespond = true;
      sinon.spy($, 'ajax');

      this.server.respondWith('POST', '/users/sign_in', [
        201,
        { 'Content-Type': 'application/json' },
        '{ "auth_token": "secret token!" }'
      ]);
    });

    describe('when the data contains an auth_token and auth_email', function() {
      it('resolves with the correct data', function(done) {
        this.authenticator.restore({ "auth_token": 'secret token!', "auth_email": "<EMAIL>" }).then(function(content){
          expect(content).to.eql({ "auth_token": "secret token!", "auth_email": "<EMAIL>" });
          done();
        });
      });
    });

    afterEach(function() {
      this.xhr.restore();
      $.ajax.restore();
    });
  });

  describe('#authenticate', function() {
    beforeEach(function() {
      this.xhr                = sinon.useFakeXMLHttpRequest();
      this.server             = sinon.fakeServer.create();
      this.server.autoRespond = true;
      sinon.spy(Ember.$, 'ajax');
    });

    describe('when the authentication request is successful', function() {
      beforeEach(function() {
        this.server.respondWith('POST', '/users/sign_in', [
          201,
          { 'Content-Type': 'application/json' },
          '{ "access_token": "secret token!" }'
        ]);
      });

      it('resolves with the correct data', function(done) {
        this.authenticator.authenticate({ email: '<EMAIL>', password: 'password' }).then(function(data) {
          expect(true).to.be.true;
          expect(data).to.eql({ access_token: 'secret token!' });
          done();
        });
      });
    });

    describe('when the authentication request has remember_me set to true', function() {
      beforeEach(function() {
        this.server.respondWith('POST', '/users/sign_in', [
          201,
          { 'Content-Type': 'application/json' },
          '{ "access_token": "secret <PASSWORD>!", "auth_token": "remember" }'
        ]);
      });

      it('resolves with the correct data', function(done) {
        this.authenticator.authenticate({ email: '<EMAIL>', password: 'password', remember_me: true }).then(function(data) {
          expect(true).to.be.true;
          expect(data).to.eql({ access_token: 'secret <PASSWORD>!', auth_token: 'remember' });
          done();
        });
      });
    });

    describe('when the authentication request fails', function() {
      beforeEach(function() {
        this.server.respondWith('POST', '/users/sign_in', [
          400,
          { 'Content-Type': 'application/json' },
          '{ "error": "invalid_grant" }'
        ]);
      });

      it('rejects with the correct error', function(done) {
        this.authenticator.authenticate({ email: '<EMAIL>', password: 'password' }).then(null, function(error) {
          expect(error).to.eql('{ "error": "invalid_grant" }');
          done();
        });
      });
    });

    afterEach(function() {
      this.xhr.restore();
      Ember.$.ajax.restore();
    });
  });

  describe('#invalidate', function() {<commit_msg>fixed test<commit_after>import { Devise } from 'ember-simple-auth-devise/authenticators/devise';

describe('Devise', function() {
  beforeEach(function() {
    this.authenticator = Devise.create();
  });

  describe('#restore', function() {
    beforeEach(function() {
      this.xhr                = sinon.useFakeXMLHttpRequest();
      this.server             = sinon.fakeServer.create();
      this.server.autoRespond = true;
      sinon.spy($, 'ajax');

      this.server.respondWith('POST', '/users/sign_in', [
        201,
        { 'Content-Type': 'application/json' },
        '{ "auth_token": "secret token!" }'
      ]);
    });

    describe('when the data contains an auth_token and auth_email', function() {
      it('resolves with the correct data', function(done) {
        this.authenticator.restore({ "auth_token": 'secret token!', "auth_email": "<EMAIL>" }).then(function(content){
          expect(content).to.eql({ "auth_token": "secret token!", "auth_email": "<EMAIL>" });
          done();
        });
      });
    });

    afterEach(function() {
      this.xhr.restore();
      $.ajax.restore();
    });
  });

  describe('#authenticate', function() {
    beforeEach(function() {
      this.xhr                = sinon.useFakeXMLHttpRequest();
      this.server             = sinon.fakeServer.create();
      this.server.autoRespond = true;
      sinon.spy(Ember.$, 'ajax');
    });

    describe('when the authentication request is successful', function() {
      beforeEach(function() {
        this.server.respondWith('POST', '/users/sign_in', [
          201,
          { 'Content-Type': 'application/json' },
          '{ "access_token": "secret token!" }'
        ]);
      });

      it('resolves with the correct data', function(done) {
        this.authenticator.authenticate({ email: '<EMAIL>', password: 'password' }).then(function(data) {
          expect(true).to.be.true;
          expect(data).to.eql({ access_token: 'secret token!' });
          done();
        });
      });
    });

    describe('when the authentication request has remember_me set to true', function() {
      beforeEach(function() {
        this.server.respondWith('POST', '/users/sign_in', [
          201,
          { 'Content-Type': 'application/json' },
          '{ "access_token": "secret token!", "auth_token": "remember" }'
        ]);
      });

      it('resolves with the correct data', function(done) {
        this.authenticator.authenticate({ email: '<EMAIL>', password: 'password', remember_me: true }).then(function(data) {
          expect(true).to.be.true;
          expect(data).to.eql({ access_token: '<PASSWORD>!', auth_token: '<PASSWORD>' });
          done();
        });
      });
    });

    describe('when the authentication request fails', function() {
      beforeEach(function() {
        this.server.respondWith('POST', '/users/sign_in', [
          400,
          { 'Content-Type': 'application/json' },
          '{ "error": "invalid_grant" }'
        ]);
      });

      it('rejects with the correct error', function(done) {
        this.authenticator.authenticate({ email: '<EMAIL>', password: 'password' }).then(null, function(error) {
          expect(error).to.eql({ "error": "invalid_grant" });
          done();
        });
      });
    });

    afterEach(function() {
      this.xhr.restore();
      Ember.$.ajax.restore();
    });
  });

  describe('#invalidate', function() {
{'fraction_non_alphanumeric': 0.17774545454545454, 'fraction_numerical': 0.003490909090909091, 'mean_word_length': 2.4639798488664986, 'pattern_counts': {'":': 20, '<': 17, '<?xml version=': 0, '>': 17, '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': '6648414', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1987, 'n_words': 368}