Commit 182e6a1c authored by Phil Hughes's avatar Phil Hughes

Merge branch 'geo-replicable-fix-hard-code' into 'master'

Geo Replication - Remove hardcoded data

Closes #247528

See merge request gitlab-org/gitlab!42255
parents 9bac264b bd338203
......@@ -11,7 +11,6 @@ export default graphQlFieldName => {
}
nodes {
id
packageFileId
state
retryCount
lastSyncFailure
......
......@@ -55,7 +55,12 @@ export const fetchReplicableItemsGraphQl = ({ state, dispatch }, direction) => {
variables: { first, last, before, after },
})
.then(res => {
const registries = res.data.geoNode.packageFileRegistries;
if (!res.data.geoNode || !(state.graphqlFieldName in res.data.geoNode)) {
dispatch('receiveReplicableItemsSuccess', { data: [], pagination: null });
return;
}
const registries = res.data.geoNode[state.graphqlFieldName];
const data = registries.nodes;
const pagination = {
...registries.pageInfo,
......
......@@ -51,18 +51,16 @@ export const MOCK_GRAPHQL_PAGINATION_DATA = {
export const MOCK_BASIC_GRAPHQL_QUERY_RESPONSE = {
geoNode: {
packageFileRegistries: {
[MOCK_GRAPHQL_REGISTRY]: {
pageInfo: MOCK_GRAPHQL_PAGINATION_DATA,
nodes: [
{
id: 'git/1',
packageFileId: '1',
state: 'PENDING',
lastSyncedAt: null,
},
{
id: 'git/2',
packageFileId: '2',
state: 'SYNCED',
lastSyncedAt: null,
},
......
......@@ -120,6 +120,38 @@ describe('GeoReplicable Store Actions', () => {
state.graphqlFieldName = MOCK_GRAPHQL_REGISTRY;
});
describe('on success with no registry data', () => {
beforeEach(() => {
jest.spyOn(gqClient, 'query').mockResolvedValue({
data: {},
});
});
const direction = null;
const data = [];
it('should not error and pass empty values to the mutations', () => {
testAction(
actions.fetchReplicableItemsGraphQl,
direction,
state,
[],
[
{
type: 'receiveReplicableItemsSuccess',
payload: { data, pagination: null },
},
],
() => {
expect(gqClient.query).toHaveBeenCalledWith({
query: buildReplicableTypeQuery(MOCK_GRAPHQL_REGISTRY),
variables: { before: '', after: '', first: DEFAULT_PAGE_SIZE, last: null },
});
},
);
});
});
describe('on success', () => {
beforeEach(() => {
jest.spyOn(gqClient, 'query').mockResolvedValue({
......@@ -131,7 +163,7 @@ describe('GeoReplicable Store Actions', () => {
describe('with no direction set', () => {
const direction = null;
const registries = MOCK_BASIC_GRAPHQL_QUERY_RESPONSE.geoNode?.packageFileRegistries;
const registries = MOCK_BASIC_GRAPHQL_QUERY_RESPONSE.geoNode[MOCK_GRAPHQL_REGISTRY];
const data = registries.nodes;
it('should call gqClient with no before/after variables as well as a first variable but no last variable', () => {
......@@ -158,7 +190,7 @@ describe('GeoReplicable Store Actions', () => {
describe('with direction set to "next"', () => {
const direction = NEXT;
const registries = MOCK_BASIC_GRAPHQL_QUERY_RESPONSE.geoNode?.packageFileRegistries;
const registries = MOCK_BASIC_GRAPHQL_QUERY_RESPONSE.geoNode[MOCK_GRAPHQL_REGISTRY];
const data = registries.nodes;
it('should call gqClient with after variable but no before variable as well as a first variable but no last variable', () => {
......@@ -190,7 +222,7 @@ describe('GeoReplicable Store Actions', () => {
describe('with direction set to "prev"', () => {
const direction = PREV;
const registries = MOCK_BASIC_GRAPHQL_QUERY_RESPONSE.geoNode?.packageFileRegistries;
const registries = MOCK_BASIC_GRAPHQL_QUERY_RESPONSE.geoNode[MOCK_GRAPHQL_REGISTRY];
const data = registries.nodes;
it('should call gqClient with before variable but no after variable as well as a last variable but no first variable', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment