chore(trading): tweaking catching no market data error (#3044)
This commit is contained in:
parent
4430f0c5f6
commit
068f7b3fc3
@ -20,46 +20,78 @@ describe('positions', { tags: '@smoke' }, () => {
|
|||||||
cy.getByTestId('Positions').click();
|
cy.getByTestId('Positions').click();
|
||||||
validatePositionsDisplayed();
|
validatePositionsDisplayed();
|
||||||
});
|
});
|
||||||
|
describe('renders position among some graphql errors', () => {
|
||||||
it('renders position among some graphql errors', () => {
|
it('rows should be displayed despite errors', () => {
|
||||||
const errors = [
|
const errors = [
|
||||||
{
|
{
|
||||||
message: 'no market data for market: market-2',
|
message:
|
||||||
path: ['market', 'data'],
|
'no market data for market: 9c55fb644c6f7de5422d40d691a62bffd5898384c70135bab29ba1e3e2e5280a',
|
||||||
extensions: {
|
path: ['marketsConnection', 'edges'],
|
||||||
code: 13,
|
extensions: {
|
||||||
type: 'Internal',
|
code: 13,
|
||||||
|
type: 'Internal',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
];
|
||||||
];
|
const marketData = marketsDataQuery();
|
||||||
const marketData = marketsDataQuery();
|
const edges = marketData.marketsConnection?.edges.map((market) => {
|
||||||
const edges = marketData.marketsConnection?.edges.map((market) => {
|
const replace =
|
||||||
const replace =
|
market.node.data?.market.id === 'market-2' ? null : market.node.data;
|
||||||
market.node.data?.market.id === 'market-2' ? null : market.node.data;
|
return { ...market, node: { ...market.node, data: replace } };
|
||||||
return { ...market, node: { ...market.node, data: replace } };
|
});
|
||||||
});
|
const overrides = {
|
||||||
const overrides = {
|
...marketData,
|
||||||
...marketData,
|
marketsConnection: { ...marketData.marketsConnection, edges },
|
||||||
marketsConnection: { ...marketData.marketsConnection, edges },
|
};
|
||||||
};
|
cy.mockGQL((req) => {
|
||||||
cy.mockGQL((req) => {
|
aliasGQLQuery(req, 'MarketsData', overrides, errors);
|
||||||
aliasGQLQuery(req, 'MarketsData', overrides, errors);
|
});
|
||||||
});
|
cy.visit('/#/markets/market-0');
|
||||||
cy.visit('/#/markets/market-0');
|
const emptyCells = [
|
||||||
const emptyCells = [
|
'notional',
|
||||||
'notional',
|
'markPrice',
|
||||||
'markPrice',
|
'liquidationPrice',
|
||||||
'liquidationPrice',
|
'currentLeverage',
|
||||||
'currentLeverage',
|
'averageEntryPrice',
|
||||||
'averageEntryPrice',
|
];
|
||||||
];
|
cy.getByTestId('tab-positions').within(() => {
|
||||||
cy.getByTestId('tab-positions').within(() => {
|
cy.get('[row-id="market-2"]').within(() => {
|
||||||
cy.get('[row-id="market-2"]').within(() => {
|
emptyCells.forEach((cell) => {
|
||||||
emptyCells.forEach((cell) => {
|
cy.get(`[col-id="${cell}"]`).should('contain.text', '-');
|
||||||
cy.get(`[col-id="${cell}"]`).should('contain.text', '-');
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('error message should be displayed', () => {
|
||||||
|
const errors = [
|
||||||
|
{
|
||||||
|
message:
|
||||||
|
'no market data for asset: 9c55fb644c6f7de5422d40d691a62bffd5898384c70135bab29ba1e3e2e5280a',
|
||||||
|
path: ['assets', 'edges'],
|
||||||
|
extensions: {
|
||||||
|
code: 13,
|
||||||
|
type: 'Internal',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const marketData = marketsDataQuery();
|
||||||
|
const edges = marketData.marketsConnection?.edges.map((market) => {
|
||||||
|
const replace =
|
||||||
|
market.node.data?.market.id === 'market-2' ? null : market.node.data;
|
||||||
|
return { ...market, node: { ...market.node, data: replace } };
|
||||||
|
});
|
||||||
|
const overrides = {
|
||||||
|
...marketData,
|
||||||
|
marketsConnection: { ...marketData.marketsConnection, edges },
|
||||||
|
};
|
||||||
|
cy.mockGQL((req) => {
|
||||||
|
aliasGQLQuery(req, 'MarketsData', overrides, errors);
|
||||||
|
});
|
||||||
|
cy.visit('/#/markets/market-0');
|
||||||
|
cy.get('.pointer-events-none.absolute.inset-0').contains(
|
||||||
|
'Something went wrong:'
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sorting by ag-grid columns should work well', () => {
|
describe('sorting by ag-grid columns should work well', () => {
|
||||||
|
@ -2,7 +2,6 @@ import type { ApolloError } from '@apollo/client';
|
|||||||
import type { GraphQLErrors } from '@apollo/client/errors';
|
import type { GraphQLErrors } from '@apollo/client/errors';
|
||||||
|
|
||||||
const NOT_FOUND = 'NotFound';
|
const NOT_FOUND = 'NotFound';
|
||||||
const INTERNAL = 'Internal';
|
|
||||||
|
|
||||||
const isApolloGraphQLError = (
|
const isApolloGraphQLError = (
|
||||||
error: ApolloError | Error | undefined
|
error: ApolloError | Error | undefined
|
||||||
@ -29,12 +28,5 @@ export const isNotFoundGraphQLError = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const marketDataErrorPolicyGuard = (errors: GraphQLErrors) => {
|
export const marketDataErrorPolicyGuard = (errors: GraphQLErrors) =>
|
||||||
const path = ['market', 'data'];
|
errors.every((e) => e.message.match(/no market data for market:/i));
|
||||||
return errors.every(
|
|
||||||
(e) =>
|
|
||||||
e.extensions &&
|
|
||||||
e.extensions['type'] === INTERNAL &&
|
|
||||||
(!path || path.every((item, i) => item === e?.path?.[i]))
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user