From e986374c23618703e6fc3dce7b00490ac65808b6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 20 Dec 2023 12:18:29 +0100 Subject: [PATCH] Check fetched table --- .../scripts/load/create-many-relationships.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/server/scripts/load/create-many-relationships.js b/packages/server/scripts/load/create-many-relationships.js index 1589c1111e..926d0ac342 100755 --- a/packages/server/scripts/load/create-many-relationships.js +++ b/packages/server/scripts/load/create-many-relationships.js @@ -4,19 +4,27 @@ const { createApp, getTable, createRow, createTable } = require("./utils") const Chance = require("chance") const generator = new Chance() -const ROW_COUNT = 10 +const STUDENT_COUNT = 10 +const SUBJECT_COUNT = 10 if (!process.argv[2]) { console.error("Please specify an API key as script argument.") process.exit(-1) } +async function sleep(ms) { + return new Promise(r => setTimeout(() => r(), ms)) +} + async function run() { const apiKey = process.argv[2] const app = await createApp(apiKey) console.log(`App created: ${app._id}`) - const table = await getTable(apiKey, app._id) - console.log(`Table found: ${table.name}`) + const studentsTable = await getTable(apiKey, app._id) + if (studentsTable.name !== "Students") { + throw 'Fetched table should be "Students"' + } + console.log(`Table found: ${studentsTable.name}`) const subjectTable = await createTable(apiKey, app._id, { schema: { @@ -28,17 +36,17 @@ async function run() { name: "Subjects", }) - const SUBJECT_COUNT = 10 for (let i = 0; i < SUBJECT_COUNT; i++) { await createRow(apiKey, app._id, subjectTable, { Name: generator.profession(), }) console.log(`Subject ${i + 1} of ${SUBJECT_COUNT} created`) + await sleep(50) } - for (let i = 0; i < ROW_COUNT; i++) { - await createRow(apiKey, app._id, table) - console.log(`Row ${i + 1} of ${ROW_COUNT} created`) + for (let i = 0; i < STUDENT_COUNT; i++) { + await createRow(apiKey, app._id, studentsTable) + console.log(`Row ${i + 1} of ${STUDENT_COUNT} created`) } console.log(`App created: http://localhost:10000/builder/app/${app._id}`)