Skip to content

Commit

Permalink
test: avoid overloading external services with requests
Browse files Browse the repository at this point in the history
  • Loading branch information
CedrikNikita committed Jan 17, 2023
1 parent 1ae9243 commit aa852fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/popup/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const testAccount = {
address: 'ak_2fxchiLvnj9VADMAXHBiKPsaCEsTFehAspcmWJ3ZzF3pFK1hB5',
};

export const STUB_CURRENCY = [{
id: 'aeternity', symbol: 'ae', name: 'Aeternity', image: 'https://assets.coingecko.com/coins/images/1091/large/aeternity.png?1547035060', current_price: 0.076783, market_cap: 31487891, market_cap_rank: 523, fully_diluted_valuation: null, total_volume: 217034, high_24h: 0.078539, low_24h: 0.076793, price_change_24h: -0.001092194951687525, price_change_percentage_24h: -1.4025, market_cap_change_24h: -429134.39267925173, market_cap_change_percentage_24h: -1.34453, circulating_supply: 409885828.49932, total_supply: 536306702.0, max_supply: null, ath: 5.69, ath_change_percentage: -98.65091, ath_date: '2018-04-29T03:50:39.593Z', atl: 0.059135, atl_change_percentage: 29.84246, atl_date: '2020-03-13T02:29:11.856Z', roi: { times: -0.725775445642378, currency: 'usd', percentage: -72.57754456423778 }, last_updated: '2023-01-17T11:38:23.610Z',
}];

export const popupProps = {
connectConfirm: {
type: 'connectConfirm',
Expand Down
17 changes: 15 additions & 2 deletions tests/e2e/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import '../../../src/lib/initPolyfills';
import { v4 as uuid } from 'uuid';
import { ROUTE_ACCOUNT_DETAILS_TRANSACTIONS } from '../../../src/popup/router/routeNames';
import { formatDate, formatTime, getLoginState } from '../../../src/popup/utils';
import { STUB_CURRENCY } from '../../../src/popup/utils/config';
import {
formatDate,
formatTime,
getLoginState,
CURRENCY_URL,
CURRENCIES_URL,
} from '../../../src/popup/utils';

Cypress.Commands.add('openPopup', (onBeforeLoad, route) => {
cy.visit(`${route ? `#${route}` : ''}`, { onBeforeLoad });
Expand Down Expand Up @@ -41,7 +48,13 @@ Cypress.Commands.add('shouldHasErrorMessage', (el) => {
cy.get(el).should('exist').should('be.visible');
});

Cypress.Commands.add('login', (options = {}, route) => {
Cypress.Commands.add('mockExternalRequests', () => {
cy.intercept('GET', CURRENCY_URL, STUB_CURRENCY);
cy.intercept('GET', CURRENCIES_URL, { aeternity: { usd: 0.05 } });
});

Cypress.Commands.add('login', (options = {}, route, isMockingExternalRequests = true) => {
if (isMockingExternalRequests) cy.mockExternalRequests();
cy.openPopup(async (contentWindow) => {
/* eslint-disable-next-line no-param-reassign */
contentWindow.localStorage.state = JSON.stringify(await getLoginState(options));
Expand Down

0 comments on commit aa852fa

Please sign in to comment.