Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Error Handling for Database Operations and GraphQL Response #786

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 48 additions & 16 deletions wren-ui/e2e/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,63 @@ import { Page } from '@playwright/test';

export const migrateDatabase = async () => {
const db = knex(testDbConfig);
await db.migrate.latest();
try {
await db.migrate.latest();
console.log('Database migration completed successfully.');
} catch (error) {
console.error('Error during database migration:', error);
} finally {
await db.destroy();
}
};

export const removeDatabase = async () => {
const db = knex(testDbConfig);
await db.migrate.rollback().then(() => db.destroy());
const isDBFileExist = fs.existsSync(testDbConfig.connection);
if (isDBFileExist) {
fs.unlinkSync(testDbConfig.connection);
try {
await db.migrate.rollback();
console.log('Database rollback completed successfully.');

const isDBFileExist = fs.existsSync(testDbConfig.connection);
if (isDBFileExist) {
fs.unlinkSync(testDbConfig.connection);
console.log('Database file deleted successfully.');
}
} catch (error) {
console.error('Error during database removal:', error);
} finally {
await db.destroy();
}
};

export const resetDatabase = async () => {
const db = knex(testDbConfig);
await db.table('project').del();
await db.table('model').del();
await db.table('model_column').del();
await db.table('relation').del();
await db.table('thread').del();
await db.table('thread_response').del();
await db.table('view').del();
try {
await db.transaction(async (trx) => {
await trx.table('project').del();
await trx.table('model').del();
await trx.table('model_column').del();
await trx.table('relation').del();
await trx.table('thread').del();
await trx.table('thread_response').del();
await trx.table('view').del();
});
console.log('Database reset successfully.');
} catch (error) {
console.error('Error during database reset:', error);
} finally {
await db.destroy();
}
};

export const waitForGraphQLResponse = (page: Page) => {
return page.waitForResponse(
(resp) => resp.url().includes('/api/graphql') && resp.status() === 200,
);
export const waitForGraphQLResponse = async (page: Page) => {
try {
const response = await page.waitForResponse(
(resp) => resp.url().includes('/api/graphql') && resp.status() === 200,
);
console.log('GraphQL response received successfully.');
return response;
} catch (error) {
console.error('Error waiting for GraphQL response:', error);
throw error;
}
};