From e62ea91155f99095e6f901a5feac38d3fa48257a Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams Date: Fri, 7 Nov 2025 12:47:09 +0000 Subject: [PATCH 1/9] setting up test structure --- tests/{playwright => e2e/web/specs}/some.test.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{playwright => e2e/web/specs}/some.test.ts (100%) diff --git a/tests/playwright/some.test.ts b/tests/e2e/web/specs/some.test.ts similarity index 100% rename from tests/playwright/some.test.ts rename to tests/e2e/web/specs/some.test.ts From 0add06b6eb4a892920636785f5344c9d64a47c53 Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams Date: Fri, 7 Nov 2025 13:06:34 +0000 Subject: [PATCH 2/9] . --- tests/e2e/backend/.keep | 0 tests/e2e/mobile/.keep | 0 tests/e2e/utils/.keep | 0 tests/e2e/web/pageManager/.keep | 0 tests/e2e/web/specs/.keep | 0 tests/{e2e/web/specs => playwright}/some.test.ts | 0 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/e2e/backend/.keep create mode 100644 tests/e2e/mobile/.keep create mode 100644 tests/e2e/utils/.keep create mode 100644 tests/e2e/web/pageManager/.keep create mode 100644 tests/e2e/web/specs/.keep rename tests/{e2e/web/specs => playwright}/some.test.ts (100%) diff --git a/tests/e2e/backend/.keep b/tests/e2e/backend/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/mobile/.keep b/tests/e2e/mobile/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/utils/.keep b/tests/e2e/utils/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/web/pageManager/.keep b/tests/e2e/web/pageManager/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/web/specs/.keep b/tests/e2e/web/specs/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/web/specs/some.test.ts b/tests/playwright/some.test.ts similarity index 100% rename from tests/e2e/web/specs/some.test.ts rename to tests/playwright/some.test.ts From ae75bdba4abffb6d9bd4932186db63d99dabfb04 Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams Date: Fri, 7 Nov 2025 15:49:33 +0000 Subject: [PATCH 3/9] added playwright config file, deleted original playwright folder and moved "some.test" file --- package.json | 3 ++ playwright.config.ts | 28 +++++++++++++++++++ .../web/specs}/some.test.ts | 0 3 files changed, 31 insertions(+) create mode 100644 playwright.config.ts rename tests/{playwright => e2e/web/specs}/some.test.ts (100%) diff --git a/package.json b/package.json index 131eb76a..97639059 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,9 @@ "sync-android": "./scripts/sync_android.sh", "migrate": "./scripts/migrate.sh", "test": "jest", + "playwright": "playwright test", + "playwright:ui": "playwright test --ui", + "playwright:debug": "playwright test --debug", "test:watch": "jest --watch", "test:coverage": "jest --coverage", "test:update": "jest --updateSnapshot", diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 00000000..6e50ace9 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,28 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + testDir: './tests/e2e', + fullyParallel: true, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 2 : 0, + workers: process.env.CI ? 1 : undefined, + reporter: 'html', + use: { + baseURL: 'http://localhost:3000', + trace: 'on-first-retry', + }, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + // { + // name: 'firefox', + // use: { ...devices['Desktop Firefox'] }, + // }, + // { + // name: 'webkit', + // use: { ...devices['Desktop Safari'] }, + // }, + ], +}); \ No newline at end of file diff --git a/tests/playwright/some.test.ts b/tests/e2e/web/specs/some.test.ts similarity index 100% rename from tests/playwright/some.test.ts rename to tests/e2e/web/specs/some.test.ts From b3a6b315576d33060ffe3559aa4d37ca1bef4505 Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams Date: Fri, 7 Nov 2025 16:43:56 +0000 Subject: [PATCH 4/9] continued test structure setup --- .gitignore | 3 +++ package.json | 1 + playwright.config.ts | 2 +- tests/e2e/web/specs/some.test.ts | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9e813edd..29d68d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,9 @@ # testing /coverage +# Playwright +/tests/reports/playwright-report + # next.js /.next/ /out/ diff --git a/package.json b/package.json index 97639059..4df114de 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "playwright": "playwright test", "playwright:ui": "playwright test --ui", "playwright:debug": "playwright test --debug", + "playwright:report": "npx playwright show-report tests/reports/playwright-report", "test:watch": "jest --watch", "test:coverage": "jest --coverage", "test:update": "jest --updateSnapshot", diff --git a/playwright.config.ts b/playwright.config.ts index 6e50ace9..88f48476 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -6,7 +6,7 @@ export default defineConfig({ forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, workers: process.env.CI ? 1 : undefined, - reporter: 'html', + reporter: [['html', {outputFolder: `tests/reports/playwright-report`, open: 'on-falure'}]], use: { baseURL: 'http://localhost:3000', trace: 'on-first-retry', diff --git a/tests/e2e/web/specs/some.test.ts b/tests/e2e/web/specs/some.test.ts index c5383a52..1e7e2c40 100644 --- a/tests/e2e/web/specs/some.test.ts +++ b/tests/e2e/web/specs/some.test.ts @@ -1,7 +1,8 @@ import {expect, test} from '@playwright/test'; test('shows', async ({page}) => { - // await page.goto('http://localhost:3000/profile'); // Adjust this to your route + await page.goto('/'); // Adjust this to your route + expect(await page.title()).toBe('Compass'); // // const spinner = page.locator('[data-testid="spinner"]'); // await expect(spinner).toBeVisible(); From d91d2af35f13969dfbc247a1743d2293b97a8e76 Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams Date: Fri, 7 Nov 2025 21:15:36 +0000 Subject: [PATCH 5/9] Updating test folder structure --- .github/workflows/ci.yml | 4 ++-- tests/e2e/web/{pageManager => .auth}/.keep | 0 tests/e2e/web/components/.keep | 0 tests/e2e/web/pages/.keep | 0 tests/e2e/web/utils/.keep | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename tests/e2e/web/{pageManager => .auth}/.keep (100%) create mode 100644 tests/e2e/web/components/.keep create mode 100644 tests/e2e/web/pages/.keep create mode 100644 tests/e2e/web/utils/.keep diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56005eaf..fd5edb0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,13 +48,13 @@ jobs: - name: Run E2E tests env: NEXT_PUBLIC_API_URL: localhost:8088 - NEXT_PUBLIC_FIREBASE_ENV: PROD + NEXT_PUBLIC_FIREBASE_ENV: DEV NEXT_PUBLIC_FIREBASE_API_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }} NEXT_PUBLIC_SUPABASE_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_KEY }} run: | yarn --cwd=web serve & npx wait-on http://localhost:3000 - npx playwright test tests/playwright + npx playwright test tests/e2e SERVER_PID=$(fuser -k 3000/tcp) echo $SERVER_PID kill $SERVER_PID diff --git a/tests/e2e/web/pageManager/.keep b/tests/e2e/web/.auth/.keep similarity index 100% rename from tests/e2e/web/pageManager/.keep rename to tests/e2e/web/.auth/.keep diff --git a/tests/e2e/web/components/.keep b/tests/e2e/web/components/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/web/pages/.keep b/tests/e2e/web/pages/.keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/web/utils/.keep b/tests/e2e/web/utils/.keep new file mode 100644 index 00000000..e69de29b From 266a2b44e0d594d8f3de7f168594e79c39452d11 Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams Date: Tue, 11 Nov 2025 14:41:48 +0000 Subject: [PATCH 6/9] Added database seeding script and backend testing folder structure --- package.json | 1 + tests/e2e/backend/{ => config}/.keep | 0 tests/e2e/backend/fixtures/base.ts | 16 +++ tests/e2e/backend/specs/api.test.ts | 14 +++ tests/e2e/backend/specs/db.test.ts | 78 +++++++++++++ tests/e2e/backend/utils/userCreation.ts | 124 +++++++++++++++++++++ tests/e2e/backend/utils/userInformation.ts | 111 ++++++++++++++++++ yarn.lock | 5 + 8 files changed, 349 insertions(+) rename tests/e2e/backend/{ => config}/.keep (100%) create mode 100644 tests/e2e/backend/fixtures/base.ts create mode 100644 tests/e2e/backend/specs/api.test.ts create mode 100644 tests/e2e/backend/specs/db.test.ts create mode 100644 tests/e2e/backend/utils/userCreation.ts create mode 100644 tests/e2e/backend/utils/userInformation.ts diff --git a/package.json b/package.json index 4df114de..68a7479e 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@capacitor/android": "7.4.4", "@capacitor/assets": "3.0.5", "@capacitor/cli": "7.4.4", + "@faker-js/faker": "10.1.0", "@testing-library/dom": "^10.0.0", "@testing-library/jest-dom": "^6.6.4", "@testing-library/react": "^16.3.0", diff --git a/tests/e2e/backend/.keep b/tests/e2e/backend/config/.keep similarity index 100% rename from tests/e2e/backend/.keep rename to tests/e2e/backend/config/.keep diff --git a/tests/e2e/backend/fixtures/base.ts b/tests/e2e/backend/fixtures/base.ts new file mode 100644 index 00000000..20498845 --- /dev/null +++ b/tests/e2e/backend/fixtures/base.ts @@ -0,0 +1,16 @@ +import { test as base, APIRequestContext, request } from '@playwright/test'; + +export type TestOptions = { + apiContextPage: APIRequestContext, +} + +export const test = base.extend({ + apiContextPage: async ({}, use) => { + const apiContext = await request.newContext({ + baseURL: 'https://api.compassmeet.com' + }); + await use(apiContext) + }, +}) + +export { expect } from "@playwright/test" \ No newline at end of file diff --git a/tests/e2e/backend/specs/api.test.ts b/tests/e2e/backend/specs/api.test.ts new file mode 100644 index 00000000..59885955 --- /dev/null +++ b/tests/e2e/backend/specs/api.test.ts @@ -0,0 +1,14 @@ +import { test, expect } from "../fixtures/base"; + +test('Check API health', async ({apiContextPage}) => { + const responseHealth = await apiContextPage.get('/health'); + expect(responseHealth.status()).toBe(200) + + const responseBody = await responseHealth.json() + console.log(JSON.stringify(responseBody, null, 2)); + +}); + +test.afterAll(async ({apiContextPage}) => { + await apiContextPage?.dispose(); +}) diff --git a/tests/e2e/backend/specs/db.test.ts b/tests/e2e/backend/specs/db.test.ts new file mode 100644 index 00000000..f01143d3 --- /dev/null +++ b/tests/e2e/backend/specs/db.test.ts @@ -0,0 +1,78 @@ +import {expect, test } from '@playwright/test'; +import { createSupabaseDirectClient } from "../../../../backend/shared/src/supabase/init"; + +test('View database', async () => { + const dbClient = createSupabaseDirectClient() + const queryUserID = ` + SELECT p.* + FROM public.profiles AS p + WHERE id = $1 + `; + + const queryTableColumns = ` + SELECT + column_name, + data_type, + character_maximum_length, + is_nullable, + column_default + FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name ='profiles' + ORDER BY ordinal_position; + `; + + const queryTableColumnsNullable = ` + SELECT + column_name, + data_type, + character_maximum_length, + column_default + FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name =$1 + AND is_nullable = $2 + ORDER BY ordinal_position; + `; + + const queryInsertUserProfile = ` + INSERT INTO profiles (name, username) + VALUES ($1, $2) + RETURNING *; + `; + + const queryInsertUsers = ` + INSERT INTO profiles (id, bio) + VALUES ($1, $2) + RETURNING *; + `; + + + const rows = await dbClient.query( + queryInsertUsers, + [ + 'JFTZOhrBagPk', + { + "type": "doc", + "content": [ + { + "type": "paragraph", + "content": [ + { + "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", + "type": "text" + } + ] + } + ] + } + ] + ) + + console.log("Type of: ",typeof(rows)); + console.log("Number of rows: ",rows.length); + + console.log(JSON.stringify(await rows, null, 2)); + + +}) \ No newline at end of file diff --git a/tests/e2e/backend/utils/userCreation.ts b/tests/e2e/backend/utils/userCreation.ts new file mode 100644 index 00000000..d1b768f8 --- /dev/null +++ b/tests/e2e/backend/utils/userCreation.ts @@ -0,0 +1,124 @@ +//Run with: +// export ENVIRONMENT=DEV && ./scripts/build_api.sh && npx tsx ./tests/e2e/backend/utils/userCreation.ts + +import {createSupabaseDirectClient} from "../../../../backend/shared/lib/supabase/init"; +import {insert} from "../../../../backend/shared/lib/supabase/utils"; +import {PrivateUser} from "../../../../common/lib/user"; +import {getDefaultNotificationPreferences} from "../../../../common/lib/user-notification-preferences"; +import {randomString} from "../../../../common/lib/util/random"; +import UserAccountInformation from "./userInformation"; + +type ProfileType = 'basic' | 'medium' | 'full' + +/** + * Function used to populate the database with profiles. + * + * @param pg - Supabase client used to access the database. + * @param userInfo - Class object containing information to create a user account generated by `fakerjs`. + * @param profileType - Optional param used to signify how much information is used in the account generation. + */ +async function seedDatabase (pg: any, userInfo: UserAccountInformation, profileType?: string) { + + const userId = userInfo.user_id + const deviceToken = randomString() + const bio = { + "type": "doc", + "content": [ + { + "type": "paragraph", + "content": [ + { + "text": userInfo.bio, + "type": "text" + } + ] + } + ] + } + const basicProfile = { + user_id: userId, + bio_length: userInfo.bio.length, + bio: bio, + age: userInfo.age, + born_in_location: userInfo.born_in_location, + company: userInfo.company, + } + + const mediumProfile = { + ...basicProfile, + drinks_per_month: userInfo.drinks_per_month, + diet: [userInfo.randomElement(userInfo.diet)], + education_level: userInfo.randomElement(userInfo.education_level), + ethnicity: [userInfo.randomElement(userInfo.ethnicity)], + gender: userInfo.randomElement(userInfo.gender), + height_in_inches: userInfo.height_in_inches, + pref_gender: [userInfo.randomElement(userInfo.pref_gender)], + pref_age_min: userInfo.pref_age.min, + pref_age_max: userInfo.pref_age.max, + } + + const fullProfile = { + ...mediumProfile, + occupation_title: userInfo.occupation_title, + political_beliefs: [userInfo.randomElement(userInfo.political_beliefs)], + pref_relation_styles: [userInfo.randomElement(userInfo.pref_relation_styles)], + religion: [userInfo.randomElement(userInfo.religion)], + } + + const profileData = profileType === 'basic' ? basicProfile + : profileType === 'medium' ? mediumProfile + : fullProfile + + const user = { + // avatarUrl, + isBannedFromPosting: false, + link: {}, + } + + const privateUser: PrivateUser = { + id: userId, + email: userInfo.email, + initialIpAddress: userInfo.ip, + initialDeviceToken: deviceToken, + notificationPreferences: getDefaultNotificationPreferences(), + blockedUserIds: [], + blockedByUserIds: [], + } + + await pg.tx(async (tx:any) => { + + await insert(tx, 'users', { + id: userId, + name: userInfo.name, + username: userInfo.name, + data: user, + }) + + await insert(tx, 'private_users', { + id: userId, + data: privateUser, + }) + + await insert(tx, 'profiles', profileData ) + + }) +} + +(async () => { + const pg = createSupabaseDirectClient() + + //Edit the count seedConfig to specify the amount of each profiles to create + const seedConfig = [ + { count: 1, profileType: 'basic' as ProfileType }, + { count: 1, profileType: 'medium' as ProfileType }, + { count: 1, profileType: 'full' as ProfileType }, + ] + + for (const {count, profileType } of seedConfig) { + for (let i = 0; i < count; i++) { + const userInfo = new UserAccountInformation() + await seedDatabase(pg, userInfo, profileType) + } + } + process.exit(0) +})() \ No newline at end of file diff --git a/tests/e2e/backend/utils/userInformation.ts b/tests/e2e/backend/utils/userInformation.ts new file mode 100644 index 00000000..f2d5b6c1 --- /dev/null +++ b/tests/e2e/backend/utils/userInformation.ts @@ -0,0 +1,111 @@ +import { faker } from "@faker-js/faker"; + +class UserAccountInformation { + + name = faker.person.fullName(); + email = faker.internet.email(); + user_id = faker.string.alpha(28) + password = faker.internet.password(); + ip = faker.internet.ip() + age = faker.number.int({min: 18, max:100}); + bio = faker.lorem.words({min: 200, max:350}); + born_in_location = faker.location.country(); + gender = [ + 'Female', + 'Male', + 'Other' + ]; + + pref_gender = [ + 'Female', + 'Male', + 'Other' + ]; + + pref_age = { + min: faker.number.int({min: 18, max:27}), + max: faker.number.int({min: 36, max:68}) + }; + + pref_relation_styles = [ + 'Collaboration', + 'Friendship', + 'Relationship' + ]; + + political_beliefs = [ + 'Progressive', + 'Liberal', + 'Moderate / Centrist', + 'Conservative', + 'Socialist', + 'Nationalist', + 'Populist', + 'Green / Eco-Socialist', + 'Technocratic', + 'Libertarian', + 'Effective Accelerationism', + 'Pause AI / Tech Skeptic', + 'Independent / Other', + ]; + + religion = [ + 'Atheist', + 'Agnostic', + 'Spiritual', + 'Christian', + 'Muslim', + 'Jewish', + 'Hindu', + 'Buddhist', + 'Sikh', + 'Taoist', + 'Jain', + 'Shinto', + 'Animist', + 'Zoroastrian', + 'Unitarian Universalist', + 'Other', + ]; + + diet = [ + 'Omnivore', + 'Vegetarian', + 'Vegan', + 'Keto', + 'Paleo', + 'Pescetarian', + 'Other', + ]; + + drinks_per_month = faker.number.int({min: 4, max:40}); + height_in_inches = faker.number.float({min: 56, max: 78, fractionDigits:2}); + ethnicity = [ + 'Black/African origin', + 'East Asian', + 'South/Southeast Asian', + 'White/Caucasian', + 'Hispanic/Latino', + 'Middle Eastern', + 'Native American/Indigenous', + 'Other', + ]; + + education_level = [ + 'High school', + 'College', + 'Bachelors', + 'Masters', + 'PhD', + ]; + company = faker.company.name(); + occupation_title = faker.person.jobTitle(); + university = faker.company.name(); + + randomElement (array: Array) { + return array[Math.floor(Math.random() * array.length)].toLowerCase() + } +} + + +export default UserAccountInformation; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 5d15be8c..b091bc64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1386,6 +1386,11 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== +"@faker-js/faker@10.1.0": + version "10.1.0" + resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-10.1.0.tgz#eb72869d01ccbff41a77aa7ac851ce1ac9371129" + integrity sha512-C3mrr3b5dRVlKPJdfrAXS8+dq+rq8Qm5SNRazca0JKgw1HQERFmrVb0towvMmw5uu8hHKNiQasMaR/tydf3Zsg== + "@fastify/busboy@^3.0.0": version "3.2.0" resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-3.2.0.tgz#13ed8212f3b9ba697611529d15347f8528058cea" From 18f24e2043a64b193626134b236b68d38852a64e Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams Date: Tue, 11 Nov 2025 14:56:56 +0000 Subject: [PATCH 7/9] removed the database test --- tests/e2e/backend/specs/db.test.ts | 126 ++++++++++++++--------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/tests/e2e/backend/specs/db.test.ts b/tests/e2e/backend/specs/db.test.ts index f01143d3..0cedb79c 100644 --- a/tests/e2e/backend/specs/db.test.ts +++ b/tests/e2e/backend/specs/db.test.ts @@ -2,77 +2,77 @@ import {expect, test } from '@playwright/test'; import { createSupabaseDirectClient } from "../../../../backend/shared/src/supabase/init"; test('View database', async () => { - const dbClient = createSupabaseDirectClient() - const queryUserID = ` - SELECT p.* - FROM public.profiles AS p - WHERE id = $1 - `; + // const dbClient = createSupabaseDirectClient() + // const queryUserID = ` + // SELECT p.* + // FROM public.profiles AS p + // WHERE id = $1 + // `; - const queryTableColumns = ` - SELECT - column_name, - data_type, - character_maximum_length, - is_nullable, - column_default - FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name ='profiles' - ORDER BY ordinal_position; - `; + // const queryTableColumns = ` + // SELECT + // column_name, + // data_type, + // character_maximum_length, + // is_nullable, + // column_default + // FROM information_schema.columns + // WHERE table_schema = 'public' + // AND table_name ='profiles' + // ORDER BY ordinal_position; + // `; - const queryTableColumnsNullable = ` - SELECT - column_name, - data_type, - character_maximum_length, - column_default - FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name =$1 - AND is_nullable = $2 - ORDER BY ordinal_position; - `; + // const queryTableColumnsNullable = ` + // SELECT + // column_name, + // data_type, + // character_maximum_length, + // column_default + // FROM information_schema.columns + // WHERE table_schema = 'public' + // AND table_name =$1 + // AND is_nullable = $2 + // ORDER BY ordinal_position; + // `; - const queryInsertUserProfile = ` - INSERT INTO profiles (name, username) - VALUES ($1, $2) - RETURNING *; - `; + // const queryInsertUserProfile = ` + // INSERT INTO profiles (name, username) + // VALUES ($1, $2) + // RETURNING *; + // `; - const queryInsertUsers = ` - INSERT INTO profiles (id, bio) - VALUES ($1, $2) - RETURNING *; - `; + // const queryInsertUsers = ` + // INSERT INTO profiles (id, bio) + // VALUES ($1, $2) + // RETURNING *; + // `; - const rows = await dbClient.query( - queryInsertUsers, - [ - 'JFTZOhrBagPk', - { - "type": "doc", - "content": [ - { - "type": "paragraph", - "content": [ - { - "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", - "type": "text" - } - ] - } - ] - } - ] - ) + // const rows = await dbClient.query( + // queryInsertUsers, + // [ + // 'JFTZOhrBagPk', + // { + // "type": "doc", + // "content": [ + // { + // "type": "paragraph", + // "content": [ + // { + // "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", + // "type": "text" + // } + // ] + // } + // ] + // } + // ] + // ) - console.log("Type of: ",typeof(rows)); - console.log("Number of rows: ",rows.length); + // console.log("Type of: ",typeof(rows)); + // console.log("Number of rows: ",rows.length); - console.log(JSON.stringify(await rows, null, 2)); + // console.log(JSON.stringify(await rows, null, 2)); }) \ No newline at end of file From c949891ed649cdd1d6c2912c3568cf1fdd8341ee Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams Date: Tue, 11 Nov 2025 15:57:34 +0000 Subject: [PATCH 8/9] Replaced db seeding script --- .../backend/utils => scripts}/userCreation.ts | 16 ++--- scripts/users.ts | 58 ------------------- 2 files changed, 8 insertions(+), 66 deletions(-) rename {tests/e2e/backend/utils => scripts}/userCreation.ts (87%) delete mode 100644 scripts/users.ts diff --git a/tests/e2e/backend/utils/userCreation.ts b/scripts/userCreation.ts similarity index 87% rename from tests/e2e/backend/utils/userCreation.ts rename to scripts/userCreation.ts index d1b768f8..d0ba3416 100644 --- a/tests/e2e/backend/utils/userCreation.ts +++ b/scripts/userCreation.ts @@ -1,12 +1,12 @@ //Run with: -// export ENVIRONMENT=DEV && ./scripts/build_api.sh && npx tsx ./tests/e2e/backend/utils/userCreation.ts - -import {createSupabaseDirectClient} from "../../../../backend/shared/lib/supabase/init"; -import {insert} from "../../../../backend/shared/lib/supabase/utils"; -import {PrivateUser} from "../../../../common/lib/user"; -import {getDefaultNotificationPreferences} from "../../../../common/lib/user-notification-preferences"; -import {randomString} from "../../../../common/lib/util/random"; -import UserAccountInformation from "./userInformation"; +// export ENVIRONMENT=DEV && ./scripts/build_api.sh && npx tsx ./scripts/userCreation.ts + +import {createSupabaseDirectClient} from "../backend/shared/lib/supabase/init"; +import {insert} from "../backend/shared/lib/supabase/utils"; +import {PrivateUser} from "../common/lib/user"; +import {getDefaultNotificationPreferences} from "../common/lib/user-notification-preferences"; +import {randomString} from "../common/lib/util/random"; +import UserAccountInformation from "../tests/e2e/backend/utils/userInformation"; type ProfileType = 'basic' | 'medium' | 'full' diff --git a/scripts/users.ts b/scripts/users.ts deleted file mode 100644 index bf13be82..00000000 --- a/scripts/users.ts +++ /dev/null @@ -1,58 +0,0 @@ -// This is a script to add a user to the DB: entries in the users and private_users table -// Run with: -// export ENVIRONMENT=DEV && ./../scripts/build_api.sh && npx tsx users.ts - -import {createSupabaseDirectClient} from "shared/lib/supabase/init"; -import {insert} from "shared/lib/supabase/utils"; -import {PrivateUser} from "common/lib/user"; -import {getDefaultNotificationPreferences} from "common/lib/user-notification-preferences"; -import {randomString} from "common/lib/util/random"; - -(async () => { - - const userId = '...' - const email = '...' - const name = '...' - const username = '...' - const ip = '...' - const deviceToken = randomString() - const pg = createSupabaseDirectClient() - - const user = { - // avatarUrl, - isBannedFromPosting: false, - link: {}, - } - - const privateUser: PrivateUser = { - id: userId, - email, - initialIpAddress: ip, - initialDeviceToken: deviceToken, - notificationPreferences: getDefaultNotificationPreferences(), - blockedUserIds: [], - blockedByUserIds: [], - } - - await pg.tx(async (tx) => { - - const newUserRow = await insert(tx, 'users', { - id: userId, - name, - username, - data: user, - }) - - console.log(newUserRow) - - const newPrivateUserRow = await insert(tx, 'private_users', { - id: userId, - data: privateUser, - }) - - console.log(newPrivateUserRow) - - }) - - process.exit(0) -})() From dfd5b6f8ad2f175a1b147fac4bcc64df2d462014 Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams Date: Tue, 11 Nov 2025 16:50:54 +0000 Subject: [PATCH 9/9] Updated userInformation.ts to use values from choices.tsx --- tests/e2e/backend/utils/userInformation.ts | 84 ++++------------------ 1 file changed, 14 insertions(+), 70 deletions(-) diff --git a/tests/e2e/backend/utils/userInformation.ts b/tests/e2e/backend/utils/userInformation.ts index f2d5b6c1..2cd60b17 100644 --- a/tests/e2e/backend/utils/userInformation.ts +++ b/tests/e2e/backend/utils/userInformation.ts @@ -1,4 +1,12 @@ import { faker } from "@faker-js/faker"; +import { + RELATIONSHIP_CHOICES, + POLITICAL_CHOICES, + RELIGION_CHOICES, + DIET_CHOICES, + EDUCATION_CHOICES, + } from "../../../../web/components/filters/choices"; +import { Races } from "../../../../web/components/race"; class UserAccountInformation { @@ -27,77 +35,14 @@ class UserAccountInformation { max: faker.number.int({min: 36, max:68}) }; - pref_relation_styles = [ - 'Collaboration', - 'Friendship', - 'Relationship' - ]; - - political_beliefs = [ - 'Progressive', - 'Liberal', - 'Moderate / Centrist', - 'Conservative', - 'Socialist', - 'Nationalist', - 'Populist', - 'Green / Eco-Socialist', - 'Technocratic', - 'Libertarian', - 'Effective Accelerationism', - 'Pause AI / Tech Skeptic', - 'Independent / Other', - ]; - - religion = [ - 'Atheist', - 'Agnostic', - 'Spiritual', - 'Christian', - 'Muslim', - 'Jewish', - 'Hindu', - 'Buddhist', - 'Sikh', - 'Taoist', - 'Jain', - 'Shinto', - 'Animist', - 'Zoroastrian', - 'Unitarian Universalist', - 'Other', - ]; - - diet = [ - 'Omnivore', - 'Vegetarian', - 'Vegan', - 'Keto', - 'Paleo', - 'Pescetarian', - 'Other', - ]; - + pref_relation_styles = Object.values(RELATIONSHIP_CHOICES); + political_beliefs = Object.values(POLITICAL_CHOICES); + religion = Object.values(RELIGION_CHOICES); + diet = Object.values(DIET_CHOICES); drinks_per_month = faker.number.int({min: 4, max:40}); height_in_inches = faker.number.float({min: 56, max: 78, fractionDigits:2}); - ethnicity = [ - 'Black/African origin', - 'East Asian', - 'South/Southeast Asian', - 'White/Caucasian', - 'Hispanic/Latino', - 'Middle Eastern', - 'Native American/Indigenous', - 'Other', - ]; - - education_level = [ - 'High school', - 'College', - 'Bachelors', - 'Masters', - 'PhD', - ]; + ethnicity = Object.values(Races); + education_level = Object.values(EDUCATION_CHOICES); company = faker.company.name(); occupation_title = faker.person.jobTitle(); university = faker.company.name(); @@ -107,5 +52,4 @@ class UserAccountInformation { } } - export default UserAccountInformation; \ No newline at end of file