auto(agent): Add validation and tests for contacts route
This commit is contained in:
parent
7b5ffa06be
commit
254f71e98f
2 changed files with 24 additions and 0 deletions
|
|
@ -43,4 +43,13 @@ test('POST /contacts should validate contact data', async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(response.statusCode, 400);
|
assert.strictEqual(response.statusCode, 400);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GET /contacts should return 401 for unauthorized access', async () => {
|
||||||
|
const response = await app.inject({
|
||||||
|
method: 'GET',
|
||||||
|
url: '/contacts'
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(response.statusCode, 401);
|
||||||
});
|
});
|
||||||
|
|
@ -147,4 +147,19 @@ router.get('/deal/:dealId', requireAuth, async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add validation for GET /contacts
|
||||||
|
router.get('/', requireAuth, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const [rows] = await pool.query(
|
||||||
|
`SELECT id, name, email, phone_encrypted FROM contacts WHERE user_id = ?`,
|
||||||
|
[req.user.userId]
|
||||||
|
);
|
||||||
|
|
||||||
|
res.json(rows);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in contacts get route:', error);
|
||||||
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue