Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("with no parameters matches queryRequest with any parameters", async function(assert) {
mockQueryRecord('user').returns({json: build('user')});
await FactoryGuy.store.queryRecord('user', {name: 'Bob'});
assert.ok(true);
});
run(async () => {
let newValue = 'new name',
outfit = make('outfit');
outfit.set('name', newValue);
let person = build('super-hero');
mockUpdate(outfit).returns({attrs: {person}});
await outfit.save();
assert.equal(outfit.get('name'), newValue);
assert.equal(outfit.get('person.id'), person.get('id').toString());
assert.equal(outfit.get('person.name'), person.get('name'));
});
});
run(() => {
let done = assert.async();
let hat1 = build('big-hat');
let hat2 = build('big-hat');
let json = build('user', {hats: [hat1, hat2]});
mockFindRecord('user').returns({json});
FactoryGuy.store.findRecord('user', json.get('id')).then(function(user) {
assert.ok(user.get('hats.firstObject.id') === hat1.get('id') + '');
assert.ok(user.get('hats.lastObject.id') === hat2.get('id') + '');
done();
});
});
});
return run(async () => {
let company1 = build('company'),
company2 = build('company');
let mockQuery = mockQueryRecord('company', {name: 'Dude'}).returns({json: company1});
let company = await FactoryGuy.store.queryRecord('company', {name: 'Dude'});
assert.equal(company.get('id'), company1.get('id'));
mockQuery.withParams({type: 'Small'}).returns({json: company2});
company = await FactoryGuy.store.queryRecord('company', {type: 'Small'});
assert.equal(company.get('id'), company2.get('id'));
});
});
run(() => {
let done = assert.async();
let hat1 = build('big-hat');
let hat2 = build('big-hat');
let json = build('user', {hats: [hat1, hat2]});
mockFindRecord('user').returns({json});
FactoryGuy.store.findRecord('user', json.get('id')).then(function(user) {
assert.ok(user.get('hats.firstObject.id') === hat1.get('id') + '');
assert.ok(user.get('hats.lastObject.id') === hat2.get('id') + '');
done();
});
});
});
run(() => {
let done = assert.async();
let hat1 = build('big-hat');
let hat2 = build('big-hat');
let json = build('user', {hats: [hat1, hat2]});
mockFindRecord('user').returns({json});
FactoryGuy.store.findRecord('user', json.get('id')).then(function(user) {
assert.ok(user.get('hats.firstObject.id') === hat1.get('id') + '');
assert.ok(user.get('hats.lastObject.id') === hat2.get('id') + '');
done();
});
});
});
run(async () => {
let person = build('super-hero'),
outfit = FactoryGuy.store.createRecord('outfit');
mockCreate('outfit').returns({attrs: {person}});
await outfit.save()
assert.equal(outfit.get('person.id'), person.get('id').toString());
assert.equal(outfit.get('person.name'), person.get('name'));
});
});
run(() => {
let profile = make('profile', {description: "tomatoes", camelCaseDescription: "noodles"});
let newProfile = build('profile', {id: profile.get('id'), description: "potatoes", camelCaseDescription: "poodles"});
mockReload(profile).returns({json: newProfile});
profile.reload().then(function(reloaded) {
assert.ok(reloaded.id === profile.id, 'does not change id');
assert.ok(reloaded.get('description') === "potatoes", "description changed");
assert.ok(reloaded.get('camelCaseDescription') === "poodles", "camelCaseDescription changes");
done();
});
});
});
return run(async () => {
let company1 = build('company'),
company2 = build('company');
let mockQuery = mockQueryRecord('company', {name: 'Dude'}).returns({json: company1});
let company = await FactoryGuy.store.queryRecord('company', {name: 'Dude'});
assert.equal(company.get('id'), company1.get('id'));
mockQuery.withParams({type: 'Small'}).returns({json: company2});
company = await FactoryGuy.store.queryRecord('company', {type: 'Small'});
assert.equal(company.get('id'), company2.get('id'));
});
});
run(() => {
let done = assert.async();
let hat1 = build('big-hat');
let hat2 = build('big-hat');
let json = build('user', {hats: [hat1, hat2]});
mockFindRecord('user').returns({json});
FactoryGuy.store.findRecord('user', json.get('id')).then(function(user) {
assert.ok(user.get('hats.firstObject.id') === hat1.get('id') + '');
assert.ok(user.get('hats.lastObject.id') === hat2.get('id') + '');
done();
});
});
});