From f4ea2a7336df88b483b2edabc401b9b937b90179 Mon Sep 17 00:00:00 2001 From: Lars Waage <46653859+larwaa@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:02:50 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20chore(seeds):=20add=20images=20t?= =?UTF-8?q?o=20markdown=20seeds,=20use=20markdown=20for=20organization=20d?= =?UTF-8?q?escriptions=20(#568)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chore: add images to fake markdown --- src/repositories/events/seed.ts | 41 +------------------ src/repositories/organizations/seed.ts | 15 ++++--- src/repositories/seed.ts | 56 ++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/src/repositories/events/seed.ts b/src/repositories/events/seed.ts index 8cf1b638..8e33f7c0 100644 --- a/src/repositories/events/seed.ts +++ b/src/repositories/events/seed.ts @@ -1,15 +1,11 @@ import { faker } from "@faker-js/faker"; import type { Prisma, PrismaClient } from "@prisma/client"; -import { startCase, toLower } from "lodash-es"; import { DateTime } from "luxon"; import { env } from "~/config.js"; +import { fakeMarkdown, toTitleCase } from "../seed.js"; faker.seed(42); -const toTitleCase = (str: string) => { - return startCase(toLower(str)); -}; - const fakeName = () => { return toTitleCase( `${faker.word.adjective()} ${faker.word.verb()} ${faker.word.adverb()}`, @@ -372,38 +368,3 @@ export const load = async (db: PrismaClient) => { return events; }; - -function fakeMarkdown() { - const fakeHeader = () => - `${"#".repeat(faker.number.int({ min: 1, max: 6 }))} ${toTitleCase( - faker.lorem.words(3), - )}`; - const fakeParagraph = () => faker.lorem.paragraph().split("\n").join("\n\n"); - const fakeList = () => { - const listItems = faker.lorem.paragraphs(3).split("\n"); - return listItems.map((item) => `* ${item}`).join("\n"); - }; - const fakeCode = () => { - const code = faker.lorem.paragraphs(3).split("\n"); - return code.map((line) => ` ${line}`).join("\n"); - }; - const fakeQuote = () => { - const quote = faker.lorem.paragraphs(3).split("\n"); - return quote.map((line) => `> ${line}`).join("\n"); - }; - const fakeLink = () => `[${faker.lorem.words(3)}](${faker.internet.url()})`; - return ` -${fakeHeader()} - -${fakeParagraph()} - -${fakeList()} - -${fakeHeader()} -${fakeCode()} - -${fakeQuote()} - -${fakeLink()} - `; -} diff --git a/src/repositories/organizations/seed.ts b/src/repositories/organizations/seed.ts index 05c22731..509f5147 100644 --- a/src/repositories/organizations/seed.ts +++ b/src/repositories/organizations/seed.ts @@ -4,6 +4,7 @@ import { type Prisma, type PrismaClient, } from "@prisma/client"; +import { fakeMarkdown } from "../seed.js"; faker.seed(42); @@ -11,22 +12,22 @@ const organizationCreateInput: Prisma.OrganizationCreateInput[] = [ { id: faker.string.uuid(), name: faker.company.name(), - description: faker.lorem.paragraph(), + description: fakeMarkdown(), }, { id: faker.string.uuid(), name: faker.company.name(), - description: faker.lorem.paragraph(), + description: fakeMarkdown(), }, { id: faker.string.uuid(), name: faker.company.name(), - description: faker.lorem.paragraph(), + description: fakeMarkdown(), }, { id: faker.string.uuid(), name: faker.company.name(), - description: faker.lorem.paragraph(), + description: fakeMarkdown(), }, ]; @@ -37,7 +38,7 @@ export const load = async (db: PrismaClient) => { where: { id: organization.id, }, - update: {}, + update: organization, create: organization, }); } @@ -49,10 +50,12 @@ export const load = async (db: PrismaClient) => { }, update: { featurePermissions: [FeaturePermission.CABIN_ADMIN], + description: fakeMarkdown(), }, create: { name: "Hyttestyret", featurePermissions: [FeaturePermission.CABIN_ADMIN], + description: fakeMarkdown(), }, }); @@ -62,10 +65,12 @@ export const load = async (db: PrismaClient) => { }, update: { featurePermissions: [FeaturePermission.CABIN_ADMIN], + description: fakeMarkdown(), }, create: { name: "Rubberdøk", featurePermissions: [FeaturePermission.CABIN_ADMIN], + description: fakeMarkdown(), }, }); diff --git a/src/repositories/seed.ts b/src/repositories/seed.ts index 04e304eb..1065c3f3 100644 --- a/src/repositories/seed.ts +++ b/src/repositories/seed.ts @@ -1,4 +1,6 @@ +import { faker } from "@faker-js/faker"; import { PrismaClient } from "@prisma/client"; +import { startCase, toLower } from "lodash-es"; import * as Cabins from "./cabins/seed.js"; import * as Documents from "./documents/seed.js"; import * as Events from "./events/seed.js"; @@ -44,3 +46,57 @@ try { console.log("Finished"); await db.$disconnect(); } + +function fakeMarkdown() { + const images = [ + "https://source.unsplash.com/3tYZjGSBwbk", + "https://source.unsplash.com/t7YycgAoVSw", + "https://source.unsplash.com/lSIxP2H5Dmc", + "https://source.unsplash.com/2Eewt6DoSRI", + "https://source.unsplash.com/WqZoyvzViBA", + ]; + const fakeHeader = () => + `${"#".repeat(faker.number.int({ min: 1, max: 6 }))} ${toTitleCase( + faker.lorem.words(3), + )}`; + const fakeParagraph = () => faker.lorem.paragraph().split("\n").join("\n\n"); + const fakeList = () => { + const listItems = faker.lorem.paragraphs(3).split("\n"); + return listItems.map((item) => `* ${item}`).join("\n"); + }; + const fakeCode = () => { + const code = faker.lorem.paragraphs(3).split("\n"); + return code.map((line) => ` ${line}`).join("\n"); + }; + const fakeQuote = () => { + const quote = faker.lorem.paragraphs(3).split("\n"); + return quote.map((line) => `> ${line}`).join("\n"); + }; + const fakeLink = () => `[${faker.lorem.words(3)}](${faker.internet.url()})`; + const fakeImage = () => + `![${faker.lorem.words(3)}](${ + images[faker.number.int({ min: 0, max: images.length - 1 })] + })`; + return ` +${fakeHeader()} + +${fakeParagraph()} + +${fakeImage()} + +${fakeList()} + +${fakeHeader()} +${fakeCode()} + +${fakeQuote()} + +${fakeLink()} + - `; +} + +function toTitleCase(str: string) { + return startCase(toLower(str)); +} + +export { fakeMarkdown, toTitleCase };