Skip to content
Closed
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
2 changes: 2 additions & 0 deletions packages/manager/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { configureMultiReporters } from './cypress/support/plugins/configure-mul
import { discardPassedTestRecordings } from './cypress/support/plugins/discard-passed-test-recordings';
import { featureFlagOverrides } from './cypress/support/plugins/feature-flag-override';
import { fetchAccount } from './cypress/support/plugins/fetch-account';
import { fetchInitialEvents } from './cypress/support/plugins/fetch-events';
import { fetchLinodeClusters } from './cypress/support/plugins/fetch-linode-clusters';
import { fetchLinodeImages } from './cypress/support/plugins/fetch-linode-images';
import { fetchLinodeRegions } from './cypress/support/plugins/fetch-linode-regions';
Expand Down Expand Up @@ -101,6 +102,7 @@ export default defineConfig({
vitePreprocess,
discardPassedTestRecordings,
fetchAccount,
fetchInitialEvents,
fetchLinodeRegions,
fetchLinodeClusters,
fetchLinodeImages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,16 @@ describe('create image (using mocks)', () => {
.click();

// Verify the POST /v4/images request happens
mockGetEvents([
eventFactory.build({ action: 'disk_imagize', status: 'finished' }),
]).as('getEvents');
cy.wait('@createImage');

ui.toast.assertMessage('Image scheduled for creation.');

// Verify we redirect to the images landing page upon successful creation
cy.url().should('endWith', 'images');

mockGetEvents([
eventFactory.build({ action: 'disk_imagize', status: 'finished' }),
]).as('getEvents');

// Wait for the next events polling request
cy.wait('@getEvents');

Expand Down
2 changes: 2 additions & 0 deletions packages/manager/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ import { blockAnalytics } from './setup/block-analytics';
import { deleteInternalHeader } from './setup/delete-internal-header';
import { mockFeatureFlagClientstream } from './setup/feature-flag-clientstream';
import { mockAccountRequest } from './setup/mock-account-request';
import { mockInitialEventsRequest } from './setup/mock-events-request';
import { mockFeatureFlagRequests } from './setup/mock-feature-flags-request';
import { trackApiRequests } from './setup/request-tracking';

trackApiRequests();
mockAccountRequest();
mockInitialEventsRequest();
mockFeatureFlagRequests();
mockFeatureFlagClientstream();
deleteInternalHeader();
Expand Down
39 changes: 39 additions & 0 deletions packages/manager/cypress/support/plugins/fetch-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { getEvents } from '@linode/api-v4';
import { DateTime } from 'luxon';

import type { CypressPlugin } from './plugin';

// TODO Delete `plugin/fetch-events.ts` and `setup/mock-events-request.ts` when ARB-7116 is addressed.

Check warning on line 6 in packages/manager/cypress/support/plugins/fetch-events.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Complete the task associated to this "TODO" comment. Raw Output: {"ruleId":"sonarjs/todo-tag","severity":1,"message":"Complete the task associated to this \"TODO\" comment.","line":6,"column":4,"nodeType":null,"messageId":"completeTODO","endLine":6,"endColumn":8}
/**
* Fetches and caches the last 7-days worth of events on the user's account.
*
* This is used as part of a workaround for failures stemming from API performance
* issues in the events `v4beta` endpoints. By default, Cloud will mock responses
* to this endpoint using the data that's fetched here so that tests do not time
* out and fail while awaiting the initial events request.
*
* Once the API issue is resolved, this workaround will no longer be needed and
* should be removed. We expect this to be resolved around Dec 9, 2025.
*/
export const fetchInitialEvents: CypressPlugin = async (_on, config) => {
// Adapted from `src/queries/events/events.ts` and friends.
const eventCreatedCutoff = DateTime.now()
.minus({ days: 7 })
.setZone('utc')
.toFormat("yyyy-MM-dd'T'HH:mm:ss");

const events = await getEvents(undefined, {
action: { '+neq': 'profile_update' },
'+order': 'desc',
'+order_by': 'id',
created: { '+gt': eventCreatedCutoff },
});

return {
...config,
env: {
...config.env,
cloudManagerInitialEvents: events,
},
};
};
40 changes: 40 additions & 0 deletions packages/manager/cypress/support/setup/mock-events-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Event } from '@linode/api-v4';

Check warning on line 1 in packages/manager/cypress/support/setup/mock-events-request.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 All imports in the declaration are only used as types. Use `import type`. Raw Output: {"ruleId":"@typescript-eslint/consistent-type-imports","severity":1,"message":"All imports in the declaration are only used as types. Use `import type`.","line":1,"column":1,"nodeType":"ImportDeclaration","messageId":"typeOverValue","endLine":1,"endColumn":40,"fix":{"range":[6,6],"text":" type"}}
import { apiMatcher } from 'support/util/intercepts';
import { getFilters } from 'support/util/request';

export const mockInitialEventsRequest = () => {
const cachedEvents = Cypress.env('cloudManagerInitialEvents') as
| Event[]
| undefined;

// Short-circuit with a warning if no cached events data is available.
// In practice, this should be impossible: if the request to fetch the events
// data fails, Cypress will exit without running any tests.
if (!cachedEvents) {
console.warn('No cached events data is available');
return;
}

beforeEach(() => {
cy.intercept(
{
// middleware: true,
url: apiMatcher('account/events*'),
},
(req) => {
// Only mock the response if this is the initial fetch from Cloud Manager.
const filters = getFilters(req);

// Only our polling events requests have the '+and' filter at the top level,
// so we can use its existence to determine whether the intercepted request
// is for the initial fetch or subsequent polling fetches.
if (filters?.['+and']) {
req.continue();
return;
}

req.reply(cachedEvents);
}
);
});
};