Skip to content

Commit

Permalink
feat/Queries_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Cai authored and Kevin Cai committed Oct 11, 2023
1 parent 5ac7dc1 commit 0c2e2a5
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 18 deletions.
19 changes: 16 additions & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<main>
<Link href="/login">Login</Link>
Expand Down
1 change: 0 additions & 1 deletion src/supabase/order_queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-console */
//

Expand Down
2 changes: 1 addition & 1 deletion src/supabase/pickup_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Schedule[]> | { data: never[]; error: PostgrestError }
> {
try {
Expand Down
6 changes: 3 additions & 3 deletions src/supabase/product_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ export async function fetchProducts(): Promise<
}
}

export async function fetchProductByName(
productName: string,
export async function fetchProductByID(
productId: string,
): Promise<PostgrestSingleResponse<Product>> {
try {
const { data: product, error } = await supabase
.from('Product')
.select('*')
.eq('name', productName)
.eq('product_id', productId)
.single();

if (error) {
Expand Down
75 changes: 75 additions & 0 deletions src/supabase/tests/order_test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
28 changes: 28 additions & 0 deletions src/supabase/tests/pickup_test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
28 changes: 28 additions & 0 deletions src/supabase/tests/product_test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 10 additions & 7 deletions src/supabase/tests/user_test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -33,7 +40,3 @@ export async function testAddUserAddress() {
}
}

// Call the test functions
testFetchData();
testFetchUserByUUID();
testAddUserAddress();
4 changes: 2 additions & 2 deletions src/supabase/user_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<User[]> | { data: never[]; error: PostgrestError }
> {
try {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
, "src/supabase/tests" ],
"exclude": [
"node_modules"
]
Expand Down

0 comments on commit 0c2e2a5

Please sign in to comment.