Sha256: 32a177a02b630e28986d0784f2e435f4bd21b5e4d821904817a72e9c23111e79

Contents?: true

Size: 1.38 KB

Versions: 24

Compression:

Stored size: 1.38 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) {
    const creationDate = date.recent();
    const nickname = name.findName();

    commentsData.push({
      id: random.uuid(),
      type: "Decidim::Comments::Comment",
      body: lorem.words(),
      formattedBody: lorem.words(),
      createdAt: creationDate.toISOString(),
      formattedCreatedAt: creationDate.toLocaleTimeString(),
      author: {
        name: `${name.firstName()} ${name.lastName()}`,
        nickname: `@${nickname}`,
        avatarUrl: image.imageUrl(),
        profilePath: `/profiles/${nickname}`,
        deleted: false,
        badge: "verified-badge"
      },
      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

24 entries across 24 versions & 1 rubygems

Version Path
decidim-comments-0.17.2 app/frontend/support/generate_comments_data.ts
decidim-comments-0.17.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.16.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.17.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.16.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.15.2 app/frontend/support/generate_comments_data.ts
decidim-comments-0.15.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.15.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.14.4 app/frontend/support/generate_comments_data.ts
decidim-comments-0.14.3 app/frontend/support/generate_comments_data.ts
decidim-comments-0.14.2 app/frontend/support/generate_comments_data.ts
decidim-comments-0.14.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.13.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.12.2 app/frontend/support/generate_comments_data.ts
decidim-comments-0.13.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.12.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.13.0.pre1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.12.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.11.2 app/frontend/support/generate_comments_data.ts
decidim-comments-0.12.0.pre app/frontend/support/generate_comments_data.ts