From 6b11e6b060fb05c9cf6fc6d4682683fe803d526d Mon Sep 17 00:00:00 2001 From: Okechi Jones-Williams <55924431+O-Bots@users.noreply.github.com> Date: Sat, 15 Nov 2025 14:35:45 +0000 Subject: [PATCH] Add minor changes to tests (#20) * setting up test structure * . * added playwright config file, deleted original playwright folder and moved "some.test" file * continued test structure setup * Updating test folder structure * Added database seeding script and backend testing folder structure * removed the database test * Replaced db seeding script * Updated userInformation.ts to use values from choices.tsx * merge prep * removing extra unit test, moving api test to correct folder --- backend/api/tests/unit/get-users.unit.test.ts | 1 + package.json | 3 + playwright.config.ts | 2 +- tests/e2e/backend/fixtures/base.ts | 16 +++- tests/e2e/backend/specs/api.test.ts | 14 ---- tests/e2e/backend/specs/api/api.test.ts | 10 +++ tests/e2e/backend/specs/db.test.ts | 81 ++----------------- tests/e2e/backend/utils/database.ts | 27 +++++++ 8 files changed, 61 insertions(+), 93 deletions(-) delete mode 100644 tests/e2e/backend/specs/api.test.ts create mode 100644 tests/e2e/backend/specs/api/api.test.ts create mode 100644 tests/e2e/backend/utils/database.ts diff --git a/backend/api/tests/unit/get-users.unit.test.ts b/backend/api/tests/unit/get-users.unit.test.ts index 36ca0e3f..f1deb7b5 100644 --- a/backend/api/tests/unit/get-users.unit.test.ts +++ b/backend/api/tests/unit/get-users.unit.test.ts @@ -2,6 +2,7 @@ import { getUser } from "api/get-user"; import { createSupabaseDirectClient } from "shared/supabase/init"; import { toUserAPIResponse } from "common/api/user-types"; import { convertUser } from "common/supabase/users"; +import { APIError } from "common/src/api/utils"; jest.mock("shared/supabase/init"); jest.mock("common/supabase/users"); diff --git a/package.json b/package.json index 3822e1b4..224ffcd4 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "@capacitor/assets": "3.0.5", "@capacitor/cli": "7.4.4", "@faker-js/faker": "10.1.0", + "@types/jest": "29.2.4", "@testing-library/dom": "^10.0.0", "@testing-library/jest-dom": "^6.6.4", "@testing-library/react": "^16.3.0", @@ -64,11 +65,13 @@ "eslint": "8.57.0", "eslint-plugin-lodash": "^7.4.0", "eslint-plugin-unused-imports": "4.1.4", + "jest": "29.3.1", "nodemon": "2.0.20", "prettier": "3.6.2", "prettier-plugin-sql": "0.19.2", "prettier-plugin-tailwindcss": "^0.2.1", "ts-node": "10.9.1", + "ts-jest": "29.0.3", "tsc-alias": "1.8.2", "tsconfig-paths": "4.2.0", "tsx": "4.20.6", diff --git a/playwright.config.ts b/playwright.config.ts index 88f48476..532141d5 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', {outputFolder: `tests/reports/playwright-report`, open: 'on-falure'}]], + reporter: [['html', {outputFolder: `tests/reports/playwright-report`, open: 'on-failure'}]], use: { baseURL: 'http://localhost:3000', trace: 'on-first-retry', diff --git a/tests/e2e/backend/fixtures/base.ts b/tests/e2e/backend/fixtures/base.ts index 20498845..6284f6f7 100644 --- a/tests/e2e/backend/fixtures/base.ts +++ b/tests/e2e/backend/fixtures/base.ts @@ -1,15 +1,25 @@ import { test as base, APIRequestContext, request } from '@playwright/test'; +import { createSupabaseDirectClient } from "../../../../backend/shared/src/supabase/init"; export type TestOptions = { - apiContextPage: APIRequestContext, + backendPage: { + api: APIRequestContext, + db: any + } } export const test = base.extend({ - apiContextPage: async ({}, use) => { + backendPage: async ({}, use) => { const apiContext = await request.newContext({ baseURL: 'https://api.compassmeet.com' }); - await use(apiContext) + + const helpers = { + api: apiContext, + db: createSupabaseDirectClient() + } + await use(helpers) + await apiContext.dispose(); }, }) diff --git a/tests/e2e/backend/specs/api.test.ts b/tests/e2e/backend/specs/api.test.ts deleted file mode 100644 index 59885955..00000000 --- a/tests/e2e/backend/specs/api.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -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/api/api.test.ts b/tests/e2e/backend/specs/api/api.test.ts new file mode 100644 index 00000000..cfe567fc --- /dev/null +++ b/tests/e2e/backend/specs/api/api.test.ts @@ -0,0 +1,10 @@ +import { test, expect } from "../../fixtures/base"; + +test('Check API health', async ({backendPage}) => { + const responseHealth = await backendPage.api.get('/health'); + expect(responseHealth.status()).toBe(200) + + // const responseBody = await responseHealth.json() + // console.log(JSON.stringify(responseBody, null, 2)); + +}); diff --git a/tests/e2e/backend/specs/db.test.ts b/tests/e2e/backend/specs/db.test.ts index 0cedb79c..4faf178d 100644 --- a/tests/e2e/backend/specs/db.test.ts +++ b/tests/e2e/backend/specs/db.test.ts @@ -1,78 +1,9 @@ -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)); +import {expect, test } from '../fixtures/base'; +import { databaseUtils } from "../utils/database"; +test('View database', async ({backendPage}) => { + const userAccount = await databaseUtils.findUserByName(backendPage, 'Franklin Buckridge') + const userProfile = await databaseUtils.findProfileById(backendPage, userAccount.id) + console.log(userAccount); }) \ No newline at end of file diff --git a/tests/e2e/backend/utils/database.ts b/tests/e2e/backend/utils/database.ts new file mode 100644 index 00000000..cc9fa6ac --- /dev/null +++ b/tests/e2e/backend/utils/database.ts @@ -0,0 +1,27 @@ +class DatabaseTestingUtilities { + findUserByName = async (page: any, name: string) => { + const queryUserById = ` + SELECT p.* + FROM public.users AS p + WHERE name = $1 + `; + const userResults = await page.db.query(queryUserById,[name]) + return userResults[0] + } + + findProfileById = async (page: any, user_id: string) => { + const queryProfileById = ` + SELECT + p.*, + TO_CHAR(p.created_time, 'Mon DD, YYYY HH12:MI AM') as created_date, + TO_CHAR(p.last_modification_time, 'Mon DD, YYYY HH12:MI AM') as modified_date + FROM public.profiles AS p + WHERE user_id = $1 + `; + const profileResults = await page.db.query(queryProfileById,[user_id]) + return profileResults[0] + } + +} + +export const databaseUtils = new DatabaseTestingUtilities(); \ No newline at end of file