<commit_before>import Ember from 'ember';
import startApp from '../helpers/start-app';

var App, server;
var user = {
  reset_password_token: '<PASSWORD>',
  password: '<PASSWORD>'
};

function parsePostData(query) {
  var result = {};
  query.split("&").forEach(function(part) {
    var item = part.split("=");
    result[item[0]] = decodeURIComponent(item[1]);
  });
  return result;
}

function httpResponse(code, headers, body) {
  return [
    code,
    {'Content-Type': headers},
    JSON.stringify(body)
  ];
}

module('Integration - Password Reset', {
  setup: function() {
    var auth_token = {"authenticity_token":"<KEY>};
    App = startApp();
    server = new Pretender(function() {
      this.get('api/csrf', function(request) {
        return [200, {'Content-Type': 'application/json'}, JSON.stringify(auth_token)];
      });

      this.put('/api/users/update_password', function(request) {
        var data = parsePostData(request.requestBody);
        if (data.reset_password_token === user.reset_password_token) {
          return httpResponse(200, 'application/json', {});
        } else {
          return httpResponse(400, 'application/json', {});
        }
      });
    });
  },
  teardown: function() {
    Ember.run(App, 'destroy');
    server.shutdown();
  }
});

test ('should be able to reset password', function() {
  visit('/password_reset?token=' + user.reset_password_token);
  fillIn('input.password', user.password);
  fillIn('input.password-confirmation', user.password);
  click('button.submit');

  andThen(function() {
    equal(find('.alert').text(), 'Successfully changed password');
  });
});


<commit_msg>Fixed broken password reset test<commit_after>import Ember from 'ember';
import startApp from '../helpers/start-app';

var App, server;
var USER = {
  reset_password_token: '<PASSWORD>',
  password: '<PASSWORD>',
  raw_token: '<PASSWORD>'
};

function parsePostData(query) {
  var result = {};
  var decoded = decodeURIComponent(query);
  decoded.split('&').forEach(function(part) {
    var item = part.split('=');
    result[item[0]] = item[1];
  });
  return result;
}

function httpResponse(code, headers, body) {
  return [
    code,
    {'Content-Type': headers},
    JSON.stringify(body)
  ];
}

function isValidResetToken(rawToken, user) {
  if (rawToken === user.raw_token) {
    return true;
  } else {
    return false;
  }
}

module('Integration - Password Reset', {
  setup: function() {
    var auth_token = {"authenticity_token":"<KEY>};
    App = startApp();
    server = new Pretender(function() {
      this.get('api/csrf', function(request) {
        return [200, {'Content-Type': 'application/json'}, JSON.stringify(auth_token)];
      });

      this.put('/api/users/update_password', function(request) {
        var data = parsePostData(request.requestBody);

        if (isValidResetToken(data["user[reset_password_token]"], USER)) {
          return httpResponse(200, 'application/json', {});
        } else {
          return httpResponse(400, 'application/json', {});
        }
      });
    });
  },
  teardown: function() {
    Ember.run(App, 'destroy');
    server.shutdown();
  }
});

test ('should be able to reset password', function() {
  visit('/password_reset?token=' + USER.raw_token);
  fillIn('input.password', <PASSWORD>);
  fillIn('input.password-confirmation', <PASSWORD>.password);
  click('button.submit');

  andThen(function() {
    equal(find('.alert').text(), 'Successfully changed password');
  });
});



{'fraction_non_alphanumeric': 0.17366466723793203, 'fraction_numerical': 0.006283918880319908, 'mean_word_length': 3.620052770448549, 'pattern_counts': {'":': 2, '<': 12, '<?xml version=': 0, '>': 12, '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': '6189176', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1092, 'n_words': 216}