chore(trading): tweaking catching no market data error (#3044)

This commit is contained in:
Maciek 2023-03-02 08:25:57 +01:00 committed by GitHub
parent 4430f0c5f6
commit 068f7b3fc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 46 deletions

View File

@ -20,12 +20,13 @@ 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',
path: ['marketsConnection', 'edges'],
extensions: { extensions: {
code: 13, code: 13,
type: 'Internal', type: 'Internal',
@ -61,6 +62,37 @@ describe('positions', { tags: '@smoke' }, () => {
}); });
}); });
}); });
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', () => {
it('sorting by Market', () => { it('sorting by Market', () => {

View File

@ -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]))
);
};