Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("handles hasMany relationships", function(assert) {
let projects = makeList('project', 1),
user = makeNew('user', {projects});
assert.deepEqual(user.get('projects').toArray(), projects.toArray(), 'hasMany projects');
});
test("handles traits and optional fixture arguments", function(assert) {
let users = FactoryGuy.makeList('user', 2, 'with_hats', {name: 'Bob'});
assert.equal(users[0].get('name'), 'Bob');
assert.equal(users[0].get('hats.length') === 2, true);
});
test("with data and links for hasMany relationship", function(assert) {
const properties = makeList('property', 2),
propertyLink = '/user/1/properties',
user = make('user', {properties, links: {properties: propertyLink}});
assert.equal(user.hasMany('properties').link(), propertyLink, 'has link');
assert.deepEqual(user.properties.toArray(), properties, 'has models');
});
run(() => {
let done = assert.async();
let expectedAssertions = 2;
function finalizeTest() {
--expectedAssertions;
if (expectedAssertions === 0) {
done();
}
}
let companies = makeList('company', 2);
mockQuery('company', {name: 'Dude'}).returns({models: companies});
mockQuery('company', {type: 'Small', name: 'Dude'}).returns({models: companies});
let request1 = FactoryGuy.store.query('company', {name: 'Dude'});
let request2 = FactoryGuy.store.query('company', {type: 'Small', name: 'Dude'});
request1.then(function(returnedCompanies) {
assert.equal(A(companies).mapBy('id') + '', A(returnedCompanies).mapBy('id') + '');
finalizeTest();
});
request2.then(function(returnedCompanies) {
assert.equal(A(companies).mapBy('id') + '', A(returnedCompanies).mapBy('id') + '');
finalizeTest();
});