0

I'm writing some tests where I create a bunch of objects which rely on each other. My code looks like:

let translations =
        [server.create('translation', { key: 'positive.callRating', value: 'How would you rate your call with %agentFirstName%?' }),
         server.create('translation', { key: 'negative.sorry', value: 'What could %agentFirstName% have done better?' }),
         server.create('translation', { key: 'social.ratingGiven', value: 'I just rated %agentFirstName% %stars%!' })];

let profile = server.create('profile', { first_name: 'Andy' });
let employee = server.create('employee', { profile: profile });
let company = server.create('company', { handle: 'lendingtree', translations: translations });
let bootstrap = server.create('bootstrap', { stars: 5, company: company, employee: employee });

And I have a service which is supposed to know about some of these objects. When I call:

this.get('store').peekAll('translation')

from the service I get no results, but all of my other objects, retrieved the same way, exist in the store; profile ,employee, company and bootstrap.

I'm sure I have to tweak my model or serializer or factory somehow to make this work but it'd be more useful to know about the fundamentals.

What causes an object created via Mirage to enter the store? Are there certain requirements they must meet? Does it depend on their relation to other objects?

  • Have you set up your mirage route to return the models when it receives a request? http://www.ember-cli-mirage.com/docs/v0.1.x/defining-routes/ – Casey Mar 01 '16 at 06:44

1 Answers1

2

server.create will make objects in Mirage's database. Mirage's server is a mock server, so it knows absolutely nothing about your app; all it knows how to do is respond to HTTP requests. That means in order to get the mock data into your Ember app, your app needs to make HTTP requests, typically via store.findAll.

So, in an acceptance test, when you visit(/some/path), the model hook for that path will make a GET request, Mirage will respond with the appropriate data, and then you'll have data in your store.

Sam Selikoff
  • 12,366
  • 13
  • 58
  • 104
  • Thanks, that was the missing piece of the puzzle. Most of the other data is being loaded because I make a call to load the bootstrap and it has those objects embedded. It helps to know there is no direct relation. – TwoLeggedMammal Mar 01 '16 at 16:00