diff --git a/backend/src/modules/ticket/domain/entities/tickect.entity.spec.ts b/backend/src/modules/ticket/domain/entities/tickect.entity.spec.ts index 8835c59..6235f62 100644 --- a/backend/src/modules/ticket/domain/entities/tickect.entity.spec.ts +++ b/backend/src/modules/ticket/domain/entities/tickect.entity.spec.ts @@ -103,16 +103,14 @@ describe('Ticket entity', () => { ); }); - it('Should throw an error when closing a ticket with ESCALATED status', () => { + it('Should successfully close a ticket when status is ESCALATED', () => { ticket.assignToAgent(randomUUID()); - ticket.escalate(randomUUID(), 1, 'web_app'); expect(ticket.status).toBe(TicketStatus.ESCALATED); - expect(() => ticket.close('Test solution')).toThrow( - TicketValidationErrors.CLOSE_WITH_WRONG_STATUS_ERROR, - ); + ticket.close('Test solution'); + expect(ticket.status).toBe(TicketStatus.CLOSED); }); it('Close a ticket should change the status and closedAt field, and add the event to history', () => { @@ -133,18 +131,17 @@ describe('Ticket entity', () => { expect(primitiveTicket.closedAt).not.toBeNull(); }); - it('Should throw an error when closing a ticket with OPEN status', () => { + it('Should successfully close a ticket when status is OPEN', () => { expect(ticket.status).toBe(TicketStatus.OPEN); - expect(() => ticket.close('Test solution')).toThrow( - TicketValidationErrors.CLOSE_WITH_WRONG_STATUS_ERROR, - ); + + ticket.close('Test solution'); + expect(ticket.status).toBe(TicketStatus.CLOSED); }); - it('Should throw an error when closing a ticket with ESCALATED status', () => { - ticket.assignToAgent(randomUUID()); - ticket.escalate(randomUUID(),1, 'web_app'); + it('Should throw an error when trying to close a ticket that is already CLOSED', () => { + ticket.close('First solution'); + expect(ticket.status).toBe(TicketStatus.CLOSED); - expect(ticket.status).toBe(TicketStatus.ESCALATED); expect(() => ticket.close('Test solution')).toThrow( TicketValidationErrors.CLOSE_WITH_WRONG_STATUS_ERROR, ); @@ -157,4 +154,4 @@ describe('Ticket entity', () => { TicketValidationErrors.CLOSE_WITH_NO_SOLUTION_ERROR, ); }); -}); +}); \ No newline at end of file diff --git a/backend/src/modules/ticket/domain/entities/ticket.entity.ts b/backend/src/modules/ticket/domain/entities/ticket.entity.ts index 6686424..f31b478 100644 --- a/backend/src/modules/ticket/domain/entities/ticket.entity.ts +++ b/backend/src/modules/ticket/domain/entities/ticket.entity.ts @@ -271,7 +271,7 @@ export class Ticket { // Function to close the ticket and register the solution close(solution: string): void { - if (this.status !== TicketStatus.IN_PROGRESS) { + if (this.status === TicketStatus.CLOSED) { throw new Error(TicketValidationErrors.CLOSE_WITH_WRONG_STATUS_ERROR); } diff --git a/backend/src/modules/ticket/presentation/controllers/ticket.controller.ts b/backend/src/modules/ticket/presentation/controllers/ticket.controller.ts index 9b4ed19..1d573e1 100644 --- a/backend/src/modules/ticket/presentation/controllers/ticket.controller.ts +++ b/backend/src/modules/ticket/presentation/controllers/ticket.controller.ts @@ -218,7 +218,7 @@ export class TicketController { @ApiParam({ name: 'id', example: 'uuid-do-ticket' }) @ApiBody({ type: UpdateTicketStatusRequest }) @UseGuards(JwtGuard, RolesGuard) - @Roles(UserRole.ADMIN, UserRole.SUPPORT) + @Roles(UserRole.ADMIN, UserRole.SUPPORT, UserRole.CLIENT) @ApiResponse({ status: 200, description: 'Status do ticket alterado com sucesso.' }) async updateStatus( @Request() req: any,