auto(agent): Run expanded local discovery and continue with next actionable task
This commit is contained in:
parent
53827506a3
commit
6d9bf4c461
1 changed files with 45 additions and 0 deletions
45
backend/src/__tests__/addresses.test.js
Normal file
45
backend/src/__tests__/addresses.test.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
const { test } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const sinon = require('sinon');
|
||||
const { getAddresses, createAddress } = require('../routes/addresses');
|
||||
|
||||
// Mock the database pool
|
||||
const mockPool = {
|
||||
query: sinon.stub()
|
||||
};
|
||||
|
||||
// Mock the route functions with the mocked pool
|
||||
const mockGetAddresses = (req, res) => getAddresses({ ...req, pool: mockPool }, res);
|
||||
const mockCreateAddress = (req, res) => createAddress({ ...req, pool: mockPool }, res);
|
||||
|
||||
test('GET /addresses should return addresses', async () => {
|
||||
const mockResponse = {
|
||||
status: sinon.stub().returnsThis(),
|
||||
json: sinon.stub()
|
||||
};
|
||||
|
||||
mockPool.query.resolves([{ id: 1, street: 'Test Street', city: 'Test City' }]);
|
||||
|
||||
await mockGetAddresses({}, mockResponse);
|
||||
|
||||
assert.strictEqual(mockResponse.status.calledWith(200), true);
|
||||
assert.strictEqual(mockResponse.json.calledOnce, true);
|
||||
});
|
||||
|
||||
test('POST /addresses should create a new address', async () => {
|
||||
const mockRequest = {
|
||||
body: { street: 'New Street', city: 'New City' }
|
||||
};
|
||||
|
||||
const mockResponse = {
|
||||
status: sinon.stub().returnsThis(),
|
||||
json: sinon.stub()
|
||||
};
|
||||
|
||||
mockPool.query.resolves([{ id: 2, street: 'New Street', city: 'New City' }]);
|
||||
|
||||
await mockCreateAddress(mockRequest, mockResponse);
|
||||
|
||||
assert.strictEqual(mockResponse.status.calledWith(201), true);
|
||||
assert.strictEqual(mockResponse.json.calledOnce, true);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue