chore: mock gql subscriptions (#1419)
* chore: mock gql subscriptions * chore: fix market info, inprove fills unit tests * chore: fix socket mock
This commit is contained in:
parent
792459e589
commit
d95bfb60ea
@ -1,2 +1,3 @@
|
|||||||
NX_USE_ENV_OVERRIDES=0
|
NX_USE_ENV_OVERRIDES=0
|
||||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||||
|
CYPRESS_VEGA_URL=https://api.n07.testnet.vega.xyz/graphql
|
@ -11,6 +11,7 @@ const formFieldError = 'input-error-text';
|
|||||||
describe('deposit form validation', () => {
|
describe('deposit form validation', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.mockWeb3Provider();
|
cy.mockWeb3Provider();
|
||||||
|
cy.mockGQLSubscription();
|
||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
aliasQuery(req, 'NetworkParamsQuery', generateNetworkParameters());
|
aliasQuery(req, 'NetworkParamsQuery', generateNetworkParameters());
|
||||||
aliasQuery(req, 'DepositPage', generateDepositPage());
|
aliasQuery(req, 'DepositPage', generateDepositPage());
|
||||||
|
@ -10,6 +10,7 @@ describe('vega wallet', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Using portfolio page as it requires vega wallet connection
|
// Using portfolio page as it requires vega wallet connection
|
||||||
cy.visit('/portfolio');
|
cy.visit('/portfolio');
|
||||||
|
cy.mockGQLSubscription();
|
||||||
cy.get('main[data-testid="portfolio"]').should('exist');
|
cy.get('main[data-testid="portfolio"]').should('exist');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ describe('home', () => {
|
|||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
cy.visit('/');
|
cy.visit('/');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ describe('market info is displayed', () => {
|
|||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
cy.visit('/markets/market-0');
|
cy.visit('/markets/market-0');
|
||||||
cy.wait('@Market');
|
cy.wait('@Market');
|
||||||
cy.getByTestId(marketInfoBtn).click();
|
cy.getByTestId(marketInfoBtn).click();
|
||||||
@ -128,7 +129,9 @@ describe('market info is displayed', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('liquidity displayed', () => {
|
it('liquidity displayed', () => {
|
||||||
cy.getByTestId('accordion-toggle').eq(13).click();
|
cy.getByTestId(marketTitle)
|
||||||
|
.contains(/Liquidity(?! m)/)
|
||||||
|
.click();
|
||||||
|
|
||||||
validateMarketDataRow(0, 'Target Stake', '0.56789 tBTC');
|
validateMarketDataRow(0, 'Target Stake', '0.56789 tBTC');
|
||||||
validateMarketDataRow(1, 'Supplied Stake', '0.56767 tBTC');
|
validateMarketDataRow(1, 'Supplied Stake', '0.56767 tBTC');
|
||||||
|
@ -6,6 +6,7 @@ describe('markets table', () => {
|
|||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders markets correctly', () => {
|
it('renders markets correctly', () => {
|
||||||
|
@ -6,6 +6,7 @@ beforeEach(() => {
|
|||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
cy.visit('/markets/market-0');
|
cy.visit('/markets/market-0');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ beforeEach(() => {
|
|||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
cy.visit('/markets/market-0');
|
cy.visit('/markets/market-0');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ describe('deal ticket orders', () => {
|
|||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
cy.visit('/markets/market-0');
|
cy.visit('/markets/market-0');
|
||||||
cy.wait('@Market');
|
cy.wait('@Market');
|
||||||
connectVegaWallet();
|
connectVegaWallet();
|
||||||
|
@ -10,6 +10,7 @@ describe('fills', () => {
|
|||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
aliasQuery(req, 'Fills', generateFills());
|
aliasQuery(req, 'Fills', generateFills());
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders fills on portfolio page', () => {
|
it('renders fills on portfolio page', () => {
|
||||||
|
@ -6,6 +6,7 @@ before(() => {
|
|||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
cy.visit('/markets/market-0');
|
cy.visit('/markets/market-0');
|
||||||
cy.getByTestId('Orders').click();
|
cy.getByTestId('Orders').click();
|
||||||
cy.getByTestId('tab-orders').contains('Please connect Vega wallet');
|
cy.getByTestId('tab-orders').contains('Please connect Vega wallet');
|
||||||
|
@ -6,6 +6,7 @@ beforeEach(() => {
|
|||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('positions', () => {
|
describe('positions', () => {
|
||||||
|
@ -5,6 +5,7 @@ beforeEach(() => {
|
|||||||
cy.mockGQL((req) => {
|
cy.mockGQL((req) => {
|
||||||
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
mockTradingPage(req, MarketState.STATE_ACTIVE);
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
cy.visit('/markets/market-0');
|
cy.visit('/markets/market-0');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ describe('withdraw', () => {
|
|||||||
aliasQuery(req, 'WithdrawFormQuery', generateWithdrawFormQuery());
|
aliasQuery(req, 'WithdrawFormQuery', generateWithdrawFormQuery());
|
||||||
aliasQuery(req, 'Accounts', generateAccounts());
|
aliasQuery(req, 'Accounts', generateAccounts());
|
||||||
});
|
});
|
||||||
|
cy.mockGQLSubscription();
|
||||||
|
|
||||||
cy.visit('/portfolio');
|
cy.visit('/portfolio');
|
||||||
cy.getByTestId('Withdrawals').click();
|
cy.getByTestId('Withdrawals').click();
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import { addGetTestIdcommand } from './lib/commands/get-by-test-id';
|
import { addGetTestIdcommand } from './lib/commands/get-by-test-id';
|
||||||
import { addMockGQLCommand } from './lib/commands/mock-gql';
|
import {
|
||||||
|
addMockGQLCommand,
|
||||||
|
addMockGQLSubscriptionCommand,
|
||||||
|
} from './lib/commands/mock-gql';
|
||||||
import { addMockVegaWalletCommands } from './lib/commands/mock-vega-wallet';
|
import { addMockVegaWalletCommands } from './lib/commands/mock-vega-wallet';
|
||||||
import { addMockWeb3ProviderCommand } from './lib/commands/mock-web3-provider';
|
import { addMockWeb3ProviderCommand } from './lib/commands/mock-web3-provider';
|
||||||
import { addSlackCommand } from './lib/commands/slack';
|
import { addSlackCommand } from './lib/commands/slack';
|
||||||
@ -8,6 +11,7 @@ import { addHighlightLog } from './lib/commands/highlight-log';
|
|||||||
addGetTestIdcommand();
|
addGetTestIdcommand();
|
||||||
addSlackCommand();
|
addSlackCommand();
|
||||||
addMockGQLCommand();
|
addMockGQLCommand();
|
||||||
|
addMockGQLSubscriptionCommand();
|
||||||
addMockVegaWalletCommands();
|
addMockVegaWalletCommands();
|
||||||
addMockWeb3ProviderCommand();
|
addMockWeb3ProviderCommand();
|
||||||
addHighlightLog();
|
addHighlightLog();
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import type { RouteHandler } from 'cypress/types/net-stubbing';
|
import type { RouteHandler } from 'cypress/types/net-stubbing';
|
||||||
|
import { Server, WebSocket } from 'mock-socket';
|
||||||
declare global {
|
declare global {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
namespace Cypress {
|
namespace Cypress {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
interface Chainable<Subject> {
|
interface Chainable<Subject> {
|
||||||
mockGQL(handler: RouteHandler): void;
|
mockGQL(handler: RouteHandler): void;
|
||||||
|
mockGQLSubscription(mocks?: Record<string, onMessage>): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -15,3 +16,49 @@ export function addMockGQLCommand() {
|
|||||||
cy.intercept('POST', '**/graphql', handler).as('GQL');
|
cy.intercept('POST', '**/graphql', handler).as('GQL');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mockSocketServer = Cypress.env('VEGA_URL')
|
||||||
|
? new Server(Cypress.env('VEGA_URL').replace('http', 'ws'))
|
||||||
|
: null;
|
||||||
|
|
||||||
|
interface onMessage {
|
||||||
|
(send: (data: object) => void, variables: object): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addMockGQLSubscriptionCommand() {
|
||||||
|
Cypress.Commands.add(
|
||||||
|
'mockGQLSubscription',
|
||||||
|
(mocks?: Record<string, onMessage>) => {
|
||||||
|
cy.on('window:before:load', (win) => {
|
||||||
|
if (!mockSocketServer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
win.WebSocket = WebSocket;
|
||||||
|
mockSocketServer.on('connection', (socket) => {
|
||||||
|
socket.on('message', (message) => {
|
||||||
|
if (typeof message !== 'string') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { id, payload, type } = JSON.parse(message);
|
||||||
|
if (type === 'connection_init') {
|
||||||
|
socket.send(JSON.stringify({ type: 'connection_ack' }));
|
||||||
|
}
|
||||||
|
if (payload && mocks && mocks[payload.operationName]) {
|
||||||
|
mocks[payload.operationName](
|
||||||
|
(data) =>
|
||||||
|
socket.send(
|
||||||
|
JSON.stringify({
|
||||||
|
type: 'data',
|
||||||
|
id,
|
||||||
|
payload: { errors: [], data },
|
||||||
|
})
|
||||||
|
),
|
||||||
|
payload.variables
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -51,7 +51,8 @@ describe('FillsTable', () => {
|
|||||||
await waitForGridToBeInTheDOM();
|
await waitForGridToBeInTheDOM();
|
||||||
await waitForDataToHaveLoaded();
|
await waitForDataToHaveLoaded();
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(async () => {
|
||||||
|
await screen.findByText('Market');
|
||||||
const headers = screen.getAllByRole('columnheader');
|
const headers = screen.getAllByRole('columnheader');
|
||||||
expect(headers).toHaveLength(7);
|
expect(headers).toHaveLength(7);
|
||||||
expect(headers.map((h) => h.textContent?.trim())).toEqual([
|
expect(headers.map((h) => h.textContent?.trim())).toEqual([
|
||||||
|
@ -238,7 +238,7 @@ export const Info = ({ market, onSelect }: InfoProps) => {
|
|||||||
<MarketInfoTable
|
<MarketInfoTable
|
||||||
data={market.riskFactors}
|
data={market.riskFactors}
|
||||||
unformatted={true}
|
unformatted={true}
|
||||||
omits={['market']}
|
omits={['market', '__typename']}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@ -264,12 +264,6 @@ export const Info = ({ market, onSelect }: InfoProps) => {
|
|||||||
<MarketInfoTable data={trigger} decimalPlaces={market.decimalPlaces} />
|
<MarketInfoTable data={trigger} decimalPlaces={market.decimalPlaces} />
|
||||||
),
|
),
|
||||||
})),
|
})),
|
||||||
...(market.data?.priceMonitoringBounds || []).map((trigger, i) => ({
|
|
||||||
title: t(`Price monitoring bound ${i + 1}`),
|
|
||||||
content: (
|
|
||||||
<MarketInfoTable data={trigger} decimalPlaces={market.decimalPlaces} />
|
|
||||||
),
|
|
||||||
})),
|
|
||||||
{
|
{
|
||||||
title: t('Liquidity monitoring parameters'),
|
title: t('Liquidity monitoring parameters'),
|
||||||
content: (
|
content: (
|
||||||
|
@ -160,6 +160,7 @@
|
|||||||
"jest-websocket-mock": "^2.3.0",
|
"jest-websocket-mock": "^2.3.0",
|
||||||
"lint-staged": "^12.3.3",
|
"lint-staged": "^12.3.3",
|
||||||
"mock-apollo-client": "^1.2.0",
|
"mock-apollo-client": "^1.2.0",
|
||||||
|
"mock-socket": "^9.1.5",
|
||||||
"npmlog": "^6.0.2",
|
"npmlog": "^6.0.2",
|
||||||
"nx": "14.5.10",
|
"nx": "14.5.10",
|
||||||
"postcss": "8.4.16",
|
"postcss": "8.4.16",
|
||||||
|
@ -16775,7 +16775,7 @@ mock-apollo-client@^1.2.0:
|
|||||||
resolved "https://registry.yarnpkg.com/mock-apollo-client/-/mock-apollo-client-1.2.1.tgz#e3bfdc3ff73b1fea28fa7e91ec82e43ba8cbfa39"
|
resolved "https://registry.yarnpkg.com/mock-apollo-client/-/mock-apollo-client-1.2.1.tgz#e3bfdc3ff73b1fea28fa7e91ec82e43ba8cbfa39"
|
||||||
integrity sha512-QYQ6Hxo+t7hard1bcHHbsHxlNQYTQsaMNsm2Psh/NbwLMi2R4tGzplJKt97MUWuARHMq3GHB4PTLj/gxej4Caw==
|
integrity sha512-QYQ6Hxo+t7hard1bcHHbsHxlNQYTQsaMNsm2Psh/NbwLMi2R4tGzplJKt97MUWuARHMq3GHB4PTLj/gxej4Caw==
|
||||||
|
|
||||||
mock-socket@^9.1.0:
|
mock-socket@^9.1.0, mock-socket@^9.1.5:
|
||||||
version "9.1.5"
|
version "9.1.5"
|
||||||
resolved "https://registry.yarnpkg.com/mock-socket/-/mock-socket-9.1.5.tgz#2c4e44922ad556843b6dfe09d14ed8041fa2cdeb"
|
resolved "https://registry.yarnpkg.com/mock-socket/-/mock-socket-9.1.5.tgz#2c4e44922ad556843b6dfe09d14ed8041fa2cdeb"
|
||||||
integrity sha512-3DeNIcsQixWHHKk6NdoBhWI4t1VMj5/HzfnI1rE/pLl5qKx7+gd4DNA07ehTaZ6MoUU053si6Hd+YtiM/tQZfg==
|
integrity sha512-3DeNIcsQixWHHKk6NdoBhWI4t1VMj5/HzfnI1rE/pLl5qKx7+gd4DNA07ehTaZ6MoUU053si6Hd+YtiM/tQZfg==
|
||||||
|
Loading…
Reference in New Issue
Block a user