Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems using Ephemeral storage during testing #132

Closed
digitalplaywright opened this issue Apr 8, 2014 · 8 comments
Closed

Problems using Ephemeral storage during testing #132

digitalplaywright opened this issue Apr 8, 2014 · 8 comments
Labels

Comments

@digitalplaywright
Copy link
Contributor

As recommended I am trying to use the Ephemeral storage during testing to make sure that there is no conflict between a non-testing and testing session, and to mock API calls. However, I get this error:

TypeError: Invalid Fullname, expected: `type:name` got: null

when setEphemeralSessionStore is called on https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/tests/acceptance/login-test.js#L6

    App = startApp();
    require('appkit/tests/helpers/signin').setEphemeralSessionStore(App);

where setEphemeralSessionStore is defined in https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/tests/helpers/signin.js#L17

export function setEphemeralSessionStore(app) {
  var session   = app.__container__.lookup('ember-simple-auth:session');
  session.store = Ember.SimpleAuth.Stores.Ephemeral.create();

  app.deferReadiness();
  session.invalidate().then(function () {
    app.advanceReadiness();
  }, "invalidating test session");
}

Can you see if there is a bug or if I am doing something wrong?

@marcoow
Copy link
Member

marcoow commented Apr 8, 2014

Can you provide a backtrace?

Also you should just run the normal Ember.SimpleAuth.setup with the correct store configuration - there should also be no need for the invalidateetc.

@digitalplaywright
Copy link
Contributor Author

So I followed your recommendation and set store in Ember.SimpleAuth.setup in https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/app/initializers/auth.js

    var attribtues = {
      crossOriginWhitelist: [window.ENV.server],
      routeAfterLogin: "index",
      routeAfterLogout: "login"
    };

    if(Ember.testing == true){
      var attributes = Ember.merge({store: Ember.SimpleAuth.Stores.Ephemeral });
    }

    Em.SimpleAuth.setup(container, application,attributes);
    return Em.SimpleAuth.Authenticators.OAuth2.reopen({
      serverTokenEndpoint: window.ENV.server + "/oauth/token"
    });

The error above went away, but there an error is still remaining so I can't know if it is a full fix before that one is fixed.

The other error is triggered in https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/tests/helpers/signin.js on

var session = app.__container__.lookup('ember-simple-auth:session');

  return session.authenticate('authenticator:application', {
    email: userPayload.email,
    accessToken: userPayload.accessToken,
  }).then(wait);

I am getting another error 'TypeError: Cannot call method 'authenticate' of undefined' with the stack trace (does not look that useful):

    at Test.QUnitAdapter.Test.Adapter.extend.exception (http://localhost:8000/vendor/ember/ember.js:42781:5)
    at superWrapper [as exception] (http://localhost:8000/vendor/ember/ember.js:1292:16)
    at Ember.RSVP.onerrorDefault (http://localhost:8000/vendor/ember/ember.js:17180:28)
    at Object.__exports__.default.trigger (http://localhost:8000/vendor/ember/ember.js:8977:13)
    at Promise._onerror (http://localhost:8000/vendor/ember/ember.js:9701:16)
    at publishRejection (http://localhost:8000/vendor/ember/ember.js:10108:17)
    at http://localhost:8000/vendor/ember/ember.js:18379:7
    at Object.DeferredActionQueues.flush (http://localhost:8000/vendor/ember/ember.js:6127:24)

This is starting to look like a user error on my part, but the lookup above on session works in developer mode in the browser so any tips you have on how to fix this is very helpful. Am I missing a dependency in testing? Should this lookup not work in testing?

@marcoow
Copy link
Member

marcoow commented Apr 8, 2014

That means that nothing is registered for 'authenticator:application'. Probably you're not registering that in the test env?

@digitalplaywright
Copy link
Contributor Author

As far as I know I am registering the same in testing as production, because I am using the same initializers. However, maybe there is a problem in the way I call authenticate to begin with. Is there a recommended way to authenticate through a method call in testing?

What I am doing in https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/tests/helpers/signin.js is not very pretty

function signInUser(app, userPayload) {
  userPayload = $.extend({
    email: 'test_user@example.com',
    accessToken: 'please',
  }, userPayload || {});

  var session = app.__container__.lookup('ember-simple-auth:session');
  return session.authenticate('authenticator:application', {
    email: userPayload.email,
    accessToken: userPayload.accessToken,
  })
}

@marcoow
Copy link
Member

marcoow commented Apr 8, 2014

The recommended way would be to trigger your route action with valid credentials (e.g. LoginControllerMixin's authenticate action) and stub the server response.

@digitalplaywright
Copy link
Contributor Author

Do you know of an example showing how to do this? I know of several developers that are having trouble with this particular aspect so I don't know where to get help and I am yet to bridge the gap to a working example test using mocking with ember simple auth.

@marcoow
Copy link
Member

marcoow commented Apr 8, 2014

Have a look at this for example: https://github.com/ugisozols/ember-simple-auth-rails-demo/blob/master/test/javascripts/integration/login_test.js. When you stub the server response and wrap that in a test helper you probably have what you are looking for.

I'm closing this as it doesn't seem to be an issues with Ember.SimpleAuth. Please ask further questions on stack overflow.com so this is only used for issues.

@marcoow marcoow closed this as completed Apr 8, 2014
@digitalplaywright
Copy link
Contributor Author

I submitted a question on the subject here:

There was no ember-simple-auth tag so I am not sure how to notify you of this question other than commenting here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants