Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/import_entities/import_groups/graphql/services')
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js55
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/services/status_poller_spec.js21
2 files changed, 59 insertions, 17 deletions
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 ca987ab3ab4..5baa201906a 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,11 +1,17 @@
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 { SourceGroupsManager } from '~/import_entities/import_groups/graphql/services/source_groups_manager';
+import {
+ KEY,
+ SourceGroupsManager,
+} from '~/import_entities/import_groups/graphql/services/source_groups_manager';
+
+const FAKE_SOURCE_URL = 'http://demo.host';
describe('SourceGroupsManager', () => {
let manager;
let client;
+ let storage;
const getFakeGroup = () => ({
__typename: clientTypenames.BulkImportSourceGroup,
@@ -17,8 +23,53 @@ describe('SourceGroupsManager', () => {
readFragment: jest.fn(),
writeFragment: jest.fn(),
};
+ storage = {
+ getItem: jest.fn(),
+ setItem: jest.fn(),
+ };
+
+ manager = new SourceGroupsManager({ client, storage, sourceUrl: FAKE_SOURCE_URL });
+ });
+
+ describe('storage management', () => {
+ const IMPORT_ID = 1;
+ const IMPORT_TARGET = { destination_name: 'demo', destination_namespace: 'foo' };
+ const STATUS = 'FAKE_STATUS';
+ const FAKE_GROUP = { id: 1, import_target: IMPORT_TARGET, status: STATUS };
+
+ it('loads state from storage on creation', () => {
+ expect(storage.getItem).toHaveBeenCalledWith(KEY);
+ });
+
+ it('saves to storage when import is starting', () => {
+ manager.startImport({
+ importId: IMPORT_ID,
+ group: 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,
+ });
+ });
- manager = new SourceGroupsManager({ client });
+ it('saves to storage when import status is updated', () => {
+ const CHANGED_STATUS = 'changed';
+
+ manager.startImport({
+ importId: IMPORT_ID,
+ group: FAKE_GROUP,
+ });
+
+ manager.setImportStatusByImportId(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,
+ });
+ });
});
it('finds item by group id', () => {
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 a5fc4e18a02..0d4809971ae 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
@@ -2,7 +2,6 @@ import MockAdapter from 'axios-mock-adapter';
import Visibility from 'visibilityjs';
import createFlash from '~/flash';
import { STATUSES } from '~/import_entities/constants';
-import { SourceGroupsManager } from '~/import_entities/import_groups/graphql/services/source_groups_manager';
import { StatusPoller } from '~/import_entities/import_groups/graphql/services/status_poller';
import axios from '~/lib/utils/axios_utils';
import Poll from '~/lib/utils/poll';
@@ -18,24 +17,21 @@ jest.mock('~/import_entities/import_groups/graphql/services/source_groups_manage
}));
const FAKE_POLL_PATH = '/fake/poll/path';
-const CLIENT_MOCK = {};
describe('Bulk import status poller', () => {
let poller;
let mockAdapter;
+ let groupManager;
const getPollHistory = () => mockAdapter.history.get.filter((x) => x.url === FAKE_POLL_PATH);
beforeEach(() => {
mockAdapter = new MockAdapter(axios);
mockAdapter.onGet(FAKE_POLL_PATH).reply(200, {});
- poller = new StatusPoller({ client: CLIENT_MOCK, pollPath: FAKE_POLL_PATH });
- });
-
- it('creates source group manager with proper client', () => {
- expect(SourceGroupsManager.mock.calls).toHaveLength(1);
- const [[{ client }]] = SourceGroupsManager.mock.calls;
- expect(client).toBe(CLIENT_MOCK);
+ groupManager = {
+ setImportStatusByImportId: jest.fn(),
+ };
+ poller = new StatusPoller({ groupManager, pollPath: FAKE_POLL_PATH });
});
it('creates poller with proper config', () => {
@@ -100,14 +96,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 [managerInstance] = SourceGroupsManager.mock.instances;
- managerInstance.findByImportId.mockReturnValue({ id: FAKE_ID });
pollConfig.successCallback({ data: [{ id: FAKE_ID, status_name: STATUSES.FINISHED }] });
- expect(managerInstance.setImportStatus).toHaveBeenCalledWith(
- expect.objectContaining({ id: FAKE_ID }),
- STATUSES.FINISHED,
- );
+ expect(groupManager.setImportStatusByImportId).toHaveBeenCalledWith(FAKE_ID, STATUSES.FINISHED);
});
});