<commit_before>'use strict';

var assert = require('assert');
var async = require('async');
var cheerio = require('cheerio');
var fs = require('fs');
var request = require('supertest');
var uuid = require('uuid');

var helpers = require('../helpers');

describe('register', function() {
  var stormpathApplication;
  var stormpathClient;

  var existingUserData = {
    givenName: uuid.v4(),
    surname: uuid.v4(),
    email: 'robert+' + uuid.v4() + '@stormpath.<EMAIL>',
    password: <PASSWORD>() + uuid.v4().toUpperCase() + '!'
  };

  before(function(done) {
    stormpathClient = helpers.createClient();
    helpers.createApplication(stormpathClient, function(err, app) {
      if (err) {
        return done(err);
      }

      stormpathApplication = app;
      app.createAccount(existingUserData, done);
    });
  });

  after(function(done) {
    helpers.destroyApplication(stormpathApplication, done);
  });

  it('should bind to GET /register if enabled', function(done) {
    var app = helpers.createStormpathExpressApp({
      application: {
        href: stormpathApplication.href
      },
      web: {
        register: {
          enabled: true
        }
      }
    });

    app.on('stormpath.ready', function() {
      request(app)
        .get('/register')
        .expect(200)
        .end(function(err) {
          done(err);
        });
    });
  });

  it('should bind to POST /register if enabled', function(done) {
    var app = helpers.createStormpathExpressApp({
      application: {
        href: stormpathApplication.href
      },
      web: {
        register: {
          enabled: true
        }
      }
    });

    app.on('stormpath.ready', function() {
      request(app)
        .post('/register')
        .end(function(err, res) {
          assert.notEqual(res.statusCode, 404);
          done(err);
        });
    });
  });

  it('should bind to another URL if specified', function(done) {
    var app = helpers.createStormpathExpressApp({
      application: {
        href: stormpathApplication.href
      },
      web: {
        register: {
          enabled: true,
          uri: '/newregister'
        }
      }
    });

    app.on('stormpath.ready', function() {
      async.parallel([
        function(cb) {
          request(app)
            .get('/newregister')
            .expect(200)
            .end(cb);
        },
        function(cb) {
          request(app)
            .get('/register')
            .expect(404)
            .end(cb);
        }
      ], done);
    });
  });

  describe('via JSON API', function() {
    it('should trigger JSON responses if an accept: application/json header is provided', function(done) {
      var app = helpers.createStormpathExpressApp({
        application: {
          href: stormpathApplication.href
        },
        web: {
          register: {
            enabled: true
          }
        }
      });

      app.on('stormpath.ready', function() {
        request(app)
          .post('/register')
          .set('Accept', 'application/json')
          .expect(400)
          .end(function(err, res) {
            if (err) {
              return done(err);
            }

            var json = JSON.parse(res.text);
            if (!json.error) {
              return done(new Error('No JSON error returned.'));
            }

            done();
          });
      });
    });

    it('should return a JSON error if the account data is not valid', function(done) {
      async.series([
        function(cb) {
          var app = helpers.createStormpathExpressApp({
            application: {
              href: stormpathApplication.href
            },
            web: {
              register: {<commit_msg>Removing redundant test<commit_after>'use strict';

var assert = require('assert');
var async = require('async');
var cheerio = require('cheerio');
var fs = require('fs');
var request = require('supertest');
var uuid = require('uuid');

var helpers = require('../helpers');

describe('register', function() {
  var stormpathApplication;
  var stormpathClient;

  var existingUserData = {
    givenName: uuid.v4(),
    surname: uuid.v4(),
    email: '<EMAIL>+' + uuid.v4() + '@stor<EMAIL>',
    password: uuid.v4() + uuid.v4().toUpperCase() + '!'
  };

  before(function(done) {
    stormpathClient = helpers.createClient();
    helpers.createApplication(stormpathClient, function(err, app) {
      if (err) {
        return done(err);
      }

      stormpathApplication = app;
      app.createAccount(existingUserData, done);
    });
  });

  after(function(done) {
    helpers.destroyApplication(stormpathApplication, done);
  });

  it('should bind to GET /register if enabled', function(done) {
    var app = helpers.createStormpathExpressApp({
      application: {
        href: stormpathApplication.href
      },
      web: {
        register: {
          enabled: true
        }
      }
    });

    app.on('stormpath.ready', function() {
      request(app)
        .get('/register')
        .expect(200)
        .end(function(err) {
          done(err);
        });
    });
  });

  it('should bind to POST /register if enabled', function(done) {
    var app = helpers.createStormpathExpressApp({
      application: {
        href: stormpathApplication.href
      },
      web: {
        register: {
          enabled: true
        }
      }
    });

    app.on('stormpath.ready', function() {
      request(app)
        .post('/register')
        .end(function(err, res) {
          assert.notEqual(res.statusCode, 404);
          done(err);
        });
    });
  });

  it('should bind to another URL if specified', function(done) {
    var app = helpers.createStormpathExpressApp({
      application: {
        href: stormpathApplication.href
      },
      web: {
        register: {
          enabled: true,
          uri: '/newregister'
        }
      }
    });

    app.on('stormpath.ready', function() {
      async.parallel([
        function(cb) {
          request(app)
            .get('/newregister')
            .expect(200)
            .end(cb);
        },
        function(cb) {
          request(app)
            .get('/register')
            .expect(404)
            .end(cb);
        }
      ], done);
    });
  });

  describe('via JSON API', function() {

    it('should return a JSON error if the account data is not valid', function(done) {
      async.series([
        function(cb) {
          var app = helpers.createStormpathExpressApp({
            application: {
              href: stormpathApplication.href
            },
            web: {
              register: {
{'fraction_non_alphanumeric': 0.14102176541717049, 'fraction_numerical': 0.005441354292623942, 'mean_word_length': 1.8983793254489707, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3290828', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1895, 'n_words': 393}