2017-01-02 21:49:44 +03:00
|
|
|
import {Factory, faker} from 'ember-cli-mirage';
|
2018-03-13 14:17:29 +03:00
|
|
|
import {isEmpty} from '@ember/utils';
|
2017-01-02 21:49:44 +03:00
|
|
|
|
|
|
|
export default Factory.extend({
|
2018-03-26 13:41:45 +03:00
|
|
|
codeinjectionFoot: null,
|
|
|
|
codeinjectionHead: null,
|
|
|
|
createdAt: '2015-09-11T09:44:29.871Z',
|
|
|
|
createdBy: 1,
|
|
|
|
customExcerpt: null,
|
|
|
|
customTemplate: null,
|
2018-01-05 18:38:23 +03:00
|
|
|
description(i) { return `Title for post ${i}.`; },
|
2017-01-02 21:49:44 +03:00
|
|
|
featured: false,
|
2018-03-26 13:41:45 +03:00
|
|
|
featureImage(i) { return `/content/images/2015/10/post-${i}.jpg`; },
|
|
|
|
html(i) { return `<p>HTML for post ${i}.</p>`; },
|
|
|
|
locale: null,
|
2018-01-05 18:38:23 +03:00
|
|
|
metaDescription(i) { return `Meta description for post ${i}.`; },
|
|
|
|
metaTitle(i) { return `Meta Title for post ${i}`; },
|
2018-03-26 13:41:45 +03:00
|
|
|
ogDescription: null,
|
|
|
|
ogImage: null,
|
|
|
|
ogTitle: null,
|
|
|
|
plaintext(i) { return `Plaintext for post ${i}.`; },
|
2017-01-02 21:49:44 +03:00
|
|
|
publishedAt: '2015-12-19T16:25:07.000Z',
|
|
|
|
publishedBy: 1,
|
2018-03-26 13:41:45 +03:00
|
|
|
status(i) { return faker.list.cycle('draft', 'published', 'scheduled')(i); },
|
|
|
|
title(i) { return `Post ${i}`; },
|
|
|
|
twitterDescription: null,
|
|
|
|
twitterImage: null,
|
|
|
|
twitterTitle: null,
|
|
|
|
updatedAt: '2015-10-19T16:25:07.756Z',
|
|
|
|
updatedBy: 1,
|
2018-03-13 14:17:29 +03:00
|
|
|
uuid(i) { return `post-${i}`; },
|
|
|
|
|
|
|
|
authors() { return []; },
|
|
|
|
tags() { return []; },
|
|
|
|
|
|
|
|
afterCreate(post, server) {
|
|
|
|
if (isEmpty(post.authors)) {
|
|
|
|
let user = server.schema.users.find(1);
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
let role = server.schema.roles.find({name: 'Administrator'}) || server.create('role', {name: 'Administrator'});
|
|
|
|
user = server.create('user', {roles: [role]});
|
|
|
|
}
|
|
|
|
|
|
|
|
post.authors = [user];
|
|
|
|
post.save();
|
|
|
|
}
|
|
|
|
}
|
2017-01-02 21:49:44 +03:00
|
|
|
});
|