Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("when hasMany associations assigned, belongTo parent is assigned", function(assert) {
let project = make('project');
let user = make('user', {projects: [project]});
assert.ok(project.get('user') === user);
});
test("handles camelCase attributes", function(assert) {
let profile = make('profile', {camelCaseDescription: 'description'});
assert.ok(profile.get('camelCaseDescription') === 'description');
});
test("creates records in the store", function(assert) {
let user = make('user');
assert.ok(user instanceof User);
let storeUser = FactoryGuy.store.peekRecord('user', user.id);
assert.ok(storeUser === user);
});
test("when hasMany ( self referential ) associations are assigned, belongsTo parent is assigned", function(assert) {
let big_group = make('big-group');
let group = make('group', {versions: [big_group]});
assert.ok(big_group.get('group') === group);
});
run(() => {
let model = make('profile');
let mock = mockFindRecord('profile').returns({model}).fails();
return FactoryGuy.store.findRecord('profile', model.id, {reload: true})
.catch(() => {
assert.equal(mock.timesCalled, 1);
assert.equal(mock.status, 500);
});
});
});
run(() => {
let done = assert.async();
let profile = make('profile');
let mock = mockDelete('profile', profile.id).fails({status: 500});
profile.destroyRecord().catch(function(reason) {
let error = reason.errors[0];
assert.equal(error.status, "500");
assert.equal(mock.timesCalled, 1);
assert.ok(true);
done();
});
});
});
run(async () => {
let bob = make('user');
mockQueryRecord('user', {name: 'Bob'}).returns({model: bob});
let user = await FactoryGuy.store.queryRecord('user', {name: 'Bob'});
assert.equal(user, bob, "returns the same user");
assert.equal(FactoryGuy.store.peekAll('user').get('content').length, 1, "does not create a new model");
});
});
run(async () => {
let company = make('company'),
profile = make('profile', {company: company});
mockUpdate('profile', profile.id).match({company: company});
await profile.save()
assert.ok(profile.get('company') === company);
});
});
run(() => {
let model = make('profile');
let mock = mockFindRecord('profile').returns({model}).fails();
return FactoryGuy.store.findRecord('profile', model.id, {reload: true})
.catch(() => {
assert.equal(mock.timesCalled, 1);
assert.equal(mock.status, 500);
});
});
});
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'));
});
});