From 1e1823443720f7ca9a0c4550dddd4ff1ff874b47 Mon Sep 17 00:00:00 2001 From: Sugui Date: Sat, 6 Jan 2024 13:25:24 +0100 Subject: [PATCH] Added fake data for testing and dev environment --- package.json | 1 + tests/populateDatabase.ts | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e11f4b4..95c8a32 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "module": "index.ts", "type": "module", "devDependencies": { + "@faker-js/faker": "^8.3.1", "@types/express": "^4.17.21", "@types/express-list-endpoints": "^6.0.3", "@types/jest": "^29.5.11", diff --git a/tests/populateDatabase.ts b/tests/populateDatabase.ts index f60c9c4..89e604b 100644 --- a/tests/populateDatabase.ts +++ b/tests/populateDatabase.ts @@ -1,12 +1,20 @@ import authModel from "../src/models/AuthModel"; -import imageModel from "../src/models/ImageModel"; +import imageModel, { Image } from "../src/models/ImageModel"; +import { faker } from '@faker-js/faker'; export default async function () { - await imageModel.create({ - url: "https://example.com", - status: "consumed", - tags: ["2girls", "sleeping"], - }); + const images = faker.helpers.multiple(() => ({ + url: faker.helpers.unique(faker.internet.url), + status: faker.helpers.arrayElement(["available", "unavailable", "consumed"]), + tags: faker.helpers.arrayElements([ + "2girls", "sleeping", "touhou", + "pokemon", "closed_eyes", "yume_nikki", + "waifu", "computer", "party", "yuru_camp" + ], { min: 0, max: 5 }), + }), {count: {min: 5, max:50}}); + + // Wait until all images are inserted + await Promise.allSettled(images.map(image => imageModel.create(image))); await authModel.create({ app: "tester",