Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
run(async () => {
let serializer = FactoryGuy.store.serializerFor('profile');
serializer.attrs = {
created_at: {
serialize: false
}
};
let date = new Date();
let profile = make('profile');
profile.set('created_at', date);
mockUpdate(profile)
.match({created_at: null}) // serializer removes date
.returns({attrs: {created_at: date}});
await profile.save();
assert.ok(profile.get('created_at').toString() === date.toString());
});
});
run(async () => {
let customDescription = "special description",
profile = make('profile'),
updateMock1 = mockUpdate(profile),
updateMock2 = mockUpdate(profile);
updateMock1.match(function() {
assert.ok(true, 'updateMock1 matching function is called');
return false;
});
profile.set('description', customDescription);
await profile.save();
assert.equal(updateMock1.timesCalled, 0);
assert.equal(updateMock2.timesCalled, 1);
});
});
run(async () => {
let profile = make('profile'),
date = new Date(2016, 1, 4);
mockUpdate(profile).returns({attrs: {created_at: date}});
profile.set('description', 'new desc');
await profile.save();
assert.ok(profile.get('description') === 'new desc');
assert.ok(profile.get('created_at').toString() === date.toString());
});
});
run(async () => {
let profile = make('profile'),
date = new Date(2016, 1, 4);
mockUpdate('profile', profile.id).returns({attrs: {created_at: date}});
profile.set('description', 'new desc');
await profile.save();
assert.ok(profile.get('description') === 'new desc');
assert.ok(profile.get('created_at').toString() === date.toString());
});
});
run(async () => {
let customDescription = "special description",
profile = make('profile'),
updateMock1 = mockUpdate(profile),
updateMock2 = mockUpdate(profile);
updateMock1.match(function() {
assert.ok(true, 'updateMock1 matching function is called');
return false;
});
profile.set('description', customDescription);
await profile.save();
assert.equal(updateMock1.timesCalled, 0);
assert.equal(updateMock2.timesCalled, 1);
});
});
run(async () => {
let customDescription = "special description",
profile = make('profile'),
updateMock1 = mockUpdate(profile),
updateMock2 = mockUpdate(profile);
updateMock1.match(function() {
assert.ok(true, 'updateMock1 matching function is called');
return false;
});
profile.set('description', customDescription);
await profile.save();
assert.equal(updateMock1.timesCalled, 0);
assert.equal(updateMock2.timesCalled, 1);
});
});
run(async () => {
let newValue = 'new name',
comicBook = make('comic-book', {characters: []});
comicBook.set('name', newValue);
let company = build('company');
mockUpdate(comicBook).returns({attrs: {company}});
await comicBook.save();
assert.equal(comicBook.get('name'), newValue);
assert.equal(comicBook.get('company.id'), company.get('id').toString());
assert.equal(comicBook.get('company.name'), company.get('name').toString());
});
});
run(async () => {
let customDescription = "special description",
profile = make('profile');
mockUpdate('profile', profile.id).match({description: customDescription});
profile.set('description', customDescription);
await profile.save();
assert.ok(profile instanceof Profile);
assert.ok(profile.id === '1');
assert.ok(profile.get('description') === customDescription);
});
});
run(async () => {
let group = make('group'),
profile = make('profile', {group: group});
mockUpdate(profile);
profile.set('description', 'new desc');
await profile.save()
assert.ok(profile.get('description') === 'new desc');
});
});
run(async () => {
let newValue = 'BoringMan',
hero = make('bat_man');
hero.set('name', newValue);
let outfits = buildList('outfit', 2);
mockUpdate(hero).returns({attrs: {outfits}});
await hero.save();
assert.equal(hero.get('name'), newValue);
assert.deepEqual(hero.get('outfits').mapBy('id'), ['1', '2']);
assert.deepEqual(hero.get('outfits').mapBy('name'), ['Outfit-1', 'Outfit-2']);
});
});