Commit bd338203 authored by Zack Cuddy's avatar Zack Cuddy Committed by Phil Hughes

Geo Replication - Remove hardcoded data

There was some leftover packageFile
hardcoded properties.

This change replaces them with the
intended variable.

This is required to be generic.
parent b9481f65
...@@ -11,7 +11,6 @@ export default graphQlFieldName => { ...@@ -11,7 +11,6 @@ export default graphQlFieldName => {
} }
nodes { nodes {
id id
packageFileId
state state
retryCount retryCount
lastSyncFailure lastSyncFailure
......
...@@ -55,7 +55,12 @@ export const fetchReplicableItemsGraphQl = ({ state, dispatch }, direction) => { ...@@ -55,7 +55,12 @@ export const fetchReplicableItemsGraphQl = ({ state, dispatch }, direction) => {
variables: { first, last, before, after }, variables: { first, last, before, after },
}) })
.then(res => { .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 data = registries.nodes;
const pagination = { const pagination = {
...registries.pageInfo, ...registries.pageInfo,
......
...@@ -51,18 +51,16 @@ export const MOCK_GRAPHQL_PAGINATION_DATA = { ...@@ -51,18 +51,16 @@ export const MOCK_GRAPHQL_PAGINATION_DATA = {
export const MOCK_BASIC_GRAPHQL_QUERY_RESPONSE = { export const MOCK_BASIC_GRAPHQL_QUERY_RESPONSE = {
geoNode: { geoNode: {
packageFileRegistries: { [MOCK_GRAPHQL_REGISTRY]: {
pageInfo: MOCK_GRAPHQL_PAGINATION_DATA, pageInfo: MOCK_GRAPHQL_PAGINATION_DATA,
nodes: [ nodes: [
{ {
id: 'git/1', id: 'git/1',
packageFileId: '1',
state: 'PENDING', state: 'PENDING',
lastSyncedAt: null, lastSyncedAt: null,
}, },
{ {
id: 'git/2', id: 'git/2',
packageFileId: '2',
state: 'SYNCED', state: 'SYNCED',
lastSyncedAt: null, lastSyncedAt: null,
}, },
......
...@@ -120,6 +120,38 @@ describe('GeoReplicable Store Actions', () => { ...@@ -120,6 +120,38 @@ describe('GeoReplicable Store Actions', () => {
state.graphqlFieldName = MOCK_GRAPHQL_REGISTRY; 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', () => { describe('on success', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(gqClient, 'query').mockResolvedValue({ jest.spyOn(gqClient, 'query').mockResolvedValue({
...@@ -131,7 +163,7 @@ describe('GeoReplicable Store Actions', () => { ...@@ -131,7 +163,7 @@ describe('GeoReplicable Store Actions', () => {
describe('with no direction set', () => { describe('with no direction set', () => {
const direction = null; 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; const data = registries.nodes;
it('should call gqClient with no before/after variables as well as a first variable but no last variable', () => { 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', () => { ...@@ -158,7 +190,7 @@ describe('GeoReplicable Store Actions', () => {
describe('with direction set to "next"', () => { describe('with direction set to "next"', () => {
const direction = 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; 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', () => { 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', () => { ...@@ -190,7 +222,7 @@ describe('GeoReplicable Store Actions', () => {
describe('with direction set to "prev"', () => { describe('with direction set to "prev"', () => {
const direction = 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; 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', () => { 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