From 0c2e2a58eff55199da5cf446eaf30c16db02ec95 Mon Sep 17 00:00:00 2001 From: Kevin Cai Date: Wed, 11 Oct 2023 14:23:43 -0700 Subject: [PATCH] feat/Queries_test --- src/app/page.tsx | 19 ++++++-- src/supabase/order_queries.ts | 1 - src/supabase/pickup_queries.ts | 2 +- src/supabase/product_queries.ts | 6 +-- src/supabase/tests/order_test.ts | 75 ++++++++++++++++++++++++++++++ src/supabase/tests/pickup_test.ts | 28 +++++++++++ src/supabase/tests/product_test.ts | 28 +++++++++++ src/supabase/tests/user_test.ts | 17 ++++--- src/supabase/user_queries.ts | 4 +- tsconfig.json | 2 +- 10 files changed, 164 insertions(+), 18 deletions(-) create mode 100644 src/supabase/tests/order_test.ts create mode 100644 src/supabase/tests/pickup_test.ts create mode 100644 src/supabase/tests/product_test.ts diff --git a/src/app/page.tsx b/src/app/page.tsx index 289e3ba8..7be7b3ab 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,11 +1,24 @@ import Link from 'next/link'; -import {testFetchData,testFetchUserByUUID, testAddUserAddress} from "../supabase/tests/user_test" ; +import {testFetchUserData,testFetchUserByUUID, testAddUserAddress} from "../supabase/tests/user_test" ; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import {testFetchOrderByUUID, testFetchOrders, testGetOrderById, testToggleOrderProgress, testUpdateAllOrdersProgressToTrue} from "../supabase/tests/order_test" ; +import {testFetchProducts, testFetchProductByName} from "../supabase/tests/product_test" ; +import {testFetchPickupData, testFetchPickupTimesByUUID } from "../supabase/tests/pickup_test" export default function Checkout() { - testFetchData(); + testFetchUserData(); testFetchUserByUUID(); testAddUserAddress(); - + testFetchOrderByUUID(); + testFetchOrders(); + testGetOrderById(); + testToggleOrderProgress(); + testFetchProducts(); + testFetchProductByName(); + testFetchPickupData(); + testFetchPickupTimesByUUID(); + // testUpdateAllOrdersProgressToTrue(); + return (
Login diff --git a/src/supabase/order_queries.ts b/src/supabase/order_queries.ts index f40d6b5f..8b143762 100644 --- a/src/supabase/order_queries.ts +++ b/src/supabase/order_queries.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable no-console */ // diff --git a/src/supabase/pickup_queries.ts b/src/supabase/pickup_queries.ts index a34a84dd..99b408f4 100644 --- a/src/supabase/pickup_queries.ts +++ b/src/supabase/pickup_queries.ts @@ -17,7 +17,7 @@ const supabaseApiKey = process.env.SUPABASE_KEY const supabase = createClient(supabaseUrl, supabaseApiKey ?? ''); -export async function fetchData(): Promise< +export async function fetchPickupData(): Promise< PostgrestSingleResponse | { data: never[]; error: PostgrestError } > { try { diff --git a/src/supabase/product_queries.ts b/src/supabase/product_queries.ts index 09673897..72b8bcf5 100644 --- a/src/supabase/product_queries.ts +++ b/src/supabase/product_queries.ts @@ -36,14 +36,14 @@ export async function fetchProducts(): Promise< } } -export async function fetchProductByName( - productName: string, +export async function fetchProductByID( + productId: string, ): Promise> { try { const { data: product, error } = await supabase .from('Product') .select('*') - .eq('name', productName) + .eq('product_id', productId) .single(); if (error) { diff --git a/src/supabase/tests/order_test.ts b/src/supabase/tests/order_test.ts new file mode 100644 index 00000000..47510f91 --- /dev/null +++ b/src/supabase/tests/order_test.ts @@ -0,0 +1,75 @@ +/* eslint-disable no-console */ +// + +import { + fetchOrders, + fetchOrderByUUID, + getOrdersByUserId, + getOrderById, + toggleOrderProgress, + updateAllOrdersProgressToTrue, +} from '../order_queries'; // Replace './your-module' with the actual path to your module + +// Test fetching all orders +export async function testFetchOrders() { + try { + const result = await fetchOrders(); + console.log('Fetch Orders Result:', result); + } catch (error) { + console.error('Test Fetch Orders Error:', error); + } +} + +// Test fetching an order by UUID +export async function testFetchOrderByUUID() { + const uuid = 'SAMPLE_ORDER_ID'; // Replace with a valid order ID + try { + const result = await fetchOrderByUUID(uuid); + console.log('Fetch Order by UUID Result:', result); + } catch (error) { + console.error('Test Fetch Order by UUID Error:', error); + } +} + +// Test fetching orders by user ID +export async function testGetOrdersByUserId() { + const userId = '3b4a1317-b9ea-4cbd-95d7-e959aa80d1ea'; // Replace with a valid user ID + try { + const result = await getOrdersByUserId(userId); + console.log('Get Orders by User ID Result:', result); + } catch (error) { + console.error('Test Get Orders by User ID Error:', error); + } +} + +// Test fetching an order by ID +export async function testGetOrderById() { + const orderId = '2'; // Replace with a valid order ID + try { + const result = await getOrderById(orderId); + console.log('Get Order by ID Result:', result); + } catch (error) { + console.error('Test Get Order by ID Error:', error); + } +} + +// Test toggling order progress +export async function testToggleOrderProgress() { + const orderId = '2'; // Replace with a valid order ID + try { + const result = await toggleOrderProgress(orderId); + console.log('Toggle Order Progress Result:', result); + } catch (error) { + console.error('Test Toggle Order Progress Error:', error); + } +} + +// Test updating all orders' progress to true +export async function testUpdateAllOrdersProgressToTrue() { + try { + const result = await updateAllOrdersProgressToTrue(); + console.log('Update All Orders Progress Result:', result); + } catch (error) { + console.error('Test Update All Orders Progress Error:', error); + } +} diff --git a/src/supabase/tests/pickup_test.ts b/src/supabase/tests/pickup_test.ts new file mode 100644 index 00000000..f1820414 --- /dev/null +++ b/src/supabase/tests/pickup_test.ts @@ -0,0 +1,28 @@ +/* eslint-disable no-console */ +// + +import { + fetchPickupData, + fetchPickupTimesByUUID, +} from '../pickup_queries'; // Replace './your-module' with the actual path to your module + +// Test fetching data +export async function testFetchPickupData() { + try { + const result = await fetchPickupData(); + console.log('Fetch Data Result:', result); + } catch (error) { + console.error('Test Fetch Data Error:', error); + } +} + +// Test fetching pickup times by UUID +export async function testFetchPickupTimesByUUID() { + const uuid = '1'; // Replace with a valid UUID + try { + const result = await fetchPickupTimesByUUID(uuid); + console.log('Fetch Pickup Times by UUID Result:', result); + } catch (error) { + console.error('Test Fetch Pickup Times by UUID Error:', error); + } +} diff --git a/src/supabase/tests/product_test.ts b/src/supabase/tests/product_test.ts new file mode 100644 index 00000000..b52634d0 --- /dev/null +++ b/src/supabase/tests/product_test.ts @@ -0,0 +1,28 @@ +/* eslint-disable no-console */ +// + +import { + fetchProducts, + fetchProductByID, +} from '../product_queries'; // Replace './your-module' with the actual path to your module + +// Test fetching all products +export async function testFetchProducts() { + try { + const result = await fetchProducts(); + console.log('Fetch Products Result:', result); + } catch (error) { + console.error('Test Fetch Products Error:', error); + } +} + +// Test fetching a product by name +export async function testFetchProductByName() { + const productId = '1'; // Replace with a valid product name + try { + const result = await fetchProductByID(productId); + console.log('Fetch Product by Name Result:', result); + } catch (error) { + console.error('Test Fetch Product by Name Error:', error); + } +} diff --git a/src/supabase/tests/user_test.ts b/src/supabase/tests/user_test.ts index 16942d8e..585850ea 100644 --- a/src/supabase/tests/user_test.ts +++ b/src/supabase/tests/user_test.ts @@ -1,8 +1,15 @@ -import {fetchData, fetchUserByUUID, addUserAddress} from '../user_queries'; +/* eslint-disable no-console */ +// -export async function testFetchData() { +import { + fetchUserData, + fetchUserByUUID, + addUserAddress +} from '../user_queries'; + +export async function testFetchUserData() { try { - const result = await fetchData(); + const result = await fetchUserData(); console.log('Fetch Data Result:', result); } catch (error) { console.error('Test Fetch Data Error:', error); @@ -33,7 +40,3 @@ export async function testAddUserAddress() { } } -// Call the test functions -testFetchData(); -testFetchUserByUUID(); -testAddUserAddress(); \ No newline at end of file diff --git a/src/supabase/user_queries.ts b/src/supabase/user_queries.ts index 2624a10a..68b7e543 100644 --- a/src/supabase/user_queries.ts +++ b/src/supabase/user_queries.ts @@ -11,12 +11,12 @@ import { User } from '../schema/schema'; // Replace these with your Supabase project URL and API key const supabaseUrl = 'https://raqpvvgsmwarxhaialcz.supabase.co' -const supabaseApiKey = process.env.SUPABASEKEY +const supabaseApiKey = process.env.SUPABASE_KEY // Initialize the Supabase client const supabase = createClient(supabaseUrl, supabaseApiKey ?? ''); -export async function fetchData(): Promise< +export async function fetchUserData(): Promise< PostgrestSingleResponse | { data: never[]; error: PostgrestError } > { try { diff --git a/tsconfig.json b/tsconfig.json index 65d0e927..b96dd5a1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -34,7 +34,7 @@ ".next/types/**/*.ts", "**/*.ts", "**/*.tsx" - ], +, "src/supabase/tests" ], "exclude": [ "node_modules" ]