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 returning no result", async function(assert) {
mockQueryRecord('user');
FactoryGuy.store.queryRecord('user', {});
assert.ok(true);
});
run(() => {
let done = assert.async();
let profile = mockFindRecord('profile', 'with_company', 'with_bat_man');
let profileId = profile.get('id');
FactoryGuy.store.findRecord('profile', profileId).then(function(profile) {
assert.ok(profile.get('company.name') === 'Silly corp');
assert.ok(profile.get('superHero.name') === 'BatMan');
done();
});
});
});
run(async () => {
let customDescription = "special description",
profile = make('profile'),
updateMock = mockUpdate(profile),
adapter = FactoryGuy.store.adapterFor('profile');
adapter.updateRecord = (store, type, snapshot) => {
let url = adapter.urlForUpdateRecord(snapshot.id, type.modelName, snapshot);
let httpMethod = FactoryGuy.updateHTTPMethod(type.modelName);
let fd = new FormData();
fd.append('description', snapshot.attr('description'));
adapter.ajax(url, httpMethod, {
data: fd,
processData: false,
contentType: false,
});
};
adapter.ajaxOptions = (url, type, options) => {
return Object.assign({}, options, { url, type });
};
run(async () => {
let customDescription = "special description";
mockCreate('profile').match({description: customDescription});
assert.ok(FactoryGuy.store.peekAll('profile').get('content.length') === 0);
let profile = FactoryGuy.store.createRecord('profile', {description: customDescription});
await profile.save();
assert.ok(FactoryGuy.store.peekAll('profile').get('content.length') === 1, 'No extra records created');
assert.ok(profile instanceof Profile, 'Creates the correct type of record');
assert.ok(profile.get('description') === customDescription, 'Passes along the match attributes');
});
});
run(() => {
let done = assert.async(),
mock = mockFindRecord('profile'),
profileId = mock.get('id');
FactoryGuy.store.findRecord('profile', profileId).then(function(profile) {
assert.equal(profile.get('id'), profileId);
assert.equal(profile.get('description'), 'Text goes here');
done();
});
});
});
run(() => {
let done = assert.async();
mockFindAll('comic-book', 2, 'marvel');
FactoryGuy.store.findAll('comic-book').then(function(comics) {
assert.ok(comics.mapBy('name') + '' === ['Comic Times #1', 'Comic Times #2'] + '');
assert.ok(comics.mapBy('company.name') + '' === ['Marvel Comics', 'Marvel Comics'] + '');
done();
});
});
});
run(() => {
let done = assert.async();
let json1 = buildList('profile', 2).add({meta: {previous: '/profiles?page=1', next: '/profiles?page=3'}});
let json2 = buildList('profile', 2).add({meta: {previous: '/profiles?page=2', next: '/profiles?page=4'}});
mockQuery('profile', {page: 2}).returns({json: json1});
mockQuery('profile', {page: 3}).returns({json: json2});
FactoryGuy.store.query('profile', {page: 2}).then(function(profiles) {
assert.deepEqual(profiles.mapBy('id'), ["1", "2"]);
assert.ok(isEquivalent(profiles.get('meta'), {previous: '/profiles?page=1', next: '/profiles?page=3'}));
FactoryGuy.store.query('profile', {page: 3}).then(function(profiles2) {
assert.deepEqual(profiles2.mapBy('id'), ["3", "4"]);
assert.ok(isEquivalent(profiles2.get('meta'), {previous: '/profiles?page=2', next: '/profiles?page=4'}));
done();
});
});
});
});
let profile = run(() => FactoryGuy.store.createRecord('profile'));
await run(async () => profile.save());
run(() => {
let done = assert.async();
let store = FactoryGuy.store;
let bobQueryHander = mockQuery('user', {name: 'Bob'});
store.query('user', {name: 'Bob'}).then(function(users) {
assert.equal(users.get('length'), 0);
mockCreate('user', {name: 'Bob'});
store.createRecord('user', {name: 'Bob'}).save().then(function(user) {
bobQueryHander.returns({models: [user]});
store.query('user', {name: 'Bob'}).then(function(users) {
assert.equal(users.get('length'), 1);
done();
});
});
run(() => {
let done = assert.async();
let mock = mockReload('profile', 1).fails();
FactoryGuy.store.findRecord('profile', 1)
.catch(() => {
assert.equal(mock.timesCalled, 1);
assert.ok(true);
done();
}
);
});
});