Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
run(() => {
let done = assert.async();
let json = buildList('user', 1);
mockQuery('user', {name: 'Bob'}).returns({json});
FactoryGuy.store.query('user', {name: 'Bob'}).then(function(users) {
assert.equal(users.get('length'), 1);
// makes the user after getting query response
assert.equal(FactoryGuy.store.peekAll('user').get('content').length, 1);
done();
});
});
});
run(() => {
let done = assert.async();
let json = buildList('user', 1);
mockQuery('user', {name: 'Bob'}).returns({json});
FactoryGuy.store.query('user', {name: 'Bob'}).then(function(users) {
assert.equal(users.get('length'), 1);
// makes the user after getting query response
assert.equal(FactoryGuy.store.peekAll('user').get('content').length, 1);
done();
});
});
});
test("using traits", function(assert) {
let projectList = buildList('project', 1, 'big');
assert.deepEqual(projectList, {
data: [{
id: 1,
type: 'project',
attributes: {
title: 'Big Project'
}
}]
});
});
test("using custom attributes", function(assert) {
let userList = buildList('user', 1, {name: 'Crazy'});
assert.deepEqual(userList, {
data: [{
id: 1,
type: 'user',
attributes: {
name: 'Crazy',
style: "normal"
}
},
]
}
);
});
test("basic", function(assert) {
let userList = buildList('user', 2);
assert.deepEqual(userList, {
data: [{
id: 1,
type: 'user',
attributes: {
name: 'User1',
style: "normal"
}
},
{
id: 2,
type: 'user',
attributes: {
name: 'User2',
style: "normal"
}
run(async () => {
let outfits = buildList('outfit', 2),
hero = FactoryGuy.store.createRecord('super-hero');
mockCreate('super-hero').returns({attrs: {outfits}});
await hero.save();
assert.deepEqual(hero.get('outfits').mapBy('id'), ['1', '2']);
assert.deepEqual(hero.get('outfits').mapBy('name'), ['Outfit-1', 'Outfit-2']);
});
});
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();
});
});
});
});
run(() => {
let done = assert.async();
let json = buildList('profile', 'with_company', 'with_bat_man');
mockFindAll('profile').returns({json});
FactoryGuy.store.findAll('profile').then(function(profiles) {
assert.ok(profiles.get('firstObject.company.name') === 'Silly corp');
assert.ok(profiles.get('lastObject.superHero.name') === 'BatMan');
done();
});
});
});
run(async () => {
let outfits = buildList('outfit', 2),
hero = FactoryGuy.store.createRecord('super-hero');
mockCreate('super-hero').returns({attrs: {outfits}});
await hero.save();
assert.deepEqual(hero.get('outfits').mapBy('id'), ['1', '2']);
assert.deepEqual(hero.get('outfits').mapBy('name'), ['Outfit-1', 'Outfit-2']);
});
});
run(() => {
let done = assert.async();
let json = buildList('profile', 'with_company', 'with_bat_man');
mockFindAll('profile').returns({json});
FactoryGuy.store.findAll('profile').then(function(profiles) {
assert.ok(profiles.get('firstObject.company.name') === 'Silly corp');
assert.ok(profiles.get('lastObject.superHero.name') === 'BatMan');
done();
});
});
});