lundi 29 février 2016

Ember CLI + Mirage: When are objects saved to the store

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?




Aucun commentaire:

Enregistrer un commentaire