Merge branch 'back-end' of https://github.com/Sosokker/B2D-Ventures into back-end

This commit is contained in:
Sosokker 2024-11-10 21:18:32 +07:00
commit 7a0fd4214f
12 changed files with 151 additions and 78 deletions

View File

@ -1,18 +1,25 @@
# Supabase Configuration
PROJECT_ID=supabase-project-id
NEXT_PUBLIC_SUPABASE_URL=supabase-project-url
NEXT_PUBLIC_SUPABASE_URL_SOURCE = supabase-project-url-without-https:// (ex: https://example.com -> example.com)
NEXT_PUBLIC_SUPABASE_URL_SOURCE=supabase-project-url-without-https (e.g., https://example.com -> example.com)
NEXT_PUBLIC_SUPABASE_ANON_KEY=supabase-anon-key
NEXT_PUBLIC_AUTH_GOOGLE_ID=google-auth-token
NEXT_PUBLIC_AUTH_GOOGLE_SECRET=google-secret-key
NEXT_PUBLIC_TEST_URL=url-to-run-testing-server
SUPABASE_SERVICE_ROLE_KEY=supabase-service-role-key
# Google Authentication Configuration
NEXT_PUBLIC_AUTH_GOOGLE_ID=google-auth-client-id
NEXT_PUBLIC_AUTH_GOOGLE_SECRET=google-auth-client-secret
# Stripe Configuration
NEXT_PUBLIC_STRIPE_PUBLIC_KEY=stripe-public-key
STRIPE_SECRET_KEY=stripe-secret-key
SUPABASE_SERVICE_ROLE_KEY=superbase-service-role-key
# Admin User Credentials
NEXT_PUBLIC_ADMIN_EMAIL=supabase-dummy-admin-email-for-testing
NEXT_PUBLIC_ADMIN_PASSWORD=supabase-dummy-admin-password-for-testing
# Testing Server URL
NEXT_PUBLIC_TEST_URL=testing-server-url
# Regular User Credentials
NEXT_PUBLIC_USER_EMAIL=supabase-dummy-user-email-for-testing
NEXT_PUBLIC_USER_PASSWORD=supabase-dummy-user-password-for-testing
# Admin User Credentials (Must exist in the real database)
NEXT_PUBLIC_ADMIN_EMAIL=admin@example.com
NEXT_PUBLIC_ADMIN_PASSWORD=admin-secure-password
# Temporary Regular User Credentials for Testing (Delete after test completion)
NEXT_PUBLIC_TEST_USER_EMAIL=test-user@example.com
NEXT_PUBLIC_TEST_USER_PASSWORD=test-user-password

View File

@ -1,18 +1,25 @@
# Supabase Configuration
PROJECT_ID=supabase-project-id
NEXT_PUBLIC_SUPABASE_URL=supabase-project-url
NEXT_PUBLIC_SUPABASE_URL_SOURCE = supabase-project-url-without-https:// (ex: https://example.com -> example.com)
NEXT_PUBLIC_SUPABASE_URL_SOURCE=supabase-project-url-without-https (e.g., https://example.com -> example.com)
NEXT_PUBLIC_SUPABASE_ANON_KEY=supabase-anon-key
NEXT_PUBLIC_AUTH_GOOGLE_ID=google-auth-token
NEXT_PUBLIC_AUTH_GOOGLE_SECRET=google-secret-key
NEXT_PUBLIC_TEST_URL=url-to-run-testing-server
SUPABASE_SERVICE_ROLE_KEY=supabase-service-role-key
# Google Authentication Configuration
NEXT_PUBLIC_AUTH_GOOGLE_ID=google-auth-client-id
NEXT_PUBLIC_AUTH_GOOGLE_SECRET=google-auth-client-secret
# Stripe Configuration
NEXT_PUBLIC_STRIPE_PUBLIC_KEY=stripe-public-key
STRIPE_SECRET_KEY=stripe-secret-key
SUPABASE_SERVICE_ROLE_KEY=superbase-service-role-key
# Admin User Credentials
NEXT_PUBLIC_ADMIN_EMAIL=supabase-dummy-admin-email-for-testing
NEXT_PUBLIC_ADMIN_PASSWORD=supabase-dummy-admin-password-for-testing
# Testing Server URL
NEXT_PUBLIC_TEST_URL=testing-server-url
# Regular User Credentials
NEXT_PUBLIC_USER_EMAIL=supabase-dummy-user-email-for-testing
NEXT_PUBLIC_USER_PASSWORD=supabase-dummy-user-password-for-testing
# Admin User Credentials (Must exist in the real database)
NEXT_PUBLIC_ADMIN_EMAIL=admin@example.com
NEXT_PUBLIC_ADMIN_PASSWORD=admin-secure-password
# Temporary Regular User Credentials for Testing (Delete after test completion)
NEXT_PUBLIC_TEST_USER_EMAIL=test-user@example.com
NEXT_PUBLIC_TEST_USER_PASSWORD=test-user-password

View File

@ -13,6 +13,7 @@ dotenv.config({ path: path.resolve(__dirname, '.env') });
*/
export default defineConfig({
globalSetup: require.resolve('./test_util/global-setup'),
globalTeardown: require.resolve('./test_util/global-teardown'),
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
@ -27,7 +28,7 @@ export default defineConfig({
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://127.0.0.1:3000',
baseURL: process.env.BASE_URL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
@ -39,19 +40,21 @@ export default defineConfig({
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
use: { ...devices['Desktop Chrome'],
},
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'],
storageState:"./storageState.json"
storageState:"./storageState.json",
},
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
use: { ...devices['Desktop Safari'] ,
},
},
/* Test against mobile viewports. */

View File

@ -36,7 +36,7 @@ export async function deleteUserByEmail(email: string): Promise<boolean> {
console.error(`UID is null`);
return false;
}
const data = await deleteUser(uid);
console.log(`Successfully delete user with email: ${email}`);
await deleteUser(uid);
console.log(`Successfully delete user with email: ${email} and UID: ${uid}`);
return true;
}

View File

@ -1,24 +1,24 @@
import { firefox, FullConfig } from '@playwright/test';
async function globalSetup(config: FullConfig) {
const email = process.env.NEXT_PUBLIC_DUMMY_EMAIL;
const password = process.env.NEXT_PUBLIC_DUMMY_PASSWORD;
const baseUrl = 'http://127.0.0.1:3000';
console.log('globalizing...');
const email = process.env.NEXT_PUBLIC_TEST_USER_EMAIL;
const password = process.env.NEXT_PUBLIC_TEST_USER_PASSWORD;
if (!email || !password) {
throw new Error('NEXT_PUBLIC_DUMMY_EMAIL and NEXT_PUBLIC_DUMMY_PASSWORD must be set');
throw new Error('NEXT_PUBLIC_TEST_USER_EMAIL and NEXT_PUBLIC_TEST_USER_PASSWORD must be set');
}
const browser = await firefox.launch();
const page = await browser.newPage();
await page.goto(baseUrl + '/auth');
console.log('signing up user...');
await page.goto(config.projects[0].use.baseURL + '/auth/signup');
await page.fill('id=email', email);
await page.fill('id=password', password);
await Promise.all([
page.waitForURL(baseUrl),
page.click('id=login')
]);
await page.context().storageState({ path: 'storageState.json' });
await page.fill('id=confirmPassword', password);
await page.click('id=signup')
await browser.close();
}

View File

@ -0,0 +1,13 @@
import { deleteUserByEmail } from './deleteUser';
async function globalTeardown() {
const email = process.env.NEXT_PUBLIC_TEST_USER_EMAIL;
if (!email) {
throw new Error('NEXT_PUBLIC_TEST_USER_EMAIL must be set');
}
console.log('deleting user...');
await deleteUserByEmail(email);
}
export default globalTeardown;

View File

@ -1,11 +1,9 @@
// dropdownUtils.ts
import { Page, Locator } from '@playwright/test';
export const selectFirstOption = async (page: Page, triggerLocator: Locator) => {
let selected = false
while (!selected) {
try {
await triggerLocator.hover();
await triggerLocator.click({ force: true });
// Select the first available option
@ -16,9 +14,7 @@ export const selectFirstOption = async (page: Page, triggerLocator: Locator) =>
const optionText = await firstOption.textContent();
console.log(`${optionText}`);
await firstOption.click();
console.log("Selected.");
selected = true;
selected = true
} catch (error) {
console.log("Retrying as the combobox disappeared.");
await page.waitForTimeout(100);

26
tests/helpers/login.ts Normal file
View File

@ -0,0 +1,26 @@
import { Page } from '@playwright/test';
export const login = async (page: Page, role: 'user' | 'admin') => {
const email = role === 'user' ? process.env.NEXT_PUBLIC_TEST_USER_EMAIL : process.env.NEXT_PUBLIC_ADMIN_EMAIL;
const password = role === 'user' ? process.env.NEXT_PUBLIC_TEST_USER_PASSWORD : process.env.NEXT_PUBLIC_ADMIN_PASSWORD;
if (!email || !password) {
throw new Error(`${role === 'user' ? 'User' : 'Admin'} credentials must be set`);
}
await page.goto('/');
const isLoginPage = await page.locator('id=login').isVisible();
if (!isLoginPage) {
console.log(`Logging out current session...`);
await page.evaluate(() => {
localStorage.clear();
sessionStorage.clear();
});
}
console.log(`Logging in as ${role}...`);
await page.goto('/auth');
await page.fill('id=email', email);
await page.fill('id=password', password);
await page.click('id=login');
};

View File

@ -0,0 +1,20 @@
import { test } from "@playwright/test";
import { login } from "./helpers/login";
import { selectFirstOption } from "./helpers/dropdownUtils";
test("test", async ({ page }) => {
await login(page, "user");
await page.getByRole('button', { name: 'Businesses' }).hover();
await page.getByRole("link", { name: "Business Apply to raise on on" }).click();
await selectFirstOption(page, page.locator("button").filter({ hasText: "Select an industry" }));
await selectFirstOption(page, page.locator("button").filter({ hasText: "Select a country" }));
await page.getByPlaceholder("$").fill("999998");
await page.getByRole("button", { name: "Yes" }).first().click();
await page.getByRole("button", { name: "Yes" }).nth(1).click();
await page.getByRole("button", { name: "Yes" }).nth(2).click();
await page.getByPlaceholder('https:// ').fill('https://www.test.md');
await selectFirstOption(page, page.locator("button").filter({ hasText: "Select" }));
await page.locator("#companyName").fill("kasetsart");
await page.getByRole('button', { name: 'Submit application' }).click();
});

View File

@ -0,0 +1,36 @@
// import { test } from '@playwright/test';
// import { selectFirstOption } from './helpers/dropdownUtils';
// import { login } from './helpers/login';
// import path from 'path';
//
// test('test', async ({ page }) => {
// await login(page,'user')
// await page.getByRole('button', { name: 'Projects' }).hover();
// await page.getByRole('link', { name: 'Projects Start your new' }).click();
//
// const projectName = page.locator('#projectName')
// await projectName.pressSequentially('DummyTester');
// await projectName.click();
//
// const img = path.join(__dirname, 'mockup', '1x1.png');
// await page.locator('#projectLogo').click();
// await page.locator('#projectLogo').setInputFiles(img);
// await page.locator('#projectPhotos').click();
// await page.locator('#projectPhotos').setInputFiles(img);
//
// const projectTypeButton = page.locator('button').filter({ hasText: 'Select a Project type' });
// await selectFirstOption(page, projectTypeButton);
//
// await page.locator('#shortDescription').fill('0123456789');
// await page.getByPlaceholder('https:// ').fill('https://www.test.md');
// await page.getByPlaceholder('$ 500').fill('499');
// await page.getByPlaceholder('$ 1,000,000').fill('99999999');
// await page.locator('#deadline').fill('2024-11-29T21:19');
//
// const tag = page.getByRole('combobox').nth(1);
// await selectFirstOption(page, tag);
//
// await projectName.pressSequentially('1234');
//
// await page.getByRole('button', { name: 'Submit application' }).click();
// });

View File

@ -1,35 +0,0 @@
import { test } from '@playwright/test';
import { selectFirstOption } from './helpers/dropdownUtils';
import path from 'path';
test('test', async ({ page }) => {
await page.goto("http://127.0.0.1:3000/");
await page.getByRole('button', { name: 'Projects' }).hover();
await page.getByRole('link', { name: 'Projects Start your new' }).click();
const projectName = page.locator('#projectName')
await projectName.pressSequentially('DummyTester');
await projectName.click();
const img = path.join(__dirname, 'mockup', '1x1.png');
await page.locator('#projectLogo').click();
await page.locator('#projectLogo').setInputFiles(img);
await page.locator('#projectPhotos').click();
await page.locator('#projectPhotos').setInputFiles(img);
const projectTypeButton = page.locator('button').filter({ hasText: 'Select a Project type' });
await selectFirstOption(page, projectTypeButton);
await page.locator('#shortDescription').fill('0123456789');
await page.getByPlaceholder('https:// ').fill('https://www.test.md');
await page.getByPlaceholder('$ 500').fill('499');
await page.getByPlaceholder('$ 1,000,000').fill('99999999');
await page.locator('#deadline').fill('2024-11-29T21:19');
const tag = page.getByRole('combobox').nth(1);
await selectFirstOption(page, tag);
await projectName.pressSequentially('1234');
await page.getByRole('button', { name: 'Submit application' }).click();
});