diff --git a/packages/manager/.changeset/pr-10465-tests-1715702208954.md b/packages/manager/.changeset/pr-10465-tests-1715702208954.md new file mode 100644 index 00000000000..30c1318e0c7 --- /dev/null +++ b/packages/manager/.changeset/pr-10465-tests-1715702208954.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tests +--- + +Clean up support ticket test intercepts ([#10465](https://github.com/linode/manager/pull/10465)) diff --git a/packages/manager/cypress/e2e/core/helpAndSupport/open-support-ticket.spec.ts b/packages/manager/cypress/e2e/core/helpAndSupport/open-support-ticket.spec.ts index 72456bd05ee..d5a3b762de9 100644 --- a/packages/manager/cypress/e2e/core/helpAndSupport/open-support-ticket.spec.ts +++ b/packages/manager/cypress/e2e/core/helpAndSupport/open-support-ticket.spec.ts @@ -8,7 +8,6 @@ import { } from 'support/helpers'; import 'cypress-file-upload'; import { interceptGetProfile } from 'support/intercepts/profile'; -import { apiMatcher } from 'support/util/intercepts'; import { mockAppendFeatureFlags, mockGetFeatureFlagClientstream, @@ -23,6 +22,7 @@ import { } from 'support/util/random'; import { supportTicketFactory } from 'src/factories'; import { + mockAttachSupportTicketFile, mockCreateSupportTicket, mockGetSupportTicket, mockGetSupportTickets, @@ -58,7 +58,7 @@ describe('help & support', () => { cy.wait('@getProfile').then((xhr) => { const user = xhr.response?.body['username']; - const mockTicketData = { + const mockTicketData = supportTicketFactory.build({ attachments: [image], closable: false, closed: null, @@ -71,32 +71,13 @@ describe('help & support', () => { summary: 'cy-test ticket', updated: ts.toISOString(), updated_by: user, - }; + }); + // intercept create ticket request, stub response. - cy.intercept('POST', apiMatcher('support/tickets'), mockTicketData).as( - 'createTicket' - ); - // stub incoming response - cy.intercept( - 'GET', - apiMatcher(`support/tickets/${ticketId}`), - mockTicketData - ).as('getTicket'); - // intercept create support ticket request, stub response with 200 - cy.intercept( - 'POST', - apiMatcher(`support/tickets/${ticketId}/attachments`), - (req) => { - req.reply(200); - } - ).as('attachmentPost'); - // stub incoming response - cy.intercept(apiMatcher(`support/tickets/${ticketId}/replies*`), { - data: [], - page: 1, - pages: 1, - results: 0, - }).as('getReplies'); + mockCreateSupportTicket(mockTicketData).as('createTicket'); + mockGetSupportTicket(mockTicketData).as('getTicket'); + mockGetSupportTicketReplies(ticketId, []).as('getReplies'); + mockAttachSupportTicketFile(ticketId).as('attachmentPost'); containsClick('Open New Ticket'); cy.get('input[placeholder="Enter a title for your ticket."]') diff --git a/packages/manager/cypress/support/intercepts/support.ts b/packages/manager/cypress/support/intercepts/support.ts index 7e1ea4d36d9..d4a65e94b71 100644 --- a/packages/manager/cypress/support/intercepts/support.ts +++ b/packages/manager/cypress/support/intercepts/support.ts @@ -25,6 +25,21 @@ export const mockCreateSupportTicket = ( ); }; +/** + * Interepts request to attach file to support ticket and mocks response. + * + * @param ticketId - Support ticket ID for which to intercept request. + * + * @returns Cypress chainable. + */ +export const mockAttachSupportTicketFile = (ticketId: number) => { + return cy.intercept( + 'POST', + apiMatcher(`support/tickets/${ticketId}/attachments`), + {} + ); +}; + /** * Intercepts request to fetch a support ticket and mocks response. *