This is from my experience of setting up ESA at the weekend. It could be that my solutions are not the best, or that the problems are covered in the docs and I just didn't read thoroughly enough.
Setting up log in redirects import Route from '@ember/routing/route';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
import { mock } from 'ember-data-factory-guy';
test('after successful login the user is redirected to the dashboard', async function(assert) {
mock({
type: 'POST',
url: '/token',
responseText: { access_token: 'rubbish' }
});
await visit('/login');
await click('[data-test-login-button]');
assert.equal(currentURL(), '/dashboard', 'The user is redirected to dashboard after login');
});
This is from my experience of setting up ESA at the weekend. It could be that my solutions are not the best, or that the problems are covered in the docs and I just didn't read thoroughly enough.
Setting up log in redirects import Route from '@ember/routing/route'; import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
OR
But the latter causes issues in the test, it’s not up to date. Far simpler to use the mixin and override that property.
The already authenticated redirect
Testing - mock already logged in for your protected routes
Easy when you know it.
Testing - respond to login correctly in test