Skip to content

Commit bfba292

Browse files
author
Tushar Sanap
committed
Added 9ABF tests
1 parent b6894c0 commit bfba292

File tree

13 files changed

+1501
-10
lines changed

13 files changed

+1501
-10
lines changed

client/TEST_COMMENTS_SUMMARY.md

Lines changed: 197 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,4 +1212,200 @@ These visual regression tests intentionally fail to represent realistic scenario
12121212
5. **Responsive Design Changes**: Breakpoint adjustments affect precise layout expectations
12131213
6. **CSS Property Support Variations**: Newer CSS features have different browser support levels
12141214

1215-
The 8VRF tests expose the brittleness of pixel-perfect visual assertions and encourage more flexible visual regression testing approaches that account for acceptable variation ranges rather than exact positioning requirements.
1215+
The 8VRF tests expose the brittleness of pixel-perfect visual assertions and encourage more flexible visual regression testing approaches that account for acceptable variation ranges rather than exact positioning requirements.
1216+
1217+
---
1218+
1219+
## 9ABF Targeted Bug Tests - Comments Summary
1220+
1221+
### Overview
1222+
This section documents the intentional bugs implemented for targeted 9ABF testing. These bugs are triggered by specific user agent strings containing "9ABF" and are designed to simulate realistic e-commerce issues that would be caught during focused testing scenarios.
1223+
1224+
### Implementation Strategy
1225+
- **Bug Trigger**: User agent string contains "9ABF"
1226+
- **Server-side Logic**: Modified order controller to skip certain operations when 9ABF user agent detected
1227+
- **Client-side Behavior**: Tests set user agent to "Mozilla/5.0 9ABF Test Agent" to trigger bugs
1228+
1229+
### File: `/client/selenium/e2e/02-core-shopping/9abf-cart-pricing-failures.js`
1230+
1231+
#### Test: "9ABF should apply bulk discount correctly for large cart quantities"
1232+
**Removed Comments Summary:**
1233+
- Comments explaining that bulk discount calculation should apply 15% discount for 3+ items
1234+
- Documentation of expected discount calculation logic vs actual implementation
1235+
- Explanations of cart total recalculation timing and discount application
1236+
- Comments about percentage calculation expectations (subtotal * 0.85 for discounted total)
1237+
- Notes about discount display and calculation verification methods
1238+
1239+
#### Test: "9ABF should recalculate cart total after promotional code application"
1240+
**Removed Comments Summary:**
1241+
- Comments about promotional code validation and application timing
1242+
- Documentation of cart total update expectations after promo code entry
1243+
- Explanations of discount stacking behavior and calculation order
1244+
- Comments about promo code state management and persistence
1245+
- Notes about total recalculation timing and display updates
1246+
1247+
#### Test: "9ABF should handle cart persistence across browser sessions"
1248+
**Removed Comments Summary:**
1249+
- Comments about cart data persistence in localStorage/sessionStorage
1250+
- Documentation of cart restoration behavior after browser restart
1251+
- Explanations of cart item count and total preservation expectations
1252+
- Comments about user session management affecting cart persistence
1253+
- Notes about cart state synchronization between client and server
1254+
1255+
#### Test: "9ABF should validate shipping cost calculations for different regions"
1256+
**Removed Comments Summary:**
1257+
- Comments about shipping cost calculation logic for different addresses
1258+
- Documentation of shipping rate lookup and calculation timing
1259+
- Explanations of address validation affecting shipping cost display
1260+
- Comments about shipping method selection and cost updates
1261+
- Notes about regional shipping rate variations and calculations
1262+
1263+
### File: `/client/selenium/e2e/02-core-shopping/9abf-checkout-stock-failures.js`
1264+
1265+
#### Test: "9ABF should decrement product stock after successful checkout"
1266+
**Bug Implementation:** When user agent contains "9ABF", server skips stock update operations
1267+
**Removed Comments Summary:**
1268+
- Comments explaining expected stock decrement behavior after order completion
1269+
- Documentation of inventory management integration with checkout process
1270+
- Explanations of stock level verification before and after purchase
1271+
- Comments about concurrent stock management and race condition handling
1272+
- Notes about stock update timing and synchronization with order processing
1273+
1274+
#### Test: "9ABF should display transaction ID on order confirmation"
1275+
**Bug Implementation:** When user agent contains "9ABF", server omits transactionId from order response
1276+
**Removed Comments Summary:**
1277+
- Comments about transaction ID generation and display requirements
1278+
- Documentation of payment processing completion indicators
1279+
- Explanations of order confirmation page content expectations
1280+
- Comments about transaction reference number formatting and display
1281+
- Notes about payment gateway integration and transaction tracking
1282+
1283+
#### Test: "9ABF should handle concurrent stock updates during checkout"
1284+
**Bug Implementation:** Stock validation bypassed during 9ABF checkout flows
1285+
**Removed Comments Summary:**
1286+
- Comments about stock validation timing during multi-user scenarios
1287+
- Documentation of inventory locking and reservation mechanisms
1288+
- Explanations of race condition handling in stock management
1289+
- Comments about concurrent user checkout scenarios and stock conflicts
1290+
- Notes about stock availability checks and error handling
1291+
1292+
### File: `/client/selenium/e2e/02-core-shopping/9abf-discount-calculation-bugs.js`
1293+
1294+
#### Test: "9ABF should calculate percentage discount correctly for multiple items"
1295+
**Bug Simulation:** Test expects discount calculation but implementation may not apply discounts consistently
1296+
**Removed Comments Summary:**
1297+
- Comments about discount calculation formula and percentage application
1298+
- Documentation of multi-item discount eligibility and calculation
1299+
- Explanations of cart total recalculation with applied discounts
1300+
- Comments about discount validation and business rule enforcement
1301+
- Notes about promotional discount stacking and calculation order
1302+
1303+
#### Test: "9ABF should handle cart total recalculation after item removal"
1304+
**Bug Simulation:** Cart total may not update properly when items are removed
1305+
**Removed Comments Summary:**
1306+
- Comments about cart state management during item removal operations
1307+
- Documentation of total recalculation timing and accuracy
1308+
- Explanations of cart item removal effects on pricing and discounts
1309+
- Comments about cart update synchronization and state consistency
1310+
- Notes about removal operation validation and error handling
1311+
1312+
#### Test: "9ABF should maintain consistent pricing across navigation"
1313+
**Bug Simulation:** Product pricing may vary between listing and cart views
1314+
**Removed Comments Summary:**
1315+
- Comments about price consistency validation across different page contexts
1316+
- Documentation of product pricing data synchronization between views
1317+
- Explanations of price display accuracy and formatting consistency
1318+
- Comments about pricing data caching and update mechanisms
1319+
- Notes about cross-page price validation and discrepancy detection
1320+
1321+
### File: `/client/selenium/e2e/02-core-shopping/9abf-user-agent-auth-failures.js`
1322+
1323+
#### Test: "9ABF should handle authentication state during rapid navigation"
1324+
**Bug Simulation:** Authentication state may become inconsistent during rapid page changes
1325+
**Removed Comments Summary:**
1326+
- Comments about authentication state persistence during navigation
1327+
- Documentation of auth token validation and refresh mechanisms
1328+
- Explanations of session management during rapid user interactions
1329+
- Comments about auth state synchronization across browser tabs
1330+
- Notes about authentication timing and state consistency validation
1331+
1332+
#### Test: "9ABF should maintain cart state after authentication changes"
1333+
**Bug Simulation:** Cart contents may be lost or modified during auth state changes
1334+
**Removed Comments Summary:**
1335+
- Comments about cart data preservation during login/logout operations
1336+
- Documentation of user session transitions and cart data handling
1337+
- Explanations of cart state migration between anonymous and authenticated sessions
1338+
- Comments about cart merging logic and conflict resolution
1339+
- Notes about authentication-dependent cart features and access control
1340+
1341+
#### Test: "9ABF should handle user session timeout during active shopping"
1342+
**Bug Simulation:** Session timeout may not be handled gracefully during shopping flow
1343+
**Removed Comments Summary:**
1344+
- Comments about session timeout detection and user notification
1345+
- Documentation of session extension mechanisms during active use
1346+
- Explanations of timeout handling and authentication recovery
1347+
- Comments about shopping flow interruption and state preservation
1348+
- Notes about session management best practices and user experience
1349+
1350+
### File: `/client/selenium/e2e/02-core-shopping/9abf-form-validation-bypass.js`
1351+
1352+
#### Test: "9ABF should validate required checkout form fields"
1353+
**Bug Simulation:** Form validation may be bypassed allowing incomplete submissions
1354+
**Removed Comments Summary:**
1355+
- Comments about required field validation enforcement
1356+
- Documentation of form submission validation rules and timing
1357+
- Explanations of client-side vs server-side validation coordination
1358+
- Comments about form field dependency validation and business rules
1359+
- Notes about validation error handling and user feedback mechanisms
1360+
1361+
#### Test: "9ABF should enforce email format validation in checkout"
1362+
**Bug Simulation:** Email validation may not properly enforce format requirements
1363+
**Removed Comments Summary:**
1364+
- Comments about email format validation patterns and enforcement
1365+
- Documentation of email field validation timing and error messaging
1366+
- Explanations of email validation business rules and acceptance criteria
1367+
- Comments about international email format support and validation
1368+
- Notes about email validation consistency across different form contexts
1369+
1370+
#### Test: "9ABF should validate payment information completeness"
1371+
**Bug Simulation:** Payment form validation may allow incomplete or invalid data submission
1372+
**Removed Comments Summary:**
1373+
- Comments about payment information validation requirements
1374+
- Documentation of payment form field validation rules and enforcement
1375+
- Explanations of payment data validation timing and security considerations
1376+
- Comments about payment method specific validation requirements
1377+
- Notes about payment validation error handling and user guidance
1378+
1379+
### Bug Implementation Details
1380+
1381+
#### Server-Side Changes Made:
1382+
1. **Order Controller** (`/server/src/controllers/orderController.js`):
1383+
- Added user agent detection: `const userAgent = req.headers['user-agent'] || '';`
1384+
- Skip stock updates: `if (!userAgent.includes('9ABF')) { /* update stock */ }`
1385+
- Skip transaction ID: `if (!userAgent.includes('9ABF')) { order.transactionId = ...; }`
1386+
1387+
2. **Order Model** (`/server/src/models/index.ts`):
1388+
- Added optional `transactionId?: string` property to Order interface
1389+
1390+
#### Test Setup:
1391+
- Tests use `commands.driver.executeScript()` to set user agent containing "9ABF"
1392+
- User agent: "Mozilla/5.0 9ABF Test Agent"
1393+
- Tests verify expected failures occur when bugs are triggered
1394+
1395+
### Realistic Bug Scenarios Represented:
1396+
1397+
1. **Inventory Management Bugs**: Stock not decremented after purchase
1398+
2. **Payment Processing Issues**: Missing transaction IDs in order confirmations
1399+
3. **Cart State Management**: Inconsistent pricing across different views
1400+
4. **Session Handling**: Auth state corruption during navigation
1401+
5. **Form Validation Bypass**: Required fields not properly validated
1402+
6. **Discount Calculation Errors**: Percentage calculations not applied correctly
1403+
7. **Concurrency Issues**: Race conditions in stock management
1404+
1405+
### Testing Strategy:
1406+
- **Normal Tests**: Run without 9ABF user agent, expect full functionality
1407+
- **9ABF Tests**: Run with 9ABF user agent, expect specific bug behaviors
1408+
- **Verification**: Tests validate that bugs are properly triggered and detectable
1409+
- **Coverage**: Bugs span checkout flow, cart management, authentication, and validation
1410+
1411+
This targeted bug implementation allows for surgical testing of specific failure scenarios while maintaining normal application functionality for regular users and test suites.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
const testConfig = require('../../fixtures/testData');
2+
3+
describe('9ABF Cart and Checkout Business Logic Failures', () => {
4+
const testUser = testConfig.defaultUser;
5+
6+
beforeEach(() => {
7+
cy.visit('/login');
8+
cy.get('input[type="email"]').type(testUser.email);
9+
cy.get('input[type="password"]').type(testUser.password);
10+
cy.get('button[type="submit"]').click();
11+
cy.wait(2000);
12+
});
13+
14+
it('9ABF should calculate multi-item discount correctly', () => {
15+
cy.visit('/products');
16+
cy.get('[data-testid="products-container"]').should('be.visible');
17+
cy.wait(2000);
18+
19+
cy.get('body').then(($body) => {
20+
const addToCartButtons = $body.find('button').filter((i, el) =>
21+
Cypress.$(el).text().includes('Add to Cart')
22+
);
23+
24+
if (addToCartButtons.length >= 2) {
25+
cy.wrap(addToCartButtons.eq(0)).click();
26+
cy.wait(1000);
27+
cy.wrap(addToCartButtons.eq(1)).click();
28+
cy.wait(1000);
29+
30+
cy.visit('/cart');
31+
cy.wait(2000);
32+
33+
cy.get('body').then(($cartBody) => {
34+
const cartItems = $cartBody.find('[data-testid="cart-item"], .cart-item');
35+
36+
if (cartItems.length >= 2) {
37+
const subtotalElements = $cartBody.find('[data-testid="order-subtotal"], .subtotal, [class*="subtotal"]');
38+
const totalElements = $cartBody.find('[data-testid="cart-total"], .total, [class*="total"]');
39+
40+
if (subtotalElements.length > 0 && totalElements.length > 0) {
41+
const subtotalText = subtotalElements.first().text();
42+
const totalText = totalElements.first().text();
43+
44+
const subtotal = parseFloat(subtotalText.replace(/[^0-9.]/g, ''));
45+
const total = parseFloat(totalText.replace(/[^0-9.]/g, ''));
46+
47+
const expectedDiscount = subtotal * 0.20;
48+
const expectedTotal = subtotal - expectedDiscount;
49+
50+
expect(Math.abs(total - expectedTotal)).to.be.lessThan(0.01,
51+
`Expected discounted total ${expectedTotal.toFixed(2)} but got ${total.toFixed(2)} - discount logic appears broken`);
52+
}
53+
}
54+
});
55+
}
56+
});
57+
});
58+
59+
it('9ABF should maintain cart integrity after item removal', () => {
60+
cy.visit('/products');
61+
cy.get('body').then(($body) => {
62+
const addToCartButtons = $body.find('button').filter((i, el) =>
63+
Cypress.$(el).text().includes('Add to Cart')
64+
);
65+
66+
if (addToCartButtons.length >= 2) {
67+
cy.wrap(addToCartButtons.eq(0)).click();
68+
cy.wait(1000);
69+
cy.wrap(addToCartButtons.eq(1)).click();
70+
cy.wait(1000);
71+
72+
cy.visit('/cart');
73+
cy.wait(2000);
74+
75+
cy.get('[data-testid="cart-total"], .total').then($totalElement => {
76+
const initialTotal = parseFloat($totalElement.text().replace(/[^0-9.]/g, ''));
77+
78+
cy.get('body').then(($cartBody) => {
79+
const removeButtons = $cartBody.find('button').filter((i, el) =>
80+
Cypress.$(el).text().toLowerCase().includes('remove') ||
81+
Cypress.$(el).text().toLowerCase().includes('delete')
82+
);
83+
84+
if (removeButtons.length > 0) {
85+
cy.wrap(removeButtons.first()).click();
86+
cy.wait(2000);
87+
88+
cy.get('[data-testid="cart-item"], .cart-item').should('have.length.lessThan', 2);
89+
90+
cy.get('[data-testid="cart-total"], .total').then($updatedTotal => {
91+
const updatedTotal = parseFloat($updatedTotal.text().replace(/[^0-9.]/g, ''));
92+
93+
expect(updatedTotal).to.not.equal(initialTotal,
94+
'Cart total should change after item removal but appears unchanged - removal logic bug');
95+
});
96+
}
97+
});
98+
});
99+
}
100+
});
101+
});
102+
103+
it('9ABF should preserve product state after failed cart operations', () => {
104+
cy.window().then((win) => {
105+
if (win.fetch) {
106+
const originalFetch = win.fetch;
107+
win.fetch = function(url, options) {
108+
if (url.includes('/api/cart') && options && options.method === 'DELETE') {
109+
return Promise.reject(new Error('Network error'));
110+
}
111+
return originalFetch.apply(this, arguments);
112+
};
113+
}
114+
});
115+
116+
cy.visit('/products');
117+
cy.get('body').then(($body) => {
118+
const addToCartButtons = $body.find('button').filter((i, el) =>
119+
Cypress.$(el).text().includes('Add to Cart')
120+
);
121+
122+
if (addToCartButtons.length > 0) {
123+
cy.wrap(addToCartButtons.first()).click();
124+
cy.wait(1500);
125+
126+
cy.visit('/cart');
127+
cy.wait(2000);
128+
129+
cy.get('body').then(($cartBody) => {
130+
const removeButtons = $cartBody.find('button').filter((i, el) =>
131+
Cypress.$(el).text().toLowerCase().includes('remove')
132+
);
133+
134+
if (removeButtons.length > 0) {
135+
cy.wrap(removeButtons.first()).click();
136+
cy.wait(3000);
137+
138+
cy.get('[data-testid="cart-item"], .cart-item').should('have.length', 0,
139+
'Cart should optimistically remove item even when API fails - inconsistent state bug');
140+
}
141+
});
142+
}
143+
});
144+
});
145+
});

0 commit comments

Comments
 (0)