const generateUsersDirectMessageThreads = (threadId, userId) => { const createdAt = faker.date.past(2); const lastActive = faker.date.between(createdAt, faker.date.recent()); const lastSeen = faker.date.between(createdAt, new Date()); return { id: uuid(), createdAt, threadId, userId, lastActive, lastSeen, receiveNotifications: true, }; }
const generateReaction = (userId, messageId) => { return { id: uuid(), messageId, userId, timestamp: faker.date.past(2), type: 'like', }; }
const generateChannel = communityId => { const name = faker.commerce.department(); return { id: uuid(), communityId, createdAt: faker.date.past(2), name, description: casual.short_description(), slug: slugify(name), isPrivate: faker.random.boolean(), isDefault: false, }; }
const generateUsersCommunities = (communityId, userId) => { const isOwner = faker.random.boolean(); // for ease of use, set to false const isModerator = false; // if user is either an admin or moderator, they have to be a member // otherwise random chance const isMember = isOwner || isModerator ? true : faker.random.boolean(); // might be blocked as long as they aren't an admin, mod, or member const isBlocked = isOwner || isModerator || isMember ? false : faker.random.boolean(); return { id: uuid(), createdAt: faker.date.past(2), communityId, userId, isOwner, isModerator, isMember, isBlocked, receiveNotifications: true, reputation: 1, }; }
const generateCommunity = () => { const name = faker.company.companyName(); return { id: uuid(), createdAt: faker.date.past(2), name, description: casual.short_description(), website: faker.internet.url(), profilePhoto: faker.image.business(), coverPhoto: faker.image.image(), slug: slugify(name), }; }
const generateMessage = (senderId, threadId, threadType) => { return { id: uuid(), threadType, threadId, senderId, content: { body: casual.text(), }, messageType: 'text', timestamp: faker.date.past(2), }; }
const generateThread = (communityId, channelId, creatorId) => { const content = { title: casual.title(), body: JSON.stringify(toJSON(fromPlainText(casual.text()))), }; const createdAt = faker.date.past(2); return { id: uuid(), createdAt, creatorId, channelId, communityId, isPublished: faker.random.boolean(), content, type: 'DRAFTJS', lastActive: faker.date.between(createdAt, new Date()), edits: [ { timestamp: createdAt, content, }, ], modifiedAt: faker.date.between(createdAt, new Date()), }; }
const generateUsersThreads = (threadId, userId) => { const createdAt = faker.date.past(2); return { id: uuid(), createdAt, threadId, userId, isParticipant: true, receiveNotifications: true, }; }
const generateUser = () => { const createdAt = faker.date.past(2); const name = faker.name.findName(); return { id: uuid(), name, description: casual.short_description(), website: faker.internet.url(), username: faker.internet.userName(name), profilePhoto: faker.internet.avatar(), coverPhoto: faker.image.image(), email: faker.internet.email(name), providerId: uuid(), createdAt, // Make sure lastSeen is > createdAt lastSeen: faker.date.between(createdAt, new Date()), }; }
const message = (props) => Object.assign({ from: `${faker.name.firstName()} ${faker.name.lastName()}`, fromAvatar: faker.image.avatar(), subject: faker.company.catchPhrase(), body: fakeBody(), flagged: faker.random.boolean(), sent: faker.date.past(1).toISOString(), }, props)
// Messages const createMessage = user => { const message = new Message({ title: faker.lorem.words(5), sentDate: faker.date.between('2020-01-01', '2020-12-31'), recipient: user._id, content: faker.lorem.paragraph(), isRead: faker.random.boolean() }); return message.save(); }
const defineMessage = (participants, numMessages) => { const generateMessage = count => ({ uuid: faker.random.uuid(), from: faker.random.arrayElement(participants), text: faker.lorem.sentence(), sentAt: faker.date.recent(), }); const messages = times(numMessages)(generateMessage).sort((a, b) => moment(a.sentAt).isBefore(moment(b.sentAt))); return messages; }
// Statistics const createStats = accountId => { const stats = new Stat({ accountId, name: faker.date.recent(_.random(1, 60, false)), // Date is NOW or 1-60 days before date: faker.date.recent(_.random(1, 60, false)), income: faker.finance.amount(100, 5000, 2), expenses: faker.finance.amount(100, 5000, 2) }); return stats.save(); }
_generateBirthday() { var from = new Date(1940, 5, 7, 9, 11, 0, 0); var to = new Date(2000, 6, 8, 10, 12, 0, 0); return Faker.date.between(from, to); }