debian-mirror-gitlab/spec/frontend/packages/details/store/actions_spec.js

105 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import testAction from 'helpers/vuex_action_helper';
import Api from '~/api';
import { deprecatedCreateFlash as createFlash } from '~/flash';
2021-03-11 19:13:27 +05:30
import { FETCH_PACKAGE_VERSIONS_ERROR } from '~/packages/details/constants';
2020-11-24 15:15:51 +05:30
import { fetchPackageVersions, deletePackage } from '~/packages/details/store/actions';
2020-10-24 23:57:45 +05:30
import * as types from '~/packages/details/store/mutation_types';
2020-11-24 15:15:51 +05:30
import { DELETE_PACKAGE_ERROR_MESSAGE } from '~/packages/shared/constants';
2020-10-24 23:57:45 +05:30
import { npmPackage as packageEntity } from '../../mock_data';
jest.mock('~/flash.js');
jest.mock('~/api.js');
describe('Actions Package details store', () => {
describe('fetchPackageVersions', () => {
2021-03-08 18:12:59 +05:30
it('should fetch the package versions', (done) => {
2020-10-24 23:57:45 +05:30
Api.projectPackage = jest.fn().mockResolvedValue({ data: packageEntity });
testAction(
fetchPackageVersions,
undefined,
{ packageEntity },
[
{ type: types.SET_LOADING, payload: true },
{ type: types.SET_PACKAGE_VERSIONS, payload: packageEntity.versions },
{ type: types.SET_LOADING, payload: false },
],
[],
() => {
expect(Api.projectPackage).toHaveBeenCalledWith(
packageEntity.project_id,
packageEntity.id,
);
done();
},
);
});
2021-03-08 18:12:59 +05:30
it("does not set the versions if they don't exist", (done) => {
2020-10-24 23:57:45 +05:30
Api.projectPackage = jest.fn().mockResolvedValue({ data: { packageEntity, versions: null } });
testAction(
fetchPackageVersions,
undefined,
{ packageEntity },
2021-03-08 18:12:59 +05:30
[
{ type: types.SET_LOADING, payload: true },
{ type: types.SET_LOADING, payload: false },
],
2020-10-24 23:57:45 +05:30
[],
() => {
expect(Api.projectPackage).toHaveBeenCalledWith(
packageEntity.project_id,
packageEntity.id,
);
done();
},
);
});
2021-03-08 18:12:59 +05:30
it('should create flash on API error', (done) => {
2020-10-24 23:57:45 +05:30
Api.projectPackage = jest.fn().mockRejectedValue();
testAction(
fetchPackageVersions,
undefined,
{ packageEntity },
2021-03-08 18:12:59 +05:30
[
{ type: types.SET_LOADING, payload: true },
{ type: types.SET_LOADING, payload: false },
],
2020-10-24 23:57:45 +05:30
[],
() => {
expect(Api.projectPackage).toHaveBeenCalledWith(
packageEntity.project_id,
packageEntity.id,
);
expect(createFlash).toHaveBeenCalledWith(FETCH_PACKAGE_VERSIONS_ERROR);
done();
},
);
});
});
2020-11-24 15:15:51 +05:30
describe('deletePackage', () => {
2021-03-08 18:12:59 +05:30
it('should call Api.deleteProjectPackage', (done) => {
2020-11-24 15:15:51 +05:30
Api.deleteProjectPackage = jest.fn().mockResolvedValue();
testAction(deletePackage, undefined, { packageEntity }, [], [], () => {
expect(Api.deleteProjectPackage).toHaveBeenCalledWith(
packageEntity.project_id,
packageEntity.id,
);
done();
});
});
2021-03-08 18:12:59 +05:30
it('should create flash on API error', (done) => {
2020-11-24 15:15:51 +05:30
Api.deleteProjectPackage = jest.fn().mockRejectedValue();
testAction(deletePackage, undefined, { packageEntity }, [], [], () => {
expect(createFlash).toHaveBeenCalledWith(DELETE_PACKAGE_ERROR_MESSAGE);
done();
});
});
});
2020-10-24 23:57:45 +05:30
});