completely fix wrong credentials bypass, integrate login/register handlers with django views, and resolve database uniqueness constraints for E2E runs
This commit is contained in:
parent
2ba073b9b0
commit
a0299efa5f
3 changed files with 70 additions and 9 deletions
|
|
@ -6,7 +6,8 @@ describe('Supplier Portal Onboarding & Feature E2E Flow', () => {
|
||||||
|
|
||||||
// 2. Registration Page
|
// 2. Registration Page
|
||||||
cy.contains('Get Started Today').click();
|
cy.contains('Get Started Today').click();
|
||||||
cy.get('input#reg-email').type('test_seller@example.com');
|
const randUser = `test_seller_${Date.now()}@example.com`;
|
||||||
|
cy.get('input#reg-email').type(randUser);
|
||||||
cy.get('input#reg-phone').type('9876543210');
|
cy.get('input#reg-phone').type('9876543210');
|
||||||
cy.get('input#reg-pass').type('super_secure_pass_123');
|
cy.get('input#reg-pass').type('super_secure_pass_123');
|
||||||
cy.get('input#reg-confirm-pass').type('super_secure_pass_123');
|
cy.get('input#reg-confirm-pass').type('super_secure_pass_123');
|
||||||
|
|
@ -109,7 +110,8 @@ describe('Supplier Portal Onboarding & Feature E2E Flow', () => {
|
||||||
|
|
||||||
// 2. Go to Registration
|
// 2. Go to Registration
|
||||||
cy.contains('Get Started Today').click();
|
cy.contains('Get Started Today').click();
|
||||||
cy.get('input#reg-email').type('security_test@example.com');
|
const randSecurityUser = `security_test_${Date.now()}@example.com`;
|
||||||
|
cy.get('input#reg-email').type(randSecurityUser);
|
||||||
cy.get('input#reg-phone').type('9000000000');
|
cy.get('input#reg-phone').type('9000000000');
|
||||||
cy.get('input#reg-pass').type('password123');
|
cy.get('input#reg-pass').type('password123');
|
||||||
cy.get('input#reg-confirm-pass').type('password123');
|
cy.get('input#reg-confirm-pass').type('password123');
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,27 @@ import { render, screen, fireEvent } from '@testing-library/react'
|
||||||
import { describe, it, expect, vi, beforeAll } from 'vitest'
|
import { describe, it, expect, vi, beforeAll } from 'vitest'
|
||||||
import App from './App'
|
import App from './App'
|
||||||
|
|
||||||
// Mock window.scrollTo since jsdom does not implement it
|
// Mock window.scrollTo and fetch since jsdom does not implement them
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
window.scrollTo = vi.fn()
|
window.scrollTo = vi.fn()
|
||||||
|
global.fetch = vi.fn((url) => {
|
||||||
|
let responseData: any = {};
|
||||||
|
if (url.includes('/api/auth/register') || url.includes('/api/auth/login')) {
|
||||||
|
responseData = { id: 1, username: 'test_seller', email: 'test@example.com' };
|
||||||
|
} else if (url.includes('/api/products')) {
|
||||||
|
responseData = [];
|
||||||
|
} else if (url.includes('/api/orders')) {
|
||||||
|
responseData = [];
|
||||||
|
} else if (url.includes('/api/returns')) {
|
||||||
|
responseData = [];
|
||||||
|
} else if (url.includes('/api/wallet')) {
|
||||||
|
responseData = { outstanding: 850.00, withdrawn: 1250.00, transactions: [] };
|
||||||
|
}
|
||||||
|
return Promise.resolve({
|
||||||
|
ok: true,
|
||||||
|
json: () => Promise.resolve(responseData)
|
||||||
|
} as Response);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Supplier Portal Onboarding & Active Dashboard Tests', () => {
|
describe('Supplier Portal Onboarding & Active Dashboard Tests', () => {
|
||||||
|
|
@ -64,7 +82,7 @@ describe('Supplier Portal Onboarding & Active Dashboard Tests', () => {
|
||||||
fireEvent.click(registerBtn)
|
fireEvent.click(registerBtn)
|
||||||
|
|
||||||
// Step 1: Contact Verification
|
// Step 1: Contact Verification
|
||||||
expect(screen.getByText(/Step 1 of 3: Contact Verification/i)).toBeInTheDocument()
|
expect(await screen.findByText(/Step 1 of 3: Contact Verification/i)).toBeInTheDocument()
|
||||||
|
|
||||||
const sendWhatsappBtn = screen.getByText(/Send WhatsApp OTP/i)
|
const sendWhatsappBtn = screen.getByText(/Send WhatsApp OTP/i)
|
||||||
fireEvent.click(sendWhatsappBtn)
|
fireEvent.click(sendWhatsappBtn)
|
||||||
|
|
@ -151,7 +169,7 @@ describe('Supplier Portal Onboarding & Active Dashboard Tests', () => {
|
||||||
alertMock.mockRestore()
|
alertMock.mockRestore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('logs in successfully and navigates dashboard tools', () => {
|
it('logs in successfully and navigates dashboard tools', async () => {
|
||||||
render(<App />)
|
render(<App />)
|
||||||
|
|
||||||
const loginBtn = screen.getByRole('button', { name: /^Login$/i })
|
const loginBtn = screen.getByRole('button', { name: /^Login$/i })
|
||||||
|
|
@ -167,7 +185,7 @@ describe('Supplier Portal Onboarding & Active Dashboard Tests', () => {
|
||||||
fireEvent.click(submitBtn)
|
fireEvent.click(submitBtn)
|
||||||
|
|
||||||
// Check dashboard rendering
|
// Check dashboard rendering
|
||||||
expect(screen.getByText('Performance Analytics')).toBeInTheDocument()
|
expect(await screen.findByText('Performance Analytics')).toBeInTheDocument()
|
||||||
|
|
||||||
// Check Sidebar Tab click: Manage Products
|
// Check Sidebar Tab click: Manage Products
|
||||||
const productsTabBtn = screen.getByText(/Manage Products/i)
|
const productsTabBtn = screen.getByText(/Manage Products/i)
|
||||||
|
|
|
||||||
47
src/App.tsx
47
src/App.tsx
|
|
@ -269,7 +269,34 @@ export default function App() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
navigateTo('profile-completion')
|
fetch(`${CONFIG.apiBaseUrl}/api/auth/register/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
username: email,
|
||||||
|
email: email,
|
||||||
|
phone: phone,
|
||||||
|
password: password
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (!res.ok) throw new Error('Registration failed. Username/email might already be taken.');
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// Auto login after signup
|
||||||
|
fetch(`${CONFIG.apiBaseUrl}/api/auth/login/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ username: email, password: password })
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
navigateTo('profile-completion')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
alert(err.message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleLoginSubmit = (e: React.FormEvent) => {
|
const handleLoginSubmit = (e: React.FormEvent) => {
|
||||||
|
|
@ -282,8 +309,22 @@ export default function App() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsProfileComplete(true)
|
fetch(`${CONFIG.apiBaseUrl}/api/auth/login/`, {
|
||||||
navigateTo('dashboard', true)
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ username: email, password: password })
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (!res.ok) throw new Error('Invalid credentials.');
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
setIsProfileComplete(true)
|
||||||
|
navigateTo('dashboard', true)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
alert(err.message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleProfileSubmit = (e: React.FormEvent) => {
|
const handleProfileSubmit = (e: React.FormEvent) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue