2022-01-19 15:57:58 +03:00
|
|
|
import faker from 'faker';
|
2022-09-23 20:15:08 +03:00
|
|
|
import moment from 'moment-timezone';
|
2022-03-08 14:32:01 +03:00
|
|
|
import {Factory} from 'miragejs';
|
2022-01-19 15:57:58 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|