vendredi 6 mars 2015

Testing sessions with ember-cli-simple-auth-testing

I have an app that uses ember-cli-simple-auth. I've set up ember-cli-simple-auth-testing, but the session information is empty. How do I go about adding information to the current session?


All of the failing tests use this property:



// controllers/current-user.js
currentUser: function() {
return this.get('session.account');
}.property('session.account')


This is a failing test:



module('Integration - Favorites', {
beforeEach: function() {
App = startApp();
server = setupPretender(); // a helper that sets up Pretender
authenticateSession();
},
afterEach: function() {
Ember.run(App, 'destroy');
server.shutdown();
}
});

test('user can favorite a project', function(assert) {
visit('/collaborate');
click('.favorite');

andThen(function() {
// asserts that there is a span with the class .fa-star
});
});


This is the code it tests:



// controllers.projects.js
actions: {
updateFavorites: function(id, isSelected) {
var user = this.get('currentUser'); // this is defined in the app, but not during tests
user.then(function(user) {
var favorites = user.get('favorites');

if (isSelected) {
favorites.pushObject(id);
} else {
favorites.removeObject(id);
}

user.set('favorites', favorites);
user.save();
});
}
}


When I run that test, I get this error message:



not ok 1 PhantomJS 1.9 - Integration - Favorites: user can favorite a project
---
actual: >
false
expected: >
true
message: >
TypeError: 'undefined' is not an object (evaluating 'user.then')
Log: >
...


I saw that there is a helper in ember-simple-auth-testing called currentSession, but if I try to add it, I get ReferenceError: currentSession is not defined.


How would I set the test's session? Why is the currentSession function not available?


Versions:



ember: 1.10.0
ember-cli: 0.1.12
ember-cli-simple-auth: 0.6.7 (also tried 0.7.3)
ember-cli-simple-auth-testing: 0.6.7 (also tried 0.7.3)
node: 0.10.33
npm: 2.1.6




Aucun commentaire:

Enregistrer un commentaire