chore: Moves portal slug as ID to query resources in vue store (#5359)

This commit is contained in:
Nithin David Thomas
2022-08-31 19:59:05 +05:30
committed by GitHub
parent d14beeb654
commit ebea5428bc
16 changed files with 121 additions and 148 deletions

View File

@@ -15,16 +15,13 @@ describe('#actions', () => {
await actions.index({
commit,
dispatch,
state: {
selectedPortalId: 4,
},
state: {},
});
expect(dispatch.mock.calls).toMatchObject([['setPortalId', 1]]);
expect(commit.mock.calls).toEqual([
[types.SET_UI_FLAG, { isFetching: true }],
[types.CLEAR_PORTALS],
[types.ADD_MANY_PORTALS_ENTRY, apiResponse.payload],
[types.ADD_MANY_PORTALS_IDS, [1, 2]],
[types.ADD_MANY_PORTALS_IDS, ['domain', 'campaign']],
[types.SET_PORTALS_META, { current_page: 1, portals_count: 1 }],
[types.SET_UI_FLAG, { isFetching: false }],
]);
@@ -43,7 +40,7 @@ describe('#actions', () => {
it('sends correct actions if API is success', async () => {
axios.post.mockResolvedValue({ data: apiResponse.payload[1] });
await actions.create(
{ commit, dispatch, state: { portals: { selectedPortalId: null } } },
{ commit, dispatch, state: { portals: {} } },
{
color: 'red',
custom_domain: 'domain_for_help',
@@ -53,17 +50,14 @@ describe('#actions', () => {
expect(commit.mock.calls).toEqual([
[types.SET_UI_FLAG, { isCreating: true }],
[types.ADD_PORTAL_ENTRY, apiResponse.payload[1]],
[types.ADD_PORTAL_ID, 2],
[types.ADD_PORTAL_ID, 'campaign'],
[types.SET_UI_FLAG, { isCreating: false }],
]);
});
it('sends correct actions if API is error', async () => {
axios.post.mockRejectedValue({ message: 'Incorrect header' });
await expect(
actions.create(
{ commit, dispatch, state: { portals: { selectedPortalId: null } } },
{}
)
actions.create({ commit, dispatch, state: { portals: {} } }, {})
).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[types.SET_UI_FLAG, { isCreating: true }],
@@ -75,32 +69,32 @@ describe('#actions', () => {
describe('#update', () => {
it('sends correct actions if API is success', async () => {
axios.patch.mockResolvedValue({ data: apiResponse.payload[1] });
await actions.update({ commit }, apiResponse.payload[1]);
await actions.update({ commit }, { portalObj: apiResponse.payload[1] });
expect(commit.mock.calls).toEqual([
[
types.SET_HELP_PORTAL_UI_FLAG,
{ uiFlags: { isUpdating: true }, portalId: 2 },
{ uiFlags: { isUpdating: true }, portalSlug: 'campaign' },
],
[types.UPDATE_PORTAL_ENTRY, apiResponse.payload[1]],
[
types.SET_HELP_PORTAL_UI_FLAG,
{ uiFlags: { isUpdating: false }, portalId: 2 },
{ uiFlags: { isUpdating: false }, portalSlug: 'campaign' },
],
]);
});
it('sends correct actions if API is error', async () => {
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
await expect(
actions.update({ commit }, apiResponse.payload[1])
actions.update({ commit }, { portalObj: apiResponse.payload[1] })
).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[
types.SET_HELP_PORTAL_UI_FLAG,
{ uiFlags: { isUpdating: true }, portalId: 2 },
{ uiFlags: { isUpdating: true }, portalSlug: 'campaign' },
],
[
types.SET_HELP_PORTAL_UI_FLAG,
{ uiFlags: { isUpdating: false }, portalId: 2 },
{ uiFlags: { isUpdating: false }, portalSlug: 'campaign' },
],
]);
});
@@ -109,40 +103,35 @@ describe('#actions', () => {
describe('#delete', () => {
it('sends correct actions if API is success', async () => {
axios.delete.mockResolvedValue({});
await actions.delete({ commit }, 2);
await actions.delete({ commit }, { portalSlug: 'campaign' });
expect(commit.mock.calls).toEqual([
[
types.SET_HELP_PORTAL_UI_FLAG,
{ uiFlags: { isDeleting: true }, portalId: 2 },
{ uiFlags: { isDeleting: true }, portalSlug: 'campaign' },
],
[types.REMOVE_PORTAL_ENTRY, 2],
[types.REMOVE_PORTAL_ID, 2],
[types.REMOVE_PORTAL_ENTRY, 'campaign'],
[types.REMOVE_PORTAL_ID, 'campaign'],
[
types.SET_HELP_PORTAL_UI_FLAG,
{ uiFlags: { isDeleting: false }, portalId: 2 },
{ uiFlags: { isDeleting: false }, portalSlug: 'campaign' },
],
]);
});
it('sends correct actions if API is error', async () => {
axios.delete.mockRejectedValue({ message: 'Incorrect header' });
await expect(actions.delete({ commit }, 2)).rejects.toThrow(Error);
await expect(
actions.delete({ commit }, { portalSlug: 'campaign' })
).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[
types.SET_HELP_PORTAL_UI_FLAG,
{ uiFlags: { isDeleting: true }, portalId: 2 },
{ uiFlags: { isDeleting: true }, portalSlug: 'campaign' },
],
[
types.SET_HELP_PORTAL_UI_FLAG,
{ uiFlags: { isDeleting: false }, portalId: 2 },
{ uiFlags: { isDeleting: false }, portalSlug: 'campaign' },
],
]);
});
});
describe('#setPortalId', () => {
it('sends correct actions', async () => {
axios.delete.mockResolvedValue({});
await actions.setPortalId({ commit }, 1);
expect(commit.mock.calls).toEqual([[types.SET_SELECTED_PORTAL_ID, 1]]);
});
});
});

View File

@@ -40,7 +40,6 @@ export default {
1: { isFetching: false, isUpdating: true, isDeleting: false },
},
},
selectedPortalId: 1,
},
uiFlags: {
allFetched: false,

View File

@@ -16,9 +16,9 @@ describe('#getters', () => {
expect(getters.isFetchingPortals(state)).toEqual(true);
});
it('portalById', () => {
it('portalBySlug', () => {
const state = portal;
expect(getters.portalById(state)(1)).toEqual({
expect(getters.portalBySlug(state)(1)).toEqual({
id: 1,
color: 'red',
custom_domain: 'domain_for_help',

View File

@@ -31,13 +31,13 @@ describe('#mutations', () => {
expect(state).toEqual(portal);
});
it('does adds helpcenter object to state', () => {
mutations[types.ADD_PORTAL_ENTRY](state, { id: 3 });
expect(state.portals.byId[3]).toEqual({ id: 3 });
mutations[types.ADD_PORTAL_ENTRY](state, { slug: 'new' });
expect(state.portals.byId.new).toEqual({ slug: 'new' });
});
});
describe('[types.ADD_PORTAL_ID]', () => {
it('adds helpcenter id to state', () => {
it('adds helpcenter slug to state', () => {
mutations[types.ADD_PORTAL_ID](state, 12);
expect(state.portals.allIds).toEqual([1, 2, 12]);
});
@@ -48,13 +48,13 @@ describe('#mutations', () => {
mutations[types.UPDATE_PORTAL_ENTRY](state, {});
expect(state).toEqual(portal);
});
it('does not updates if object id is not present ', () => {
mutations[types.UPDATE_PORTAL_ENTRY](state, { id: 5 });
it('does not updates if object slug is not present ', () => {
mutations[types.UPDATE_PORTAL_ENTRY](state, { slug: 5 });
expect(state).toEqual(portal);
});
it(' updates if object with id already present in the state', () => {
it(' updates if object with slug already present in the state', () => {
mutations[types.UPDATE_PORTAL_ENTRY](state, {
id: 2,
slug: 2,
name: 'Updated name',
});
expect(state.portals.byId[2].name).toEqual('Updated name');
@@ -62,7 +62,7 @@ describe('#mutations', () => {
});
describe('[types.REMOVE_PORTAL_ENTRY]', () => {
it('does not remove object entry if no id is passed', () => {
it('does not remove object entry if no slug is passed', () => {
mutations[types.REMOVE_PORTAL_ENTRY](state, undefined);
expect(state).toEqual({ ...portal });
});
@@ -73,7 +73,7 @@ describe('#mutations', () => {
});
describe('[types.REMOVE_PORTAL_ID]', () => {
it('removes id from state', () => {
it('removes slug from state', () => {
mutations[types.REMOVE_PORTAL_ID](state, 2);
expect(state.portals.allIds).toEqual([1, 12]);
});
@@ -82,12 +82,12 @@ describe('#mutations', () => {
describe('[types.SET_HELP_PORTAL_UI_FLAG]', () => {
it('sets correct flag in state', () => {
mutations[types.SET_HELP_PORTAL_UI_FLAG](state, {
portalId: 1,
portalSlug: 'domain',
uiFlags: { isFetching: true },
});
expect(state.portals.uiFlags.byId[1]).toEqual({
expect(state.portals.uiFlags.byId.domain).toEqual({
isFetching: true,
isUpdating: true,
isUpdating: false,
isDeleting: false,
});
});
@@ -99,9 +99,7 @@ describe('#mutations', () => {
expect(state.portals.allIds).toEqual([]);
expect(state.portals.byId).toEqual({});
expect(state.portals.uiFlags).toEqual({
byId: {
'1': { isFetching: true, isUpdating: true, isDeleting: false },
},
byId: {},
});
});
});
@@ -118,11 +116,4 @@ describe('#mutations', () => {
});
});
});
describe('#SET_SELECTED_PORTAL_ID', () => {
it('set selected portal id', () => {
mutations[types.SET_SELECTED_PORTAL_ID](state, 4);
expect(state.portals.selectedPortalId).toEqual(4);
});
});
});