forked from mainmatter/ember-simple-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored FastBoot tests (mainmatter#1391)
Use ember-fastboot-addon-tests, removes some boilerplate, works with latest FastBoot. Fixes mainmatter#1097 and mainmatter#1371
- Loading branch information
1 parent
00f0e94
commit 98a4b3c
Showing
4 changed files
with
473 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,17 @@ | ||
/* global describe, before, after, it */ | ||
/* jshint node:true */ | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var RSVP = require('rsvp'); | ||
var AddonTestApp = require('ember-cli-addon-tests').AddonTestApp; | ||
var request = require('request'); | ||
var request = RSVP.denodeify(request); | ||
'use strict'; | ||
|
||
describe('Graceful regression tests', function() { | ||
this.timeout(600000); | ||
|
||
var app; | ||
var url = 'http://localhost:49741'; | ||
|
||
before(function() { | ||
app = new AddonTestApp(); | ||
return app.create('not-fastboot-ready-app', { fixturesPath: 'fastboot-tests/fixtures/' }) | ||
.then(addDependencies) | ||
.then(function() { | ||
return app.runEmberCommand('build'); | ||
}) | ||
.then(function() { | ||
return app.startServer({ | ||
command: 'fastboot', | ||
additionalArguments: ['--host 0.0.0.0'] | ||
}); | ||
}); | ||
}); | ||
const expect = require('chai').expect; | ||
const setupTest = require('ember-fastboot-addon-tests').setupTest; | ||
|
||
after(function() { | ||
return app.stopServer(); | ||
}); | ||
describe('Graceful regression tests', function() { | ||
setupTest('not-fastboot-ready-app'); | ||
|
||
it('does not error when using the adaptive store', function() { | ||
return request({ url: url + '/protected' }) | ||
.then(function(response) { | ||
return this.visit('/protected') | ||
.then(function({ response }) { | ||
|
||
expect(response.headers['set-cookie']).to.deep.equal(['ember_simple_auth-session=%7B%22authenticated%22%3A%7B%7D%7D; path=/']) | ||
expect(response.req.path).to.equal('/login'); | ||
}); | ||
}); | ||
}); | ||
|
||
function addDependencies(app) { | ||
app.editPackageJSON(function(pkg) { | ||
pkg['devDependencies']['ember-cli-fastboot'] = "1.0.0-beta.19"; | ||
}); | ||
return app.run('npm', 'install'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,49 @@ | ||
/* global describe, before, after, it */ | ||
/* jshint node:true */ | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var RSVP = require('rsvp'); | ||
var AddonTestApp = require('ember-cli-addon-tests').AddonTestApp; | ||
var request = require('request'); | ||
var request = RSVP.denodeify(request); | ||
'use strict'; | ||
|
||
describe('Integration tests', function() { | ||
this.timeout(600000); | ||
|
||
var app; | ||
var url = 'http://localhost:49741'; | ||
|
||
before(function() { | ||
app = new AddonTestApp(); | ||
return app.create('fastboot-ready-app', { fixturesPath: 'fastboot-tests/fixtures/' }) | ||
.then(addDependencies) | ||
.then(function() { | ||
return app.runEmberCommand('build'); | ||
}) | ||
.then(function() { | ||
return app.startServer({ | ||
command: 'fastboot', | ||
additionalArguments: ['--host 0.0.0.0'] | ||
}); | ||
}); | ||
}); | ||
const expect = require('chai').expect; | ||
const setupTest = require('ember-fastboot-addon-tests').setupTest; | ||
|
||
after(function() { | ||
return app.stopServer(); | ||
}); | ||
describe('Integration tests', function() { | ||
setupTest('fastboot-ready-app'); | ||
|
||
it('redirects to login page on a protected route', function() { | ||
return request({ url: url + '/protected' }) | ||
.then(function(response) { | ||
return this.visit('/protected') | ||
.then(function({ response }) { | ||
|
||
expect(response.headers['set-cookie']).to.deep.equal(['ember_simple_auth-session=%7B%22authenticated%22%3A%7B%7D%7D; path=/']) | ||
expect(response.req.path).to.equal('/login'); | ||
}); | ||
}); | ||
|
||
it('authenticates and create the session when accessing authenticate route', function() { | ||
return request({ url: url + '/authenticate', jar: true }) | ||
.then(function(response) { | ||
return this.visit({ url: '/authenticate', jar: true }) | ||
.then(function({ response }) { | ||
|
||
expect(response.headers['set-cookie']).to.deep.equal(['ember_simple_auth-session=%7B%22authenticated%22%3A%7B%22authenticator%22%3A%22authenticator%3Aauth%22%2C%22account_id%22%3A%22123%22%7D%7D; path=/']) | ||
expect(response.req.path).to.equal('/'); | ||
}); | ||
}); | ||
|
||
it('user can access protected page after authentication', function() { | ||
return request({ url: url + '/protected', jar: true }) | ||
.then(function(response) { | ||
return this.visit({ url: '/protected', jar: true }) | ||
.then(function({ response }) { | ||
expect(response.req.path).to.equal('/protected'); | ||
expect(response.body).to.contain('This is a protected page only visible to authenticated users!'); | ||
}); | ||
}); | ||
|
||
it('invalidate removes session cookies', function() { | ||
return request({ url: url + '/invalidate', jar: true }) | ||
.then(function(response) { | ||
return this.visit({ url: '/invalidate', jar: true }) | ||
.then(function({ response }) { | ||
expect(response.req.path).to.equal('/'); | ||
expect(response.headers['set-cookie']).to.deep.equal(['ember_simple_auth-session=%7B%22authenticated%22%3A%7B%7D%7D; path=/']) | ||
}); | ||
}); | ||
|
||
it('implicit grant callback route works with FastBoot', function() { | ||
return request({ url: url + '/callback', jar: true }) | ||
.then(function(response) { | ||
return this.visit({ url: '/callback', jar: true }) | ||
.then(function({ response }) { | ||
expect(response.statusCode).to.equal(200); | ||
}); | ||
}); | ||
}); | ||
|
||
function addDependencies(app) { | ||
app.editPackageJSON(function(pkg) { | ||
pkg['devDependencies']['ember-cli-fastboot'] = "1.0.0-beta.19"; | ||
}); | ||
return app.run('npm', 'install'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.