Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions backend/src/modules/ticket/domain/entities/tickect.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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,
);
Expand All @@ -157,4 +154,4 @@ describe('Ticket entity', () => {
TicketValidationErrors.CLOSE_WITH_NO_SOLUTION_ERROR,
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading