Fake data generator (#594)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2021-12-10 10:47:54 +01:00
committed by GitHub
parent ed9bcfa943
commit 36f2353878
23 changed files with 1101 additions and 22 deletions
+29
View File
@@ -0,0 +1,29 @@
import chunter, { Comment } from '@anticrm/chunter'
import { AttachedData, Class, Doc, generateId, Ref, Space, TxOperations } from '@anticrm/core'
import faker from 'faker'
export interface CommentOptions {
min: number
max: number
paragraphMin: number
paragraphMax: number
updateFactor: number // 0-100 value, will generate random value and if value is less updateFactor it will be updated.
}
export async function addComments<T extends Doc> (options: CommentOptions, client: TxOperations, space: Ref<Space>, objectId: Ref<T>, _class: Ref<Class<T>>, collection: string): Promise<void> {
const commentsCount = options.min + faker.datatype.number(options.max)
for (let i = 0; i < commentsCount; i++) {
const commentId = `candidate-comment-${generateId()}-${i}` as Ref<Comment>
const commentData: AttachedData<Comment> = {
message: faker.lorem.paragraphs(options.paragraphMin + faker.datatype.number(options.paragraphMax))
}
await client.addCollection(chunter.class.Comment, space, objectId, _class, collection, commentData, commentId)
if (faker.datatype.number(100) > options.updateFactor) {
const updateMsg = faker.lorem.paragraphs(options.paragraphMin + faker.datatype.number(options.paragraphMax))
await client.updateCollection(chunter.class.Comment, space, commentId, objectId, _class, collection, { message: updateMsg })
}
}
}