diff --git a/e2e/assets/test-package.zip b/e2e/assets/test-package.zip new file mode 100644 index 0000000..3553e6c Binary files /dev/null and b/e2e/assets/test-package.zip differ diff --git a/e2e/packageIO.spec.ts b/e2e/packageIO.spec.ts index e69de29..4293c5f 100644 --- a/e2e/packageIO.spec.ts +++ b/e2e/packageIO.spec.ts @@ -0,0 +1,69 @@ +import { test, expect } from '@playwright/test'; +import * as path from 'path'; + +test.describe('Package Upload and Download E2E Tests', () => { + const testPackageName = 'test-package'; + const testPackageVersion = '1.0.0'; + const testFileName = 'test-package.zip'; + const testFilePath = `e2e/assets/${testFileName}`; + const downloadDir = `e2e/downloads`; + +// test('upload a package', async ({ page }) => { +// await page.goto('http://localhost:4000'); + +// // Login +// await page.fill('input[name="username"]', 'ece30861defaultadminuser'); +// await page.fill( +// 'input[name="password"]', +// "correcthorsebatterystaple123(!__+@**(A'\"`;DROP TABLE packages;" +// ); +// await page.click('button:has-text("Login")'); +// await expect(page.getByText('Welcome, ece30861defaultadminuser!')).toBeVisible(); + +// // Navigate to the Upload Page +// await page.getByRole('link', { name: 'Upload' }).click(); + +// page.on('dialog', async (dialog) => { +// expect(dialog.message()).toBe('Package uploaded successfully!'); // Assert the alert message +// await dialog.accept(); // Accept the alert to close it +// }); +// // Fill out the upload form +// await page.getByLabel('Package Name:').fill(testPackageName); +// await page.getByLabel('Upload ZIP File:').setInputFiles(testFilePath); +// await page.getByRole('button', { name: 'Upload Package' }).click(); +// }); + + test('download a package', async ({ page, context }) => { + await page.goto('http://localhost:4000'); // Replace with your app URL + + // Login + await page.fill('input[name="username"]', 'ece30861defaultadminuser'); + await page.fill( + 'input[name="password"]', + "correcthorsebatterystaple123(!__+@**(A'\"`;DROP TABLE packages;" + ); + await page.click('button:has-text("Login")'); + await expect(page.getByText('Welcome, ece30861defaultadminuser!')).toBeVisible(); + + // Navigate to the Download Page + await page.getByRole('link', { name: 'Download' }).click(); + // Search for the package + await page.getByLabel('Search by Name or Regex:').fill(testPackageName); + await page.getByRole('button', { name: 'Search' }).click(); + await expect(page.getByText(`${testPackageName} (v${testPackageVersion})`)).toBeVisible(); + + // Start downloading the package + const [download] = await Promise.all([ + context.waitForEvent('download'), + page.click('button:has-text("Download")'), + ]); + + // Save the downloaded file + const downloadPath = path.join(downloadDir, testFileName); + await download.saveAs(downloadPath); + + // Verify the file exists + const fs = require('fs'); + expect(fs.existsSync(downloadPath)).toBeTruthy(); + }); +}); diff --git a/frontend/src/pages/download.tsx b/frontend/src/pages/download.tsx index e4fba9f..64c818e 100644 --- a/frontend/src/pages/download.tsx +++ b/frontend/src/pages/download.tsx @@ -62,7 +62,7 @@ const DownloadPage: React.FC = () => { setSearchPerformed(true); } else if (response.status === 404) { setPackages([]); - alert('No packages found with the given regex.'); + setError('No packages found with the given regex.'); } else { setError('Search failed with an unknown error.'); } diff --git a/frontend/src/pages/history.tsx b/frontend/src/pages/history.tsx index 5f1eb5f..24c4383 100644 --- a/frontend/src/pages/history.tsx +++ b/frontend/src/pages/history.tsx @@ -118,12 +118,14 @@ const HistoryPage: React.FC = () => { method: 'GET', headers: { 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache', // Prevent caching so we dont get 304 but 200 'X-Authorization': authToken, }, }); if (response.ok) { const data: HistoryEntry[] = await response.json(); + // console.log('Fetched history:', data); // delete this setHistory(data); } else { alert('Failed to fetch history. Please try again.'); diff --git a/frontend/src/pages/manageUsers.tsx b/frontend/src/pages/manageUsers.tsx index 17e9704..d1baff4 100644 --- a/frontend/src/pages/manageUsers.tsx +++ b/frontend/src/pages/manageUsers.tsx @@ -246,8 +246,11 @@ const ManageUsers: React.FC = () => {