90 lines
No EOL
2 KiB
JavaScript
90 lines
No EOL
2 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('assert');
|
|
const { app } = require('../app');
|
|
|
|
test('GET /reviews should return all reviews', async () => {
|
|
const response = await app.inject({
|
|
method: 'GET',
|
|
url: '/reviews'
|
|
});
|
|
|
|
assert.strictEqual(response.statusCode, 200);
|
|
assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8');
|
|
});
|
|
|
|
test('POST /reviews should create a new review', async () => {
|
|
const newReview = {
|
|
dealId: 1,
|
|
revieweeId: 2,
|
|
rating: 5,
|
|
comment: 'Great product'
|
|
};
|
|
|
|
const response = await app.inject({
|
|
method: 'POST',
|
|
url: '/reviews/1',
|
|
payload: newReview
|
|
});
|
|
|
|
assert.strictEqual(response.statusCode, 201);
|
|
assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8');
|
|
});
|
|
|
|
test('POST /reviews should return 400 for invalid review data', async () => {
|
|
const invalidReview = {
|
|
dealId: 1,
|
|
revieweeId: 2,
|
|
rating: 6,
|
|
comment: 'Some content'
|
|
};
|
|
|
|
const response = await app.inject({
|
|
method: 'POST',
|
|
url: '/reviews/1',
|
|
payload: invalidReview
|
|
});
|
|
|
|
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);
|
|
}); |