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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-30 15:12:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-30 15:12:30 +0300
commit6d19e491d1257b6fbc74f4cf3a30ddb28deaeaf4 (patch)
treee14c505a5e880c85161d8c5b17b23341b6c37a21 /spec/frontend/import_entities
parentea0085de54590ffde24fee2ced286961a419410d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/import_entities')
-rw-r--r--spec/frontend/import_entities/import_groups/components/import_table_row_spec.js2
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/client_factory_spec.js178
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/fixtures.js5
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js92
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/services/status_poller_spec.js14
5 files changed, 154 insertions, 137 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..3080d7ebdb8 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,7 @@ const getFakeGroup = (status) => ({
new_name: 'group1',
},
id: 1,
- status,
+ progress: { status },
});
const EXISTING_GROUP_TARGET_NAMESPACE = 'existing-group';
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..0d0679c74e5 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
@@ -9,9 +9,12 @@ import {
createResolvers,
} from '~/import_entities/import_groups/graphql/client_factory';
import importGroupMutation from '~/import_entities/import_groups/graphql/mutations/import_group.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 +81,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 +117,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 +130,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 +148,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 +178,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 +218,6 @@ describe('Bulk import resolvers', () => {
});
describe('mutations', () => {
- let results;
const GROUP_ID = 1;
beforeEach(() => {
@@ -195,7 +229,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',
@@ -214,35 +251,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', () => {
@@ -261,33 +305,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('resets status to NONE if request fails', async () => {
- axiosMockAdapter
- .onPost(FAKE_ENDPOINTS.createBulkImport)
- .reply(httpStatus.INTERNAL_SERVER_ERROR);
-
- client
- .mutate({
+ 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 },
- })
- .catch(() => {});
- await waitForPromises();
+ });
+ await waitForPromises();
+
+ expect(results[0].progress.status).toBe(STATUSES.CREATED);
+ });
+
+ it('resets status to NONE if request fails', async () => {
+ axiosMockAdapter
+ .onPost(FAKE_ENDPOINTS.createBulkImport)
+ .reply(httpStatus.INTERNAL_SERVER_ERROR);
- expect(results[0].status).toBe(STATUSES.NONE);
+ client
+ .mutate({
+ mutation: importGroupMutation,
+ variables: { sourceGroupId: GROUP_ID },
+ })
+ .catch(() => {});
+ await waitForPromises();
+
+ expect(results[0].progress.status).toBe(STATUSES.NONE);
+ });
});
it('shows default error message when server error is not provided', async () => {
@@ -324,5 +384,39 @@ 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,
+ });
+ });
});
});
diff --git a/spec/frontend/import_entities/import_groups/graphql/fixtures.js b/spec/frontend/import_entities/import_groups/graphql/fixtures.js
index 62e9581bd2d..b046e04fa28 100644
--- a/spec/frontend/import_entities/import_groups/graphql/fixtures.js
+++ b/spec/frontend/import_entities/import_groups/graphql/fixtures.js
@@ -10,7 +10,10 @@ export const generateFakeEntry = ({ id, status, ...rest }) => ({
new_name: `group${id}`,
},
id,
- status,
+ progress: {
+ id: `test-${id}`,
+ status,
+ },
...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..e9c214b8d3b 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,42 +7,29 @@ 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', () => {
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 };
+ const FAKE_GROUP = { id: 1, importTarget: 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,
- });
+ it('saves to storage when saveImportState is called', () => {
+ manager.saveImportState(IMPORT_ID, FAKE_GROUP);
const storedObject = JSON.parse(storage.setItem.mock.calls[0][1]);
expect(Object.values(storedObject)[0]).toStrictEqual({
id: FAKE_GROUP.id,
@@ -54,15 +38,12 @@ describe('SourceGroupsManager', () => {
});
});
- 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.saveImportState(IMPORT_ID, FAKE_GROUP);
- manager.setImportStatusByImportId(IMPORT_ID, CHANGED_STATUS);
+ manager.saveImportState(IMPORT_ID, { status: CHANGED_STATUS });
const storedObject = JSON.parse(storage.setItem.mock.calls[1][1]);
expect(Object.values(storedObject)[0]).toStrictEqual({
id: FAKE_GROUP.id,
@@ -71,63 +52,4 @@ describe('SourceGroupsManager', () => {
});
});
});
-
- 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);
});
});