place-contrib: audit a switch-off whose withdrawal the service did not confirm

Switching sharing off commits before the withdrawal asks the service. When
the service did not confirm, the decision had taken effect but left no audit
row. It is now audited with withdrawFailed, and the admin still gets the
error.
This commit is contained in:
Maurice
2026-10-30 23:14:32 +00:00
parent 593df53993
commit 7ade99c8ce
2 changed files with 36 additions and 8 deletions
@@ -7,6 +7,7 @@
import type { AuditService } from '../../../../src/nest/audit/audit.service';
import { AdminGuard } from '../../../../src/nest/auth-core/admin.guard';
import { JwtAuthGuard } from '../../../../src/nest/auth-core/jwt-auth.guard';
import { DomainError } from '../../../../src/nest/common/domain-error';
import { RESPONSE_CONTRACT_KEY } from '../../../../src/nest/common/response-contract';
import { PlaceContribController } from '../../../../src/nest/place-contrib/place-contrib.controller';
import {
@@ -87,6 +88,20 @@ describe('PlaceContribController', () => {
expect(audit.writeAudit).not.toHaveBeenCalled();
});
it('PCCT-010: switching off whose withdrawal the service did not confirm is still audited, then fails', async () => {
const refused = new DomainError(502, 'The TREK Places API did not confirm the withdrawal');
contrib.decide.mockRejectedValueOnce(refused);
await expect(
controller.decide(admin, { action: 'off', withdraw: true } as PlaceContribDecisionDto, req),
).rejects.toBe(refused);
expect(audit.writeAudit).toHaveBeenCalledWith({
userId: 3,
action: 'admin.places_contribute_decision',
details: { action: 'off', withdraw: true, withdrawFailed: true },
ip: '203.0.113.9',
});
});
it('PCCT-006: the log query goes to the service as parsed', async () => {
const query = { page: 2, perPage: 10, result: 'withheld' } as PlaceContribLogQueryDto;
expect(await controller.log(query)).toEqual({ entries: [], total: 0, page: 2, perPage: 10 });