auto(agent): enhance reviews route tests and validation
This commit is contained in:
parent
32c84925df
commit
2d68f838ec
2 changed files with 54 additions and 10 deletions
|
|
@ -14,14 +14,15 @@ test('GET /reviews should return all reviews', async () => {
|
||||||
|
|
||||||
test('POST /reviews should create a new review', async () => {
|
test('POST /reviews should create a new review', async () => {
|
||||||
const newReview = {
|
const newReview = {
|
||||||
title: 'Great product',
|
dealId: 1,
|
||||||
content: 'I really enjoyed using this.',
|
revieweeId: 2,
|
||||||
rating: 5
|
rating: 5,
|
||||||
|
comment: 'Great product'
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await app.inject({
|
const response = await app.inject({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/reviews',
|
url: '/reviews/1',
|
||||||
payload: newReview
|
payload: newReview
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -31,16 +32,59 @@ test('POST /reviews should create a new review', async () => {
|
||||||
|
|
||||||
test('POST /reviews should return 400 for invalid review data', async () => {
|
test('POST /reviews should return 400 for invalid review data', async () => {
|
||||||
const invalidReview = {
|
const invalidReview = {
|
||||||
title: '',
|
dealId: 1,
|
||||||
content: 'Some content',
|
revieweeId: 2,
|
||||||
rating: 6
|
rating: 6,
|
||||||
|
comment: 'Some content'
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await app.inject({
|
const response = await app.inject({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/reviews',
|
url: '/reviews/1',
|
||||||
payload: invalidReview
|
payload: invalidReview
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(response.statusCode, 400);
|
assert.strictEqual(response.statusCode, 400);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('POST /reviews should return 404 for non-existent deal', async () => {
|
||||||
|
const newReview = {
|
||||||
|
dealId: 999,
|
||||||
|
revieweeId: 2,
|
||||||
|
rating: 5,
|
||||||
|
comment: 'Great product'
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await app.inject({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/reviews/999',
|
||||||
|
payload: newReview
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(response.statusCode, 404);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('POST /reviews should return 409 for already reviewed deal', async () => {
|
||||||
|
const newReview = {
|
||||||
|
dealId: 1,
|
||||||
|
revieweeId: 2,
|
||||||
|
rating: 5,
|
||||||
|
comment: 'Great product'
|
||||||
|
};
|
||||||
|
|
||||||
|
// First submission
|
||||||
|
await app.inject({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/reviews/1',
|
||||||
|
payload: newReview
|
||||||
|
});
|
||||||
|
|
||||||
|
// Second submission - should fail
|
||||||
|
const response = await app.inject({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/reviews/1',
|
||||||
|
payload: newReview
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(response.statusCode, 409);
|
||||||
});
|
});
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
LAST_ROUTE=profile.js
|
LAST_ROUTE=reviews.js
|
||||||
UPDATED_AT=2026-03-06T19:50:34Z
|
UPDATED_AT=2026-03-06T19:51:18Z
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue