Sha256: 0c4d8d6bfba751d6c2264d66ae2275dfcb56382eb0d99f9de2c55ae9ba435506

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

import { date, image, lorem, name, random } from "faker/locale/en";

import { CommentFragment }           from "../support/schema";

/**
 * Generate random comment data to emulate a database real content
 * @param {number} num - The number of comments to generate random data
 * @returns {Object[]} - An array of objects representing comments data
 */
const generateCommentsData = (num = 1) => {
  let commentsData: CommentFragment[] = [];

  for (let idx = 0; idx < num; idx += 1) {
    commentsData.push({
      id: random.uuid(),
      type: "Decidim::Comments::Comment",
      body: lorem.words(),
      createdAt: date.past().toISOString(),
      author: {
        name: name.findName(),
        avatarUrl: image.imageUrl(),
      },
      hasComments: false,
      comments: [],
      acceptsNewComments: true,
      alignment: 0,
      upVotes: random.number(),
      upVoted: false,
      downVotes: random.number(),
      downVoted: false,
      sgid: random.uuid(),
      alreadyReported: false,
    });
  }

  return commentsData;
};

export default generateCommentsData;

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
decidim-comments-0.0.8.1 app/frontend/support/generate_comments_data.ts
decidim-0.0.8.1 decidim-comments/app/frontend/support/generate_comments_data.ts
decidim-comments-0.0.7 app/frontend/support/generate_comments_data.ts
decidim-0.0.7 decidim-comments/app/frontend/support/generate_comments_data.ts