channels.forEach(channel => { const community = communities.find( community => community.id === channel.communityId ); if (community.deletedAt) return; randomAmount({ max: 10 }, () => { const creator = faker.random.arrayElement(users); const thread = generateThread(channel.communityId, channel.id, creator.id); threads.push(thread); }); });
const randomAmount = ({ max, min }, cb) => { if (!max) throw new Error('randomAmount({ max }): max has to be defined!'); const n = faker.random.number({ min: min || 0, max }); let result = []; for (var i = 0; i < n; i++) { result.push(cb(i)); } return result; }
messages.map(message => { randomAmount({ max: 5 }, () => { const user = faker.random.arrayElement(users); reactions.push(generateReaction(user.id, message.id)); }); });
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, }; }
threads.forEach(thread => { const channel = channels.find(channel => channel.id === thread.channelId); const threadMessages = []; randomAmount({ max: 10 }, () => { const sender = faker.random.arrayElement(users); const message = generateMessage(sender.id, thread.id, 'story'); messages.push(message); threadMessages.push(message); }); });
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 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, }; }
function createRows ( size ) { return I.Range( 0, size ).map(function ( idx ) { return I.Map({ id : 'record_' + idx, author : faker.name.findName(), notes : faker.lorem.sentence(), profession : faker.random.array_element([ 'dev', 'qa', 'ban', 'san' ]) }); }).toList(); }
async function addProduct(data) { const defaultProduct = { name: faker.commerce.product(), price: faker.finance.amount(), weight: faker.random.number() }; const body = Object.assign(defaultProduct, data); return await queryApi("POST", "/products", { body }); }
beforeEach(() => { mockFilePath = faker.random.word(); // Due to the way the dotnetPath module caches values, we need to isolate the module in each // test to prevent side effects and test behavior properly. // See https://stackoverflow.com/questions/48989643/how-to-reset-module-imported-between-tests jest.isolateModules(() => { dotnetPath = require("./dotnet-path"); cliFilePath = dotnetPath.CLI_FILE_PATH; releaseDir = dotnetPath.RELEASE_DIRECTORY; }); });
/** * @returns {Object} - a new message object */ function generateMsg(number) { return { number, text: txtgen.sentence(), is_user_msg: faker.random.boolean() }; }
async function addProduct(data) { const defaultProduct = { name: faker.commerce.product(), price: faker.finance.amount(), weight: faker.random.number() }; const body = Object.assign(defaultProduct, data); return await queryApi("POST", "/products", { body }); }
async function addProduct(data) { const defaultProduct = { name: faker.commerce.product(), price: faker.finance.amount(), weight: faker.random.number() }; const body = Object.assign(defaultProduct, data); return await queryApi("POST", "/products", { body }); }
/** * @returns {Object} - a new message object */ function generateMsg(number) { return { number, text: txtgen.sentence(), is_user_msg: faker.random.boolean() }; }