Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: [M3-6221] - Clean up cy.intercept calls in support ticket create test #10465

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
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10465-tests-1715702208954.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Clean up support ticket test intercepts ([#10465](https://github.com/linode/manager/pull/10465))
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,6 +22,7 @@ import {
} from 'support/util/random';
import { supportTicketFactory } from 'src/factories';
import {
mockAttachSupportTicketFile,
mockCreateSupportTicket,
mockGetSupportTicket,
mockGetSupportTickets,
Expand Down Expand Up @@ -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,
Expand All @@ -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."]')
Expand Down
15 changes: 15 additions & 0 deletions packages/manager/cypress/support/intercepts/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading