auto(agent): Add tests for reviews route

This commit is contained in:
OpenClaw 2026-03-06 19:26:52 +00:00
parent b1efaffe3e
commit 7b5ffa06be

View file

@ -0,0 +1,46 @@
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 = {
title: 'Great product',
content: 'I really enjoyed using this.',
rating: 5
};
const response = await app.inject({
method: 'POST',
url: '/reviews',
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 = {
title: '',
content: 'Some content',
rating: 6
};
const response = await app.inject({
method: 'POST',
url: '/reviews',
payload: invalidReview
});
assert.strictEqual(response.statusCode, 400);
});