2021-02-22 17:27:13 +05:30
|
|
|
import * as types from '~/import_entities/import_projects/store/mutation_types';
|
|
|
|
import mutations from '~/import_entities/import_projects/store/mutations';
|
|
|
|
import getInitialState from '~/import_entities/import_projects/store/state';
|
|
|
|
import { STATUSES } from '~/import_entities/constants';
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
describe('import_projects store mutations', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
let state;
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
const SOURCE_PROJECT = {
|
|
|
|
id: 1,
|
|
|
|
full_name: 'full/name',
|
|
|
|
sanitized_name: 'name',
|
|
|
|
provider_link: 'https://demo.link/full/name',
|
|
|
|
};
|
|
|
|
const IMPORTED_PROJECT = {
|
|
|
|
name: 'demo',
|
|
|
|
importSource: 'something',
|
|
|
|
providerLink: 'custom-link',
|
|
|
|
importStatus: 'status',
|
|
|
|
fullName: 'fullName',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe(`${types.SET_FILTER}`, () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
const NEW_VALUE = 'new-value';
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = {
|
|
|
|
filter: 'some-value',
|
|
|
|
repositories: ['some', ' repositories'],
|
|
|
|
pageInfo: { page: 1 },
|
|
|
|
};
|
2020-10-24 23:57:45 +05:30
|
|
|
mutations[types.SET_FILTER](state, NEW_VALUE);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('removes current repositories list', () => {
|
|
|
|
expect(state.repositories.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('resets current page to 0', () => {
|
|
|
|
expect(state.pageInfo.page).toBe(0);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.REQUEST_REPOS}`, () => {
|
|
|
|
it('sets repos loading flag to true', () => {
|
|
|
|
state = {};
|
|
|
|
|
|
|
|
mutations[types.REQUEST_REPOS](state);
|
|
|
|
|
|
|
|
expect(state.isLoadingRepos).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.RECEIVE_REPOS_SUCCESS}`, () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('with legacy response format', () => {
|
|
|
|
describe('for imported projects', () => {
|
|
|
|
const response = {
|
|
|
|
importedProjects: [IMPORTED_PROJECT],
|
|
|
|
providerRepos: [],
|
|
|
|
};
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('recreates importSource from response', () => {
|
|
|
|
state = getInitialState();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
mutations[types.RECEIVE_REPOS_SUCCESS](state, response);
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(state.repositories[0].importSource).toStrictEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
fullName: IMPORTED_PROJECT.importSource,
|
|
|
|
sanitizedName: IMPORTED_PROJECT.name,
|
|
|
|
providerLink: IMPORTED_PROJECT.providerLink,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('passes project to importProject', () => {
|
|
|
|
state = getInitialState();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
mutations[types.RECEIVE_REPOS_SUCCESS](state, response);
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(IMPORTED_PROJECT).toStrictEqual(
|
|
|
|
expect.objectContaining(state.repositories[0].importedProject),
|
|
|
|
);
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('for importable projects', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
state = getInitialState();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
const response = {
|
|
|
|
importedProjects: [],
|
|
|
|
providerRepos: [SOURCE_PROJECT],
|
|
|
|
};
|
|
|
|
mutations[types.RECEIVE_REPOS_SUCCESS](state, response);
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('sets importSource to project', () => {
|
|
|
|
expect(state.repositories[0].importSource).toBe(SOURCE_PROJECT);
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('for incompatible projects', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
const response = {
|
|
|
|
importedProjects: [],
|
2020-11-24 15:15:51 +05:30
|
|
|
providerRepos: [],
|
|
|
|
incompatibleRepos: [SOURCE_PROJECT],
|
2020-10-24 23:57:45 +05:30
|
|
|
};
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = getInitialState();
|
|
|
|
mutations[types.RECEIVE_REPOS_SUCCESS](state, response);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets incompatible flag', () => {
|
|
|
|
expect(state.repositories[0].importSource.incompatible).toBe(true);
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('sets importSource to project', () => {
|
|
|
|
expect(state.repositories[0].importSource).toStrictEqual(
|
|
|
|
expect.objectContaining(SOURCE_PROJECT),
|
|
|
|
);
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('sets repos loading flag to false', () => {
|
|
|
|
const response = {
|
|
|
|
importedProjects: [],
|
|
|
|
providerRepos: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
state = getInitialState();
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
mutations[types.RECEIVE_REPOS_SUCCESS](state, response);
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(state.isLoadingRepos).toBe(false);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('passes response as it is', () => {
|
|
|
|
const response = [];
|
|
|
|
state = getInitialState();
|
|
|
|
|
|
|
|
mutations[types.RECEIVE_REPOS_SUCCESS](state, response);
|
|
|
|
|
|
|
|
expect(state.repositories).toStrictEqual(response);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('sets repos loading flag to false', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
const response = [];
|
|
|
|
|
|
|
|
state = getInitialState();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
mutations[types.RECEIVE_REPOS_SUCCESS](state, response);
|
|
|
|
|
|
|
|
expect(state.isLoadingRepos).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.RECEIVE_REPOS_ERROR}`, () => {
|
|
|
|
it('sets repos loading flag to false', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
state = getInitialState();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
mutations[types.RECEIVE_REPOS_ERROR](state);
|
|
|
|
|
|
|
|
expect(state.isLoadingRepos).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.REQUEST_IMPORT}`, () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const REPO_ID = 1;
|
|
|
|
const importTarget = { targetNamespace: 'ns', newName: 'name ' };
|
|
|
|
state = { repositories: [{ importSource: { id: REPO_ID } }] };
|
|
|
|
|
|
|
|
mutations[types.REQUEST_IMPORT](state, { repoId: REPO_ID, importTarget });
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`sets status to ${STATUSES.SCHEDULING}`, () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(state.repositories[0].importedProject.importStatus).toBe(STATUSES.SCHEDULING);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.RECEIVE_IMPORT_SUCCESS}`, () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const REPO_ID = 1;
|
|
|
|
state = { repositories: [{ importSource: { id: REPO_ID } }] };
|
|
|
|
|
|
|
|
mutations[types.RECEIVE_IMPORT_SUCCESS](state, {
|
|
|
|
repoId: REPO_ID,
|
|
|
|
importedProject: IMPORTED_PROJECT,
|
|
|
|
});
|
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('sets import status', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(state.repositories[0].importedProject.importStatus).toBe(
|
|
|
|
IMPORTED_PROJECT.importStatus,
|
|
|
|
);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('sets imported project', () => {
|
|
|
|
expect(IMPORTED_PROJECT).toStrictEqual(
|
|
|
|
expect.objectContaining(state.repositories[0].importedProject),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.RECEIVE_IMPORT_ERROR}`, () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const REPO_ID = 1;
|
|
|
|
state = { repositories: [{ importSource: { id: REPO_ID } }] };
|
|
|
|
|
|
|
|
mutations[types.RECEIVE_IMPORT_ERROR](state, REPO_ID);
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it(`removes importedProject entry`, () => {
|
|
|
|
expect(state.repositories[0].importedProject).toBeNull();
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
describe(`${types.RECEIVE_JOBS_SUCCESS}`, () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
it('updates import status of existing project', () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
const repoId = 1;
|
2020-10-24 23:57:45 +05:30
|
|
|
state = {
|
|
|
|
repositories: [{ importedProject: { id: repoId }, importStatus: STATUSES.STARTED }],
|
|
|
|
};
|
|
|
|
const updatedProjects = [{ id: repoId, importStatus: STATUSES.FINISHED }];
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
mutations[types.RECEIVE_JOBS_SUCCESS](state, updatedProjects);
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(state.repositories[0].importedProject.importStatus).toBe(
|
|
|
|
updatedProjects[0].importStatus,
|
|
|
|
);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.REQUEST_NAMESPACES}`, () => {
|
|
|
|
it('sets namespaces loading flag to true', () => {
|
|
|
|
state = {};
|
|
|
|
|
|
|
|
mutations[types.REQUEST_NAMESPACES](state);
|
|
|
|
|
|
|
|
expect(state.isLoadingNamespaces).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.RECEIVE_NAMESPACES_SUCCESS}`, () => {
|
|
|
|
const response = [{ fullPath: 'some/path' }];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = {};
|
|
|
|
mutations[types.RECEIVE_NAMESPACES_SUCCESS](state, response);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('stores namespaces to state', () => {
|
|
|
|
expect(state.namespaces).toStrictEqual(response);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets namespaces loading flag to false', () => {
|
|
|
|
expect(state.isLoadingNamespaces).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.RECEIVE_NAMESPACES_ERROR}`, () => {
|
|
|
|
it('sets namespaces loading flag to false', () => {
|
|
|
|
state = {};
|
|
|
|
|
|
|
|
mutations[types.RECEIVE_NAMESPACES_ERROR](state);
|
|
|
|
|
|
|
|
expect(state.isLoadingNamespaces).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.SET_IMPORT_TARGET}`, () => {
|
|
|
|
const PROJECT = {
|
|
|
|
id: 2,
|
|
|
|
sanitizedName: 'sanitizedName',
|
|
|
|
};
|
|
|
|
|
|
|
|
it('stores custom target if it differs from defaults', () => {
|
|
|
|
state = { customImportTargets: {}, repositories: [{ importSource: PROJECT }] };
|
|
|
|
const importTarget = { targetNamespace: 'ns', newName: 'name ' };
|
|
|
|
|
|
|
|
mutations[types.SET_IMPORT_TARGET](state, { repoId: PROJECT.id, importTarget });
|
|
|
|
expect(state.customImportTargets[PROJECT.id]).toBe(importTarget);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes custom target if it is equal to defaults', () => {
|
|
|
|
const importTarget = { targetNamespace: 'ns', newName: 'name ' };
|
|
|
|
state = {
|
|
|
|
defaultTargetNamespace: 'default',
|
|
|
|
customImportTargets: {
|
|
|
|
[PROJECT.id]: importTarget,
|
|
|
|
},
|
|
|
|
repositories: [{ importSource: PROJECT }],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations[types.SET_IMPORT_TARGET](state, {
|
|
|
|
repoId: PROJECT.id,
|
|
|
|
importTarget: {
|
|
|
|
targetNamespace: state.defaultTargetNamespace,
|
|
|
|
newName: PROJECT.sanitizedName,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.customImportTargets[SOURCE_PROJECT.id]).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`${types.SET_PAGE}`, () => {
|
|
|
|
it('sets page number', () => {
|
|
|
|
const NEW_PAGE = 4;
|
|
|
|
state = { pageInfo: { page: 5 } };
|
|
|
|
|
|
|
|
mutations[types.SET_PAGE](state, NEW_PAGE);
|
|
|
|
expect(state.pageInfo.page).toBe(NEW_PAGE);
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|