fix(#15): Erweiterte Contract-Tests für alle Kernflows inkl. Contacts Endpunkte
Some checks are pending
Docker Test / test (push) Waiting to run

This commit is contained in:
OpenClaw 2026-03-06 23:44:27 +00:00
parent e93904f02d
commit bbeea75b00

View file

@ -219,4 +219,102 @@ describe('API Contract Tests', () => {
expect(response.status).toBe(200); expect(response.status).toBe(200);
}); });
}); });
describe('Contacts Endpoints', () => {
let helpRequestId;
let offerId;
beforeAll(async () => {
// Create a help request and offer to have valid IDs for contact tests
const requestResponse = await request(app)
.post('/requests')
.set('Authorization', `Bearer ${authToken}`)
.send({
title: 'Test Help Request for Contact',
description: 'This is a test help request for contacts',
valueChf: 50.0
});
helpRequestId = requestResponse.body.id;
const offerResponse = await request(app)
.post('/offers')
.set('Authorization', `Bearer ${authToken}`)
.send({
helpRequestId,
description: 'This is a test offer for contacts',
valueChf: 45.0
});
offerId = offerResponse.body.id;
});
it('should fetch all contacts', async () => {
const response = await request(app)
.get('/contacts')
.set('Authorization', `Bearer ${authToken}`);
expect(response.status).toBe(200);
expect(Array.isArray(response.body)).toBe(true);
});
it('should create a new contact', async () => {
const response = await request(app)
.post('/contacts')
.set('Authorization', `Bearer ${authToken}`)
.send({
name: 'Test Contact',
email: 'test@example.com',
phone: '123-456-7890'
});
expect(response.status).toBe(201);
expect(response.body).toHaveProperty('id');
});
it('should fail to create a contact with invalid data', async () => {
const response = await request(app)
.post('/contacts')
.set('Authorization', `Bearer ${authToken}`)
.send({
name: '',
email: 'invalid-email',
phone: ''
});
expect(response.status).toBe(400);
});
it('should send a contact request', async () => {
const response = await request(app)
.post('/contacts/request')
.set('Authorization', `Bearer ${authToken}`)
.send({
dealId: helpRequestId,
targetUserId: testUserId
});
expect(response.status).toBe(403); // Forbidden because we're not in a valid deal context
});
it('should respond to a contact request', async () => {
const response = await request(app)
.post('/contacts/respond')
.set('Authorization', `Bearer ${authToken}`)
.send({
requestId: 1,
accept: true
});
expect(response.status).toBe(404); // Not found because we don't have a valid request ID
});
it('should fetch contacts for a deal', async () => {
const response = await request(app)
.get(`/contacts/deal/${helpRequestId}`)
.set('Authorization', `Bearer ${authToken}`);
expect(response.status).toBe(403); // Forbidden because we're not in a valid deal context
});
});
}); });