Sha256: 43ee1aa946ad791d32bb02fb132bc41c5d27353efc12fa1b3ddcb4858c5e8887

Contents?: true

Size: 1.15 KB

Versions: 48

Compression:

Stored size: 1.15 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) => {
  const 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(),
        isVerified: Math.random() >= 0.5,
        isUser: Math.random() >= 0.5,
        deleted: false,
      },
      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

48 entries across 48 versions & 2 rubygems

Version Path
decidim-comments-0.8.4 app/frontend/support/generate_comments_data.ts
decidim-comments-0.8.3 app/frontend/support/generate_comments_data.ts
decidim-comments-0.8.2 app/frontend/support/generate_comments_data.ts
decidim-comments-0.8.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.8.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.7.4 app/frontend/support/generate_comments_data.ts
decidim-comments-0.7.3 app/frontend/support/generate_comments_data.ts
decidim-comments-0.7.2 app/frontend/support/generate_comments_data.ts
decidim-comments-0.7.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.7.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.6.8 app/frontend/support/generate_comments_data.ts
decidim-0.6.8 decidim-comments/app/frontend/support/generate_comments_data.ts
decidim-comments-0.6.7 app/frontend/support/generate_comments_data.ts
decidim-0.6.7 decidim-comments/app/frontend/support/generate_comments_data.ts
decidim-comments-0.6.6 app/frontend/support/generate_comments_data.ts
decidim-0.6.6 decidim-comments/app/frontend/support/generate_comments_data.ts
decidim-comments-0.6.5 app/frontend/support/generate_comments_data.ts
decidim-0.6.5 decidim-comments/app/frontend/support/generate_comments_data.ts
decidim-comments-0.6.4 app/frontend/support/generate_comments_data.ts
decidim-0.6.4 decidim-comments/app/frontend/support/generate_comments_data.ts