2021-01-03 14:25:43 +05:30
|
|
|
import { getJSONFixture } from 'helpers/fixtures';
|
2021-06-08 01:23:25 +05:30
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2021-04-29 21:17:54 +05:30
|
|
|
import * as types from '~/releases/stores/modules/index/mutation_types';
|
|
|
|
import mutations from '~/releases/stores/modules/index/mutations';
|
|
|
|
import createState from '~/releases/stores/modules/index/state';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { convertAllReleasesGraphQLResponse } from '~/releases/util';
|
|
|
|
|
|
|
|
const originalRelease = getJSONFixture('api/releases/release.json');
|
|
|
|
const originalReleases = [originalRelease];
|
|
|
|
|
|
|
|
const graphqlReleasesResponse = getJSONFixture(
|
2021-06-08 01:23:25 +05:30
|
|
|
'graphql/releases/graphql/queries/all_releases.query.graphql.json',
|
2021-01-03 14:25:43 +05:30
|
|
|
);
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
describe('Releases Store Mutations', () => {
|
|
|
|
let stateCopy;
|
2021-06-08 01:23:25 +05:30
|
|
|
let pageInfo;
|
2021-01-03 14:25:43 +05:30
|
|
|
let releases;
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-11-24 15:15:51 +05:30
|
|
|
stateCopy = createState({});
|
2021-06-08 01:23:25 +05:30
|
|
|
pageInfo = convertAllReleasesGraphQLResponse(graphqlReleasesResponse).paginationInfo;
|
2021-01-03 14:25:43 +05:30
|
|
|
releases = convertObjectPropsToCamelCase(originalReleases, { deep: true });
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('REQUEST_RELEASES', () => {
|
|
|
|
it('sets isLoading to true', () => {
|
|
|
|
mutations[types.REQUEST_RELEASES](stateCopy);
|
|
|
|
|
|
|
|
expect(stateCopy.isLoading).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('RECEIVE_RELEASES_SUCCESS', () => {
|
|
|
|
beforeEach(() => {
|
2021-01-03 14:25:43 +05:30
|
|
|
mutations[types.RECEIVE_RELEASES_SUCCESS](stateCopy, {
|
2021-06-08 01:23:25 +05:30
|
|
|
pageInfo,
|
2021-01-03 14:25:43 +05:30
|
|
|
data: releases,
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('sets is loading to false', () => {
|
|
|
|
expect(stateCopy.isLoading).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets hasError to false', () => {
|
|
|
|
expect(stateCopy.hasError).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets data', () => {
|
|
|
|
expect(stateCopy.releases).toEqual(releases);
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('sets pageInfo', () => {
|
|
|
|
expect(stateCopy.pageInfo).toEqual(pageInfo);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('RECEIVE_RELEASES_ERROR', () => {
|
|
|
|
it('resets data', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
mutations[types.RECEIVE_RELEASES_SUCCESS](stateCopy, {
|
2021-06-08 01:23:25 +05:30
|
|
|
pageInfo,
|
2021-01-03 14:25:43 +05:30
|
|
|
data: releases,
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
mutations[types.RECEIVE_RELEASES_ERROR](stateCopy);
|
|
|
|
|
|
|
|
expect(stateCopy.isLoading).toEqual(false);
|
|
|
|
expect(stateCopy.releases).toEqual([]);
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(stateCopy.pageInfo).toEqual({});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
describe('SET_SORTING', () => {
|
|
|
|
it('should merge the sorting object with sort value', () => {
|
|
|
|
mutations[types.SET_SORTING](stateCopy, { sort: 'asc' });
|
|
|
|
expect(stateCopy.sorting).toEqual({ ...stateCopy.sorting, sort: 'asc' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should merge the sorting object with order_by value', () => {
|
|
|
|
mutations[types.SET_SORTING](stateCopy, { orderBy: 'created_at' });
|
|
|
|
expect(stateCopy.sorting).toEqual({ ...stateCopy.sorting, orderBy: 'created_at' });
|
|
|
|
});
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|