Integration tests with model-specific routes


#1

Hey all! Had an interesting issue I’m running into when trying to create integration tests for my application, specifically when trying to use visit(). My situation is this: this ember app requires that I have “friendly,” readable URLs that correspond to models currently available to my ember application. For instance, instead of having a URL be /organizations/[id], I’m mapping the URL to the name of the organization as /:orgname. To illustrate, here’s the relevant code from my organization route:

import Ember from "ember";

var OrganizationRoute = Ember.Route.extend({
  model: function(params) {
    // Attach the organization slug to the Ember object for use in the product route
    Ember.organizationSlug = params.organization_slug;
    return this.store.find('organization', {slug: params.organization_slug});
  },
  ...
});

export default OrganizationRoute;

This makes unit testing a bit difficult as when I call visit('URL goes here'), tests will only pass if I send the test to a URL a valid model that has been created and saved. I don’t want my integration tests to be dependent on the dynamic and surely changing data it will receive from a REST API.

My first thought was to create an organization in the integration test, but that doesn’t seem to be working as var store = this.store(); inside of an integration test (in Ember CLI) is returning undefined. Has anyone run into this before? How did you handle it?

Many thanks,

Jeff