Skip to content

Commit 5c18b9c

Browse files
committed
style: run prettier to fix formatting issues for CI
1 parent dff481a commit 5c18b9c

15 files changed

Lines changed: 156 additions & 119 deletions

File tree

backend/eslint.config.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import globals from "globals";
2-
import pluginJs from "@eslint/js";
1+
import globals from 'globals';
2+
import pluginJs from '@eslint/js';
33

44
export default [
5-
{languageOptions: { globals: globals.node }},
5+
{ languageOptions: { globals: globals.node } },
66
pluginJs.configs.recommended,
77
{
88
rules: {
9-
"no-unused-vars": "warn",
10-
"no-console": "off",
11-
}
12-
}
9+
'no-unused-vars': 'warn',
10+
'no-console': 'off',
11+
},
12+
},
1313
];

backend/src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ app.post('/api/checkout', (req, res) => {
3333
total += product.price * item.quantity;
3434
}
3535
}
36-
36+
3737
// Simulate order success
3838
res.json({ message: 'Checkout successful', total, orderId: Date.now() });
3939
} catch (err) {

backend/src/db.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const Database = require('better-sqlite3');
22
const path = require('path');
33

4-
const dbPath = process.env.NODE_ENV === 'test'
5-
? ':memory:'
6-
: path.resolve(__dirname, 'database.sqlite');
7-
4+
const dbPath =
5+
process.env.NODE_ENV === 'test' ? ':memory:' : path.resolve(__dirname, 'database.sqlite');
6+
87
const db = new Database(dbPath);
98

109
// Initialize table
@@ -21,11 +20,33 @@ db.exec(`
2120
// Seed data if empty
2221
const count = db.prepare('SELECT COUNT(*) as count FROM products').get().count;
2322
if (count === 0) {
24-
const insert = db.prepare('INSERT INTO products (name, description, price, image_url) VALUES (?, ?, ?, ?)');
25-
insert.run('Premium Wireless Headphones', 'High quality noise-canceling headphones with 30-hour battery life.', 299.99, 'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=400&q=80');
26-
insert.run('Mechanic Gaming Keyboard', 'RGB backlit mechanical keyboard with tactile switches.', 129.99, 'https://images.unsplash.com/photo-1595225476474-87563907a212?auto=format&fit=crop&w=400&q=80');
27-
insert.run('Ultra-Wide Monitor', '34-inch curved ultra-wide gaming monitor for immersive experience.', 499.99, 'https://images.unsplash.com/photo-1527443154391-507e9dc6c5cc?auto=format&fit=crop&w=400&q=80');
28-
insert.run('Ergonomic Mouse', 'Wireless ergonomic mouse designed to reduce wrist strain.', 59.99, 'https://images.unsplash.com/photo-1527864550417-7fd91fc51a46?auto=format&fit=crop&w=400&q=80');
23+
const insert = db.prepare(
24+
'INSERT INTO products (name, description, price, image_url) VALUES (?, ?, ?, ?)'
25+
);
26+
insert.run(
27+
'Premium Wireless Headphones',
28+
'High quality noise-canceling headphones with 30-hour battery life.',
29+
299.99,
30+
'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=400&q=80'
31+
);
32+
insert.run(
33+
'Mechanic Gaming Keyboard',
34+
'RGB backlit mechanical keyboard with tactile switches.',
35+
129.99,
36+
'https://images.unsplash.com/photo-1595225476474-87563907a212?auto=format&fit=crop&w=400&q=80'
37+
);
38+
insert.run(
39+
'Ultra-Wide Monitor',
40+
'34-inch curved ultra-wide gaming monitor for immersive experience.',
41+
499.99,
42+
'https://images.unsplash.com/photo-1527443154391-507e9dc6c5cc?auto=format&fit=crop&w=400&q=80'
43+
);
44+
insert.run(
45+
'Ergonomic Mouse',
46+
'Wireless ergonomic mouse designed to reduce wrist strain.',
47+
59.99,
48+
'https://images.unsplash.com/photo-1527864550417-7fd91fc51a46?auto=format&fit=crop&w=400&q=80'
49+
);
2950
}
3051

3152
module.exports = db;

backend/tests/api.test.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,29 @@ describe('API Tests', () => {
8080
{ productId: products[1].id, quantity: 2 },
8181
];
8282

83-
const res = await request(app)
84-
.post('/api/checkout')
85-
.send({ items: cartItems });
83+
const res = await request(app).post('/api/checkout').send({ items: cartItems });
8684

87-
const expectedTotal =
88-
products[0].price * 1 + products[1].price * 2;
85+
const expectedTotal = products[0].price * 1 + products[1].price * 2;
8986
expect(res.statusCode).toBe(200);
9087
expect(res.body.total).toBeCloseTo(expectedTotal, 2);
9188
});
9289

9390
test('returns 400 with empty items array', async () => {
94-
const res = await request(app)
95-
.post('/api/checkout')
96-
.send({ items: [] });
91+
const res = await request(app).post('/api/checkout').send({ items: [] });
9792

9893
expect(res.statusCode).toBe(400);
9994
expect(res.body).toHaveProperty('error');
10095
});
10196

10297
test('returns 400 with missing items field', async () => {
103-
const res = await request(app)
104-
.post('/api/checkout')
105-
.send({});
98+
const res = await request(app).post('/api/checkout').send({});
10699

107100
expect(res.statusCode).toBe(400);
108101
expect(res.body).toHaveProperty('error', 'Invalid cart contents');
109102
});
110103

111104
test('returns 400 when items is not an array', async () => {
112-
const res = await request(app)
113-
.post('/api/checkout')
114-
.send({ items: 'not-an-array' });
105+
const res = await request(app).post('/api/checkout').send({ items: 'not-an-array' });
115106

116107
expect(res.statusCode).toBe(400);
117108
});

backend/tests/db.test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ describe('Database Module', () => {
2222

2323
test('products table exists', () => {
2424
const tables = db
25-
.prepare(
26-
"SELECT name FROM sqlite_master WHERE type='table' AND name='products'"
27-
)
25+
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='products'")
2826
.all();
2927
expect(tables).toHaveLength(1);
3028
expect(tables[0].name).toBe('products');
@@ -42,9 +40,7 @@ describe('Database Module', () => {
4240
});
4341

4442
test('products table is seeded with data', () => {
45-
const count = db
46-
.prepare('SELECT COUNT(*) as count FROM products')
47-
.get().count;
43+
const count = db.prepare('SELECT COUNT(*) as count FROM products').get().count;
4844
expect(count).toBeGreaterThan(0);
4945
});
5046

@@ -71,9 +67,7 @@ describe('Database Module', () => {
7167
expect(result.changes).toBe(1);
7268
const newId = result.lastInsertRowid;
7369

74-
const product = db
75-
.prepare('SELECT * FROM products WHERE id = ?')
76-
.get(newId);
70+
const product = db.prepare('SELECT * FROM products WHERE id = ?').get(newId);
7771
expect(product.name).toBe('Test Product');
7872
expect(product.price).toBe(9.99);
7973

frontend/babel.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
presets: [
33
['@babel/preset-env', { targets: { node: 'current' } }],
4-
['@babel/preset-react', { runtime: 'automatic' }]
4+
['@babel/preset-react', { runtime: 'automatic' }],
55
],
66
};

frontend/eslint.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import js from '@eslint/js'
2-
import globals from 'globals'
3-
import reactHooks from 'eslint-plugin-react-hooks'
4-
import reactRefresh from 'eslint-plugin-react-refresh'
5-
import { defineConfig, globalIgnores } from 'eslint/config'
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
import reactHooks from 'eslint-plugin-react-hooks';
4+
import reactRefresh from 'eslint-plugin-react-refresh';
5+
import { defineConfig, globalIgnores } from 'eslint/config';
66

77
export default defineConfig([
88
globalIgnores(['dist']),
@@ -26,4 +26,4 @@ export default defineConfig([
2626
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
2727
},
2828
},
29-
])
29+
]);

frontend/jest.config.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module.exports = {
33
setupFilesAfterEnv: ['<rootDir>/src/setupTests.js'],
44
moduleNameMapper: {
55
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
6-
'\\.(gif|ttf|eot|svg|png)$': '<rootDir>/src/__mocks__/fileMock.js'
6+
'\\.(gif|ttf|eot|svg|png)$': '<rootDir>/src/__mocks__/fileMock.js',
77
},
88
transform: {
9-
'^.+\\.[t|j]sx?$': 'babel-jest'
10-
}
9+
'^.+\\.[t|j]sx?$': 'babel-jest',
10+
},
1111
};

frontend/src/App.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@
4242
z-index: 1;
4343
top: 34px;
4444
height: 28px;
45-
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
46-
scale(1.4);
45+
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg) scale(1.4);
4746
}
4847

4948
.vite {
5049
z-index: 0;
5150
top: 107px;
5251
height: 26px;
5352
width: auto;
54-
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
55-
scale(0.8);
53+
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg) scale(0.8);
5654
}
5755
}
5856

frontend/src/App.jsx

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,28 @@ export default function App() {
2424
};
2525

2626
const handleAddToCart = (product) => {
27-
const existing = cartItems.find(item => item.id === product.id);
27+
const existing = cartItems.find((item) => item.id === product.id);
2828
if (existing) {
2929
toast.success(`Increased ${product.name} quantity!`);
30-
setCartItems(cartItems.map(item => item.id === product.id ? { ...item, quantity: item.quantity + 1 } : item));
30+
setCartItems(
31+
cartItems.map((item) =>
32+
item.id === product.id ? { ...item, quantity: item.quantity + 1 } : item
33+
)
34+
);
3135
} else {
3236
toast.success(`${product.name} added to cart!`);
3337
setCartItems([...cartItems, { ...product, quantity: 1 }]);
3438
}
3539
};
3640

3741
const handleRemoveFromCart = (productId) => {
38-
setCartItems(prev => prev.filter(item => item.id !== productId));
42+
setCartItems((prev) => prev.filter((item) => item.id !== productId));
3943
toast.error('Item removed from cart', { icon: '🗑️' });
4044
};
4145

4246
const handleCheckout = async () => {
4347
try {
44-
const items = cartItems.map(item => ({ productId: item.id, quantity: item.quantity }));
48+
const items = cartItems.map((item) => ({ productId: item.id, quantity: item.quantity }));
4549
const response = await checkout(items);
4650
toast.success(response.message || 'Checkout successful! 🎉', { duration: 4000 });
4751
setCartItems([]);
@@ -55,40 +59,59 @@ export default function App() {
5559

5660
return (
5761
<>
58-
<Toaster position="bottom-right" toastOptions={{
59-
style: {
60-
background: '#333',
61-
color: '#fff',
62-
borderRadius: '10px'
63-
}
64-
}} />
65-
62+
<Toaster
63+
position="bottom-right"
64+
toastOptions={{
65+
style: {
66+
background: '#333',
67+
color: '#fff',
68+
borderRadius: '10px',
69+
},
70+
}}
71+
/>
72+
6673
<header className="app-header">
6774
<div className="logo">NexusTech</div>
68-
<button className="btn" onClick={() => setIsCartOpen(true)} style={{ background: 'rgba(255,255,255,0.1)' }}>
75+
<button
76+
className="btn"
77+
onClick={() => setIsCartOpen(true)}
78+
style={{ background: 'rgba(255,255,255,0.1)' }}
79+
>
6980
<ShoppingBag size={20} />
70-
Cart {totalItems > 0 && <span style={{ background: '#3b82f6', padding: '2px 8px', borderRadius: '12px', fontSize: '0.8rem' }}>{totalItems}</span>}
81+
Cart{' '}
82+
{totalItems > 0 && (
83+
<span
84+
style={{
85+
background: '#3b82f6',
86+
padding: '2px 8px',
87+
borderRadius: '12px',
88+
fontSize: '0.8rem',
89+
}}
90+
>
91+
{totalItems}
92+
</span>
93+
)}
7194
</button>
7295
</header>
7396

7497
<main className="main-content">
7598
<h2>Recommended For You</h2>
7699
<div className="products-grid">
77100
{products.map((product, idx) => (
78-
<ProductCard
79-
key={product.id}
80-
product={product}
81-
onAddToCart={handleAddToCart}
101+
<ProductCard
102+
key={product.id}
103+
product={product}
104+
onAddToCart={handleAddToCart}
82105
animationDelay={idx * 0.1}
83106
/>
84107
))}
85108
</div>
86109
</main>
87110

88-
<Cart
89-
isOpen={isCartOpen}
90-
onClose={() => setIsCartOpen(false)}
91-
items={cartItems}
111+
<Cart
112+
isOpen={isCartOpen}
113+
onClose={() => setIsCartOpen(false)}
114+
items={cartItems}
92115
onRemove={handleRemoveFromCart}
93116
onCheckout={handleCheckout}
94117
/>

0 commit comments

Comments
 (0)