summaryrefslogtreecommitdiff
path: root/spec/frontend/import_entities
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/import_entities')
-rw-r--r--spec/frontend/import_entities/import_groups/components/import_table_row_spec.js19
-rw-r--r--spec/frontend/import_entities/import_groups/components/import_table_spec.js69
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/client_factory_spec.js231
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/fixtures.js6
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js109
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/services/status_poller_spec.js14
6 files changed, 291 insertions, 157 deletions
diff --git a/spec/frontend/import_entities/import_groups/components/import_table_row_spec.js b/spec/frontend/import_entities/import_groups/components/import_table_row_spec.js
index 7a83136e785..0c69cfb3bc5 100644
--- a/spec/frontend/import_entities/import_groups/components/import_table_row_spec.js
+++ b/spec/frontend/import_entities/import_groups/components/import_table_row_spec.js
@@ -19,7 +19,8 @@ const getFakeGroup = (status) => ({
new_name: 'group1',
},
id: 1,
- status,
+ validation_errors: [],
+ progress: { status },
});
const EXISTING_GROUP_TARGET_NAMESPACE = 'existing-group';
@@ -187,21 +188,25 @@ describe('import table row', () => {
expect(wrapper.text()).toContain('Please choose a group URL with no special characters.');
});
- it('Reports invalid group name if group already exists', async () => {
+ it('Reports invalid group name if relevant validation error exists', async () => {
+ const FAKE_ERROR_MESSAGE = 'fake error';
+
createComponent({
group: {
...getFakeGroup(STATUSES.NONE),
- import_target: {
- target_namespace: EXISTING_GROUP_TARGET_NAMESPACE,
- new_name: EXISTING_GROUP_PATH,
- },
+ validation_errors: [
+ {
+ field: 'new_name',
+ message: FAKE_ERROR_MESSAGE,
+ },
+ ],
},
});
jest.runOnlyPendingTimers();
await nextTick();
- expect(wrapper.text()).toContain('Name already exists.');
+ expect(wrapper.text()).toContain(FAKE_ERROR_MESSAGE);
});
});
});
diff --git a/spec/frontend/import_entities/import_groups/components/import_table_spec.js b/spec/frontend/import_entities/import_groups/components/import_table_spec.js
index 496c5cda7c7..99ef6d9a7fb 100644
--- a/spec/frontend/import_entities/import_groups/components/import_table_spec.js
+++ b/spec/frontend/import_entities/import_groups/components/import_table_spec.js
@@ -1,4 +1,5 @@
import {
+ GlButton,
GlEmptyState,
GlLoadingIcon,
GlSearchBoxByClick,
@@ -14,7 +15,7 @@ import waitForPromises from 'helpers/wait_for_promises';
import { STATUSES } from '~/import_entities/constants';
import ImportTable from '~/import_entities/import_groups/components/import_table.vue';
import ImportTableRow from '~/import_entities/import_groups/components/import_table_row.vue';
-import importGroupMutation from '~/import_entities/import_groups/graphql/mutations/import_group.mutation.graphql';
+import importGroupsMutation from '~/import_entities/import_groups/graphql/mutations/import_groups.mutation.graphql';
import setNewNameMutation from '~/import_entities/import_groups/graphql/mutations/set_new_name.mutation.graphql';
import setTargetNamespaceMutation from '~/import_entities/import_groups/graphql/mutations/set_target_namespace.mutation.graphql';
import PaginationLinks from '~/vue_shared/components/pagination_links.vue';
@@ -40,6 +41,7 @@ describe('import table', () => {
];
const FAKE_PAGE_INFO = { page: 1, perPage: 20, total: 40, totalPages: 2 };
+ const findImportAllButton = () => wrapper.find('h1').find(GlButton);
const findPaginationDropdown = () => wrapper.findComponent(GlDropdown);
const findPaginationDropdownText = () => findPaginationDropdown().find({ ref: 'text' }).text();
@@ -72,7 +74,6 @@ describe('import table', () => {
afterEach(() => {
wrapper.destroy();
- wrapper = null;
});
it('renders loading icon while performing request', async () => {
@@ -141,7 +142,7 @@ describe('import table', () => {
event | payload | mutation | variables
${'update-target-namespace'} | ${'new-namespace'} | ${setTargetNamespaceMutation} | ${{ sourceGroupId: FAKE_GROUP.id, targetNamespace: 'new-namespace' }}
${'update-new-name'} | ${'new-name'} | ${setNewNameMutation} | ${{ sourceGroupId: FAKE_GROUP.id, newName: 'new-name' }}
- ${'import-group'} | ${undefined} | ${importGroupMutation} | ${{ sourceGroupId: FAKE_GROUP.id }}
+ ${'import-group'} | ${undefined} | ${importGroupsMutation} | ${{ sourceGroupIds: [FAKE_GROUP.id] }}
`('correctly maps $event to mutation', async ({ event, payload, mutation, variables }) => {
jest.spyOn(apolloProvider.defaultClient, 'mutate');
wrapper.find(ImportTableRow).vm.$emit(event, payload);
@@ -277,4 +278,66 @@ describe('import table', () => {
);
});
});
+
+ describe('import all button', () => {
+ it('does not exists when no groups available', () => {
+ createComponent({
+ bulkImportSourceGroups: () => new Promise(() => {}),
+ });
+
+ expect(findImportAllButton().exists()).toBe(false);
+ });
+
+ it('exists when groups are available for import', async () => {
+ createComponent({
+ bulkImportSourceGroups: () => ({
+ nodes: FAKE_GROUPS,
+ pageInfo: FAKE_PAGE_INFO,
+ }),
+ });
+ await waitForPromises();
+
+ expect(findImportAllButton().exists()).toBe(true);
+ });
+
+ it('counts only not-imported groups', async () => {
+ const NEW_GROUPS = [
+ generateFakeEntry({ id: 1, status: STATUSES.NONE }),
+ generateFakeEntry({ id: 2, status: STATUSES.NONE }),
+ generateFakeEntry({ id: 3, status: STATUSES.FINISHED }),
+ ];
+
+ createComponent({
+ bulkImportSourceGroups: () => ({
+ nodes: NEW_GROUPS,
+ pageInfo: FAKE_PAGE_INFO,
+ }),
+ });
+ await waitForPromises();
+
+ expect(findImportAllButton().text()).toMatchInterpolatedText('Import 2 groups');
+ });
+
+ it('disables button when any group has validation errors', async () => {
+ const NEW_GROUPS = [
+ generateFakeEntry({ id: 1, status: STATUSES.NONE }),
+ generateFakeEntry({
+ id: 2,
+ status: STATUSES.NONE,
+ validation_errors: [{ field: 'new_name', message: 'test validation error' }],
+ }),
+ generateFakeEntry({ id: 3, status: STATUSES.FINISHED }),
+ ];
+
+ createComponent({
+ bulkImportSourceGroups: () => ({
+ nodes: NEW_GROUPS,
+ pageInfo: FAKE_PAGE_INFO,
+ }),
+ });
+ await waitForPromises();
+
+ expect(findImportAllButton().props().disabled).toBe(true);
+ });
+ });
});
diff --git a/spec/frontend/import_entities/import_groups/graphql/client_factory_spec.js b/spec/frontend/import_entities/import_groups/graphql/client_factory_spec.js
index 1feff861c1e..ef83c9ebbc4 100644
--- a/spec/frontend/import_entities/import_groups/graphql/client_factory_spec.js
+++ b/spec/frontend/import_entities/import_groups/graphql/client_factory_spec.js
@@ -8,10 +8,15 @@ import {
clientTypenames,
createResolvers,
} from '~/import_entities/import_groups/graphql/client_factory';
-import importGroupMutation from '~/import_entities/import_groups/graphql/mutations/import_group.mutation.graphql';
+import addValidationErrorMutation from '~/import_entities/import_groups/graphql/mutations/add_validation_error.mutation.graphql';
+import importGroupsMutation from '~/import_entities/import_groups/graphql/mutations/import_groups.mutation.graphql';
+import removeValidationErrorMutation from '~/import_entities/import_groups/graphql/mutations/remove_validation_error.mutation.graphql';
+import setImportProgressMutation from '~/import_entities/import_groups/graphql/mutations/set_import_progress.mutation.graphql';
import setNewNameMutation from '~/import_entities/import_groups/graphql/mutations/set_new_name.mutation.graphql';
import setTargetNamespaceMutation from '~/import_entities/import_groups/graphql/mutations/set_target_namespace.mutation.graphql';
+import updateImportStatusMutation from '~/import_entities/import_groups/graphql/mutations/update_import_status.mutation.graphql';
import availableNamespacesQuery from '~/import_entities/import_groups/graphql/queries/available_namespaces.query.graphql';
+import bulkImportSourceGroupQuery from '~/import_entities/import_groups/graphql/queries/bulk_import_source_group.query.graphql';
import bulkImportSourceGroupsQuery from '~/import_entities/import_groups/graphql/queries/bulk_import_source_groups.query.graphql';
import { StatusPoller } from '~/import_entities/import_groups/graphql/services/status_poller';
@@ -78,6 +83,31 @@ describe('Bulk import resolvers', () => {
});
});
+ describe('bulkImportSourceGroup', () => {
+ beforeEach(async () => {
+ axiosMockAdapter.onGet(FAKE_ENDPOINTS.status).reply(httpStatus.OK, statusEndpointFixture);
+ axiosMockAdapter
+ .onGet(FAKE_ENDPOINTS.availableNamespaces)
+ .reply(httpStatus.OK, availableNamespacesFixture);
+
+ return client.query({
+ query: bulkImportSourceGroupsQuery,
+ });
+ });
+
+ it('returns group', async () => {
+ const { id } = statusEndpointFixture.importable_data[0];
+ const {
+ data: { bulkImportSourceGroup: group },
+ } = await client.query({
+ query: bulkImportSourceGroupQuery,
+ variables: { id: id.toString() },
+ });
+
+ expect(group).toMatchObject(statusEndpointFixture.importable_data[0]);
+ });
+ });
+
describe('bulkImportSourceGroups', () => {
let results;
@@ -89,8 +119,12 @@ describe('Bulk import resolvers', () => {
});
it('respects cached import state when provided by group manager', async () => {
+ const FAKE_JOB_ID = '1';
const FAKE_STATUS = 'DEMO_STATUS';
- const FAKE_IMPORT_TARGET = {};
+ const FAKE_IMPORT_TARGET = {
+ new_name: 'test-name',
+ target_namespace: 'test-namespace',
+ };
const TARGET_INDEX = 0;
const clientWithMockedManager = createClient({
@@ -98,8 +132,11 @@ describe('Bulk import resolvers', () => {
getImportStateFromStorageByGroupId(groupId) {
if (groupId === statusEndpointFixture.importable_data[TARGET_INDEX].id) {
return {
- status: FAKE_STATUS,
- importTarget: FAKE_IMPORT_TARGET,
+ jobId: FAKE_JOB_ID,
+ importState: {
+ status: FAKE_STATUS,
+ importTarget: FAKE_IMPORT_TARGET,
+ },
};
}
@@ -113,8 +150,8 @@ describe('Bulk import resolvers', () => {
});
const clientResults = clientResponse.data.bulkImportSourceGroups.nodes;
- expect(clientResults[TARGET_INDEX].import_target).toBe(FAKE_IMPORT_TARGET);
- expect(clientResults[TARGET_INDEX].status).toBe(FAKE_STATUS);
+ expect(clientResults[TARGET_INDEX].import_target).toStrictEqual(FAKE_IMPORT_TARGET);
+ expect(clientResults[TARGET_INDEX].progress.status).toBe(FAKE_STATUS);
});
it('populates each result instance with empty import_target when there are no available namespaces', async () => {
@@ -143,8 +180,8 @@ describe('Bulk import resolvers', () => {
).toBe(true);
});
- it('populates each result instance with status field default to none', () => {
- expect(results.every((r) => r.status === STATUSES.NONE)).toBe(true);
+ it('populates each result instance with status default to none', () => {
+ expect(results.every((r) => r.progress.status === STATUSES.NONE)).toBe(true);
});
it('populates each result instance with import_target defaulted to first available namespace', () => {
@@ -183,7 +220,6 @@ describe('Bulk import resolvers', () => {
});
describe('mutations', () => {
- let results;
const GROUP_ID = 1;
beforeEach(() => {
@@ -195,7 +231,10 @@ describe('Bulk import resolvers', () => {
{
__typename: clientTypenames.BulkImportSourceGroup,
id: GROUP_ID,
- status: STATUSES.NONE,
+ progress: {
+ id: `test-${GROUP_ID}`,
+ status: STATUSES.NONE,
+ },
web_url: 'https://fake.host/1',
full_path: 'fake_group_1',
full_name: 'fake_name_1',
@@ -203,6 +242,7 @@ describe('Bulk import resolvers', () => {
target_namespace: 'root',
new_name: 'group1',
},
+ validation_errors: [],
},
],
pageInfo: {
@@ -214,35 +254,42 @@ describe('Bulk import resolvers', () => {
},
},
});
-
- client
- .watchQuery({
- query: bulkImportSourceGroupsQuery,
- fetchPolicy: 'cache-only',
- })
- .subscribe(({ data }) => {
- results = data.bulkImportSourceGroups.nodes;
- });
});
it('setTargetNamespaces updates group target namespace', async () => {
const NEW_TARGET_NAMESPACE = 'target';
- await client.mutate({
+ const {
+ data: {
+ setTargetNamespace: {
+ id: idInResponse,
+ import_target: { target_namespace: namespaceInResponse },
+ },
+ },
+ } = await client.mutate({
mutation: setTargetNamespaceMutation,
variables: { sourceGroupId: GROUP_ID, targetNamespace: NEW_TARGET_NAMESPACE },
});
- expect(results[0].import_target.target_namespace).toBe(NEW_TARGET_NAMESPACE);
+ expect(idInResponse).toBe(GROUP_ID);
+ expect(namespaceInResponse).toBe(NEW_TARGET_NAMESPACE);
});
it('setNewName updates group target name', async () => {
const NEW_NAME = 'new';
- await client.mutate({
+ const {
+ data: {
+ setNewName: {
+ id: idInResponse,
+ import_target: { new_name: nameInResponse },
+ },
+ },
+ } = await client.mutate({
mutation: setNewNameMutation,
variables: { sourceGroupId: GROUP_ID, newName: NEW_NAME },
});
- expect(results[0].import_target.new_name).toBe(NEW_NAME);
+ expect(idInResponse).toBe(GROUP_ID);
+ expect(nameInResponse).toBe(NEW_NAME);
});
describe('importGroup', () => {
@@ -250,8 +297,8 @@ describe('Bulk import resolvers', () => {
axiosMockAdapter.onPost(FAKE_ENDPOINTS.createBulkImport).reply(() => new Promise(() => {}));
client.mutate({
- mutation: importGroupMutation,
- variables: { sourceGroupId: GROUP_ID },
+ mutation: importGroupsMutation,
+ variables: { sourceGroupIds: [GROUP_ID] },
});
await waitForPromises();
@@ -261,33 +308,49 @@ describe('Bulk import resolvers', () => {
query: bulkImportSourceGroupsQuery,
});
- expect(intermediateResults[0].status).toBe(STATUSES.SCHEDULING);
+ expect(intermediateResults[0].progress.status).toBe(STATUSES.SCHEDULING);
});
- it('sets import status to CREATED when request completes', async () => {
- axiosMockAdapter.onPost(FAKE_ENDPOINTS.createBulkImport).reply(httpStatus.OK, { id: 1 });
- await client.mutate({
- mutation: importGroupMutation,
- variables: { sourceGroupId: GROUP_ID },
+ describe('when request completes', () => {
+ let results;
+
+ beforeEach(() => {
+ client
+ .watchQuery({
+ query: bulkImportSourceGroupsQuery,
+ fetchPolicy: 'cache-only',
+ })
+ .subscribe(({ data }) => {
+ results = data.bulkImportSourceGroups.nodes;
+ });
});
- expect(results[0].status).toBe(STATUSES.CREATED);
- });
+ it('sets import status to CREATED when request completes', async () => {
+ axiosMockAdapter.onPost(FAKE_ENDPOINTS.createBulkImport).reply(httpStatus.OK, { id: 1 });
+ await client.mutate({
+ mutation: importGroupsMutation,
+ variables: { sourceGroupIds: [GROUP_ID] },
+ });
+ await waitForPromises();
- it('resets status to NONE if request fails', async () => {
- axiosMockAdapter
- .onPost(FAKE_ENDPOINTS.createBulkImport)
- .reply(httpStatus.INTERNAL_SERVER_ERROR);
+ expect(results[0].progress.status).toBe(STATUSES.CREATED);
+ });
- client
- .mutate({
- mutation: importGroupMutation,
- variables: { sourceGroupId: GROUP_ID },
- })
- .catch(() => {});
- await waitForPromises();
+ it('resets status to NONE if request fails', async () => {
+ axiosMockAdapter
+ .onPost(FAKE_ENDPOINTS.createBulkImport)
+ .reply(httpStatus.INTERNAL_SERVER_ERROR);
+
+ client
+ .mutate({
+ mutation: [importGroupsMutation],
+ variables: { sourceGroupIds: [GROUP_ID] },
+ })
+ .catch(() => {});
+ await waitForPromises();
- expect(results[0].status).toBe(STATUSES.NONE);
+ expect(results[0].progress.status).toBe(STATUSES.NONE);
+ });
});
it('shows default error message when server error is not provided', async () => {
@@ -297,8 +360,8 @@ describe('Bulk import resolvers', () => {
client
.mutate({
- mutation: importGroupMutation,
- variables: { sourceGroupId: GROUP_ID },
+ mutation: importGroupsMutation,
+ variables: { sourceGroupIds: [GROUP_ID] },
})
.catch(() => {});
await waitForPromises();
@@ -315,8 +378,8 @@ describe('Bulk import resolvers', () => {
client
.mutate({
- mutation: importGroupMutation,
- variables: { sourceGroupId: GROUP_ID },
+ mutation: importGroupsMutation,
+ variables: { sourceGroupIds: [GROUP_ID] },
})
.catch(() => {});
await waitForPromises();
@@ -324,5 +387,75 @@ describe('Bulk import resolvers', () => {
expect(createFlash).toHaveBeenCalledWith({ message: CUSTOM_MESSAGE });
});
});
+
+ it('setImportProgress updates group progress', async () => {
+ const NEW_STATUS = 'dummy';
+ const FAKE_JOB_ID = 5;
+ const {
+ data: {
+ setImportProgress: { progress },
+ },
+ } = await client.mutate({
+ mutation: setImportProgressMutation,
+ variables: { sourceGroupId: GROUP_ID, status: NEW_STATUS, jobId: FAKE_JOB_ID },
+ });
+
+ expect(progress).toMatchObject({
+ id: FAKE_JOB_ID,
+ status: NEW_STATUS,
+ });
+ });
+
+ it('updateImportStatus returns new status', async () => {
+ const NEW_STATUS = 'dummy';
+ const FAKE_JOB_ID = 5;
+ const {
+ data: { updateImportStatus: statusInResponse },
+ } = await client.mutate({
+ mutation: updateImportStatusMutation,
+ variables: { id: FAKE_JOB_ID, status: NEW_STATUS },
+ });
+
+ expect(statusInResponse).toMatchObject({
+ id: FAKE_JOB_ID,
+ status: NEW_STATUS,
+ });
+ });
+
+ it('addValidationError adds error to group', async () => {
+ const FAKE_FIELD = 'some-field';
+ const FAKE_MESSAGE = 'some-message';
+ const {
+ data: {
+ addValidationError: { validation_errors: validationErrors },
+ },
+ } = await client.mutate({
+ mutation: addValidationErrorMutation,
+ variables: { sourceGroupId: GROUP_ID, field: FAKE_FIELD, message: FAKE_MESSAGE },
+ });
+
+ expect(validationErrors).toMatchObject([{ field: FAKE_FIELD, message: FAKE_MESSAGE }]);
+ });
+
+ it('removeValidationError removes error from group', async () => {
+ const FAKE_FIELD = 'some-field';
+ const FAKE_MESSAGE = 'some-message';
+
+ await client.mutate({
+ mutation: addValidationErrorMutation,
+ variables: { sourceGroupId: GROUP_ID, field: FAKE_FIELD, message: FAKE_MESSAGE },
+ });
+
+ const {
+ data: {
+ removeValidationError: { validation_errors: validationErrors },
+ },
+ } = await client.mutate({
+ mutation: removeValidationErrorMutation,
+ variables: { sourceGroupId: GROUP_ID, field: FAKE_FIELD },
+ });
+
+ expect(validationErrors).toMatchObject([]);
+ });
});
});
diff --git a/spec/frontend/import_entities/import_groups/graphql/fixtures.js b/spec/frontend/import_entities/import_groups/graphql/fixtures.js
index 62e9581bd2d..6f66066b312 100644
--- a/spec/frontend/import_entities/import_groups/graphql/fixtures.js
+++ b/spec/frontend/import_entities/import_groups/graphql/fixtures.js
@@ -10,7 +10,11 @@ export const generateFakeEntry = ({ id, status, ...rest }) => ({
new_name: `group${id}`,
},
id,
- status,
+ progress: {
+ id: `test-${id}`,
+ status,
+ },
+ validation_errors: [],
...rest,
});
diff --git a/spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js b/spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js
index 5baa201906a..bae715edac0 100644
--- a/spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js
+++ b/spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js
@@ -1,6 +1,3 @@
-import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
-import { clientTypenames } from '~/import_entities/import_groups/graphql/client_factory';
-import ImportSourceGroupFragment from '~/import_entities/import_groups/graphql/fragments/bulk_import_source_group_item.fragment.graphql';
import {
KEY,
SourceGroupsManager,
@@ -10,25 +7,15 @@ const FAKE_SOURCE_URL = 'http://demo.host';
describe('SourceGroupsManager', () => {
let manager;
- let client;
let storage;
- const getFakeGroup = () => ({
- __typename: clientTypenames.BulkImportSourceGroup,
- id: 5,
- });
-
beforeEach(() => {
- client = {
- readFragment: jest.fn(),
- writeFragment: jest.fn(),
- };
storage = {
getItem: jest.fn(),
setItem: jest.fn(),
};
- manager = new SourceGroupsManager({ client, storage, sourceUrl: FAKE_SOURCE_URL });
+ manager = new SourceGroupsManager({ storage, sourceUrl: FAKE_SOURCE_URL });
});
describe('storage management', () => {
@@ -41,93 +28,37 @@ describe('SourceGroupsManager', () => {
expect(storage.getItem).toHaveBeenCalledWith(KEY);
});
- it('saves to storage when import is starting', () => {
- manager.startImport({
- importId: IMPORT_ID,
- group: FAKE_GROUP,
- });
+ it('saves to storage when createImportState is called', () => {
+ const FAKE_STATUS = 'fake;';
+ manager.createImportState(IMPORT_ID, { status: FAKE_STATUS, groups: [FAKE_GROUP] });
const storedObject = JSON.parse(storage.setItem.mock.calls[0][1]);
expect(Object.values(storedObject)[0]).toStrictEqual({
- id: FAKE_GROUP.id,
- importTarget: IMPORT_TARGET,
- status: STATUS,
+ status: FAKE_STATUS,
+ groups: [
+ {
+ id: FAKE_GROUP.id,
+ importTarget: IMPORT_TARGET,
+ },
+ ],
});
});
- it('saves to storage when import status is updated', () => {
+ it('updates storage when previous state is available', () => {
const CHANGED_STATUS = 'changed';
- manager.startImport({
- importId: IMPORT_ID,
- group: FAKE_GROUP,
- });
+ manager.createImportState(IMPORT_ID, { status: STATUS, groups: [FAKE_GROUP] });
- manager.setImportStatusByImportId(IMPORT_ID, CHANGED_STATUS);
+ manager.updateImportProgress(IMPORT_ID, CHANGED_STATUS);
const storedObject = JSON.parse(storage.setItem.mock.calls[1][1]);
expect(Object.values(storedObject)[0]).toStrictEqual({
- id: FAKE_GROUP.id,
- importTarget: IMPORT_TARGET,
status: CHANGED_STATUS,
+ groups: [
+ {
+ id: FAKE_GROUP.id,
+ importTarget: IMPORT_TARGET,
+ },
+ ],
});
});
});
-
- it('finds item by group id', () => {
- const ID = 5;
-
- const FAKE_GROUP = getFakeGroup();
- client.readFragment.mockReturnValue(FAKE_GROUP);
- const group = manager.findById(ID);
- expect(group).toBe(FAKE_GROUP);
- expect(client.readFragment).toHaveBeenCalledWith({
- fragment: ImportSourceGroupFragment,
- id: defaultDataIdFromObject(getFakeGroup()),
- });
- });
-
- it('updates group with provided function', () => {
- const UPDATED_GROUP = {};
- const fn = jest.fn().mockReturnValue(UPDATED_GROUP);
- manager.update(getFakeGroup(), fn);
-
- expect(client.writeFragment).toHaveBeenCalledWith({
- fragment: ImportSourceGroupFragment,
- id: defaultDataIdFromObject(getFakeGroup()),
- data: UPDATED_GROUP,
- });
- });
-
- it('updates group by id with provided function', () => {
- const UPDATED_GROUP = {};
- const fn = jest.fn().mockReturnValue(UPDATED_GROUP);
- client.readFragment.mockReturnValue(getFakeGroup());
- manager.updateById(getFakeGroup().id, fn);
-
- expect(client.readFragment).toHaveBeenCalledWith({
- fragment: ImportSourceGroupFragment,
- id: defaultDataIdFromObject(getFakeGroup()),
- });
-
- expect(client.writeFragment).toHaveBeenCalledWith({
- fragment: ImportSourceGroupFragment,
- id: defaultDataIdFromObject(getFakeGroup()),
- data: UPDATED_GROUP,
- });
- });
-
- it('sets import status when group is provided', () => {
- client.readFragment.mockReturnValue(getFakeGroup());
-
- const NEW_STATUS = 'NEW_STATUS';
- manager.setImportStatus(getFakeGroup(), NEW_STATUS);
-
- expect(client.writeFragment).toHaveBeenCalledWith({
- fragment: ImportSourceGroupFragment,
- id: defaultDataIdFromObject(getFakeGroup()),
- data: {
- ...getFakeGroup(),
- status: NEW_STATUS,
- },
- });
- });
});
diff --git a/spec/frontend/import_entities/import_groups/graphql/services/status_poller_spec.js b/spec/frontend/import_entities/import_groups/graphql/services/status_poller_spec.js
index 0d4809971ae..9c47647c430 100644
--- a/spec/frontend/import_entities/import_groups/graphql/services/status_poller_spec.js
+++ b/spec/frontend/import_entities/import_groups/graphql/services/status_poller_spec.js
@@ -21,17 +21,15 @@ const FAKE_POLL_PATH = '/fake/poll/path';
describe('Bulk import status poller', () => {
let poller;
let mockAdapter;
- let groupManager;
+ let updateImportStatus;
const getPollHistory = () => mockAdapter.history.get.filter((x) => x.url === FAKE_POLL_PATH);
beforeEach(() => {
mockAdapter = new MockAdapter(axios);
mockAdapter.onGet(FAKE_POLL_PATH).reply(200, {});
- groupManager = {
- setImportStatusByImportId: jest.fn(),
- };
- poller = new StatusPoller({ groupManager, pollPath: FAKE_POLL_PATH });
+ updateImportStatus = jest.fn();
+ poller = new StatusPoller({ updateImportStatus, pollPath: FAKE_POLL_PATH });
});
it('creates poller with proper config', () => {
@@ -96,9 +94,9 @@ describe('Bulk import status poller', () => {
it('when success response arrives updates relevant group status', () => {
const FAKE_ID = 5;
const [[pollConfig]] = Poll.mock.calls;
+ const FAKE_RESPONSE = { id: FAKE_ID, status_name: STATUSES.FINISHED };
+ pollConfig.successCallback({ data: [FAKE_RESPONSE] });
- pollConfig.successCallback({ data: [{ id: FAKE_ID, status_name: STATUSES.FINISHED }] });
-
- expect(groupManager.setImportStatusByImportId).toHaveBeenCalledWith(FAKE_ID, STATUSES.FINISHED);
+ expect(updateImportStatus).toHaveBeenCalledWith(FAKE_RESPONSE);
});
});