Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Fix tests that aren’t cleaning up resources
Browse files Browse the repository at this point in the history
Most of these were my fault :)

I also added the package name and a per-process uuid to the application
name, so that (a) I could see how many apps were being leftover per
run and (b) so that others can know that this is our library
  • Loading branch information
Robert committed Oct 15, 2015
1 parent dc34dae commit 3cb839a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 43 deletions.
43 changes: 3 additions & 40 deletions test/controllers/test-register.js
Expand Up @@ -758,52 +758,15 @@ describe('register', function() {
});

it('should return the user to the login page with ?status=unverified if the account is unverified', function(done) {
var application;
var client = helpers.createClient();

async.series([
function(callback) {
client.createApplication({ name: uuid.v4() }, { createDirectory: true }, function(err, app) {
if (err) {
return callback(err);
}

application = app;
callback();
});
},
function(callback) {
application.getDefaultAccountStore(function(err, mapping) {
if (err) {
return callback(err);
}

mapping.getAccountStore(function(err, store) {
if (err) {
return callback(err);
}

store.getAccountCreationPolicy(function(err, policy) {
if (err) {
return callback(err);
}

policy.verificationEmailStatus = 'ENABLED';
policy.save(function(err) {
if (err) {
return callback(err);
}

callback();
});
});
});
});
helpers.setEmailVerificationStatus(stormpathApplication,'ENABLED',callback);
},
function(callback) {
var app = helpers.createStormpathExpressApp({
application: {
href: application.href
href: stormpathApplication.href
},
web: {
register: {
Expand Down Expand Up @@ -837,7 +800,7 @@ describe('register', function() {
});
}
], function(err) {
done(err);
helpers.setEmailVerificationStatus(stormpathApplication,'DISABLED',done);
});
});

Expand Down
4 changes: 4 additions & 0 deletions test/handlers/test-me.js
Expand Up @@ -48,6 +48,10 @@ describe('current user (/me) route',function() {
});
});

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

it('should respond with the expanded account object',function(done){
prepateMeTestFixture(stormpathApplication,function(fixture){
var agent = request.agent(fixture.expressApp);
Expand Down
4 changes: 4 additions & 0 deletions test/handlers/test-post-login-handler.js
Expand Up @@ -70,6 +70,10 @@ describe('Post-Login Handler',function() {
});
});

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

describe('with a JSON post',function(){

it('should be given the expanded account object',function(done){
Expand Down
4 changes: 4 additions & 0 deletions test/handlers/test-post-registration-handler.js
Expand Up @@ -102,6 +102,10 @@ describe('Post-Registration Handler',function() {
});
});

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

describe('with a JSON post',function(){

it('should be given the expanded account object',function(done){
Expand Down
6 changes: 5 additions & 1 deletion test/helpers.js
Expand Up @@ -8,6 +8,10 @@ var stormpathExpress = require('../');

var express = require('express');

var pkg = require('../package.json');

var testRunId = uuid.v4().split('-')[0];

/**
* Build a new Stormpath Client for usage in tests.
*
Expand Down Expand Up @@ -46,7 +50,7 @@ module.exports.newUser = function() {
* @param {Object} application - The initialized Stormpath Application object.
*/
module.exports.createApplication = function(client, callback) {
var appData = { name: uuid.v4() };
var appData = { name: pkg.name + ':' + testRunId + ':' + uuid.v4() };
var opts = { createDirectory: true };

client.createApplication(appData, opts, callback);
Expand Down
4 changes: 2 additions & 2 deletions test/test-stormpath.js
Expand Up @@ -23,7 +23,7 @@ describe('#init()', function() {

var app = helpers.createStormpathExpressApp({ application: { href: application.href } });
app.on('stormpath.ready', function() {
done();
helpers.destroyApplication(application, done);
});
});
});
Expand All @@ -48,7 +48,7 @@ describe('#init()', function() {

var app = helpers.createStormpathExpressApp({ application: { href: application.href } });
app.on('stormpath.ready', function() {
done();
helpers.destroyApplication(application, done);
});
});
});
Expand Down

0 comments on commit 3cb839a

Please sign in to comment.