Sha256: 48614636ab596cf681bad381c10483255ea70cc92292da9045b2cb58610ac104

Contents?: true

Size: 1.41 KB

Versions: 16

Compression:

Stored size: 1.41 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,
      userAllowedToComment: 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

16 entries across 16 versions & 1 rubygems

Version Path
decidim-comments-0.23.6 app/frontend/support/generate_comments_data.ts
decidim-comments-0.23.5 app/frontend/support/generate_comments_data.ts
decidim-comments-0.23.4 app/frontend/support/generate_comments_data.ts
decidim-comments-0.23.3 app/frontend/support/generate_comments_data.ts
decidim-comments-0.23.2 app/frontend/support/generate_comments_data.ts
decidim-comments-0.23.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.23.1.rc1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.23.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.22.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.21.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.20.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.20.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.19.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.18.1 app/frontend/support/generate_comments_data.ts
decidim-comments-0.19.0 app/frontend/support/generate_comments_data.ts
decidim-comments-0.18.0 app/frontend/support/generate_comments_data.ts