mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
c4c48d4104
refs https://github.com/TryGhost/Admin/pull/2209 - `miragejs` has been extracted to a framework-independent library, the re-exports of `miragejs` elements in `ember-cli-mirage` have been deprecated making our test logs very noisy - added `miragejs` as a top-level dependency - updated all relevant imports to pull from `miragejs` instead of `ember-cli-mirage`
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
import faker from 'faker';
|
|
import moment from 'moment';
|
|
import {Factory} from 'miragejs';
|
|
|
|
const EVENT_TYPES = [
|
|
'newsletter_event',
|
|
'login_event',
|
|
'subscription_event',
|
|
'payment_event',
|
|
'login_event',
|
|
'signup_event',
|
|
'email_delivered_event',
|
|
'email_opened_event',
|
|
'email_failed_event'
|
|
];
|
|
|
|
/* eslint-disable camelcase */
|
|
export default Factory.extend({
|
|
type() { return faker.random.arrayElement([EVENT_TYPES]); },
|
|
createdAt() { return moment.utc().format(); },
|
|
|
|
afterCreate(event, server) {
|
|
if (!event.member) {
|
|
event.update({member: server.create('member')});
|
|
}
|
|
|
|
if (event.type === 'newsletter_event') {
|
|
event.update({
|
|
data: {
|
|
source: 'member',
|
|
subscribed: event.subscribed !== undefined ? event.subscribed : faker.datatype.boolean()
|
|
}
|
|
});
|
|
}
|
|
|
|
if (event.type === 'subscription_event') {
|
|
event.update({
|
|
data: {
|
|
source: 'stripe'
|
|
// TODO: add from_plan, to_plan, currency, mrr_delta
|
|
}
|
|
});
|
|
}
|
|
|
|
if (event.type === 'payment_event') {
|
|
// TODO: add data attributes
|
|
}
|
|
|
|
if (event.type === 'signup_event') {
|
|
// TODO: add data attributes
|
|
}
|
|
}
|
|
});
|