Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import FactoryGuy from 'ember-data-factory-guy';
import faker from 'faker';
FactoryGuy.define('file', {
default: {
name: () => `${faker.lorem.words(1)}.txt`,
kind: 'file',
path: '/1234567890', // Faker.system.filePath may not yet be implemented
size: () => faker.random.number(),
provider: 'osfstorage',
materializedPath: () => `/${faker.lorem.words(1)}.png`,
lastTouched: null,
dateModified: () => faker.date.recent(1),
dateCreated: () => faker.date.past(1),
isProvider: false,
checkout: null,
links: {
import FactoryGuy from 'ember-data-factory-guy';
import faker from 'faker';
FactoryGuy.define('file-version', {
default: {
size: () => faker.random.number(),
contentType: 'text/plain', // faker.system may not come with older versions of lib
}
});
import FactoryGuy from 'ember-data-factory-guy';
import faker from 'faker';
FactoryGuy.define('file', {
default: {
name: () => faker.lorem.words(1) + '.txt',
kind: 'file',
path: '/1234567890', // Faker.system.filePath may not yet be implemented
size: () => faker.random.number(),
provider: 'osfstorage',
materializedPath: () => '/' + faker.lorem.words(1) + '.png',
lastTouched: null,
dateModified: () => faker.date.recent(1),
dateCreated: () => faker.date.past(1),
isProvider: false,
checkout: null,
links: {
},
traits: {
hasParent: { // Is a child of a public node
parent: () => FactoryGuy.belongsTo('node'),
},
hasChildren: { // Has one layer of child projects
children: FactoryGuy.hasMany('node', 3),
},
hasInstitution: {
affiliatedInstitutions: FactoryGuy.hasMany('institution', 1),
},
hasComments: {
comments: FactoryGuy.hasMany('comment', 3),
},
hasContributors: {
contributors: FactoryGuy.hasMany('contributor', 3),
},
hasFiles: {
files: FactoryGuy.hasMany('file-provider', 3, 'hasFiles'),
},
hasRegistrations: {
registrations: FactoryGuy.hasMany('registration', 1),
},
hasLogs: {
logs: FactoryGuy.hasMany('log', 5),
},
hasTags: {
tags: () => [faker.lorem.words(1), faker.lorem.words(1), faker.lorem.words(1)],
},
},
});
collection: false,
registration: false,
public: () => faker.random.boolean(),
dateCreated: () => faker.date.past(1),
dateModified: () => faker.date.recent(1),
},
traits: {
hasParent: { // Is a child of a public node
parent: () => FactoryGuy.belongsTo('node'),
},
hasChildren: { // Has one layer of child projects
children: FactoryGuy.hasMany('node', 3),
},
hasInstitution: {
affiliatedInstitutions: FactoryGuy.hasMany('institution', 1),
},
hasComments: {
comments: FactoryGuy.hasMany('comment', 3),
},
hasContributors: {
contributors: FactoryGuy.hasMany('contributor', 3),
},
hasFiles: {
files: FactoryGuy.hasMany('file-provider', 3, 'hasFiles'),
},
hasRegistrations: {
registrations: FactoryGuy.hasMany('registration', 1),
},
hasLogs: {
logs: FactoryGuy.hasMany('log', 5),
},
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(() => {
let done = assert.async();
let mock = mockCreate('profile').match({description: 'correct description'});
FactoryGuy.store.createRecord('profile', {description: 'wrong description'}).save()
.catch(() => {
assert.ok(true);
// our mock was NOT called
assert.equal(mock.timesCalled, 0);
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();
});
});
});
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();
});
});
});