Commit 2b903ece authored by Dennis Tang's avatar Dennis Tang

rename vuex actions as per best practices

parent 3acc649d
...@@ -47,7 +47,7 @@ export default { ...@@ -47,7 +47,7 @@ export default {
selectedZone() { selectedZone() {
this.isLoading = true; this.isLoading = true;
this.getMachineTypes() this.fetchMachineTypes()
.then(this.fetchSuccessHandler) .then(this.fetchSuccessHandler)
.catch(this.fetchFailureHandler); .catch(this.fetchFailureHandler);
}, },
...@@ -56,7 +56,7 @@ export default { ...@@ -56,7 +56,7 @@ export default {
}, },
}, },
methods: { methods: {
...mapActions(['getMachineTypes']), ...mapActions(['fetchMachineTypes']),
...mapActions({ setItem: 'setMachineType' }), ...mapActions({ setItem: 'setMachineType' }),
enableSubmit() { enableSubmit() {
if (this.allDropdownsSelected) { if (this.allDropdownsSelected) {
......
...@@ -76,12 +76,12 @@ export default { ...@@ -76,12 +76,12 @@ export default {
created() { created() {
this.isLoading = true; this.isLoading = true;
this.getProjects() this.fetchProjects()
.then(this.fetchSuccessHandler) .then(this.fetchSuccessHandler)
.catch(this.fetchFailureHandler); .catch(this.fetchFailureHandler);
}, },
methods: { methods: {
...mapActions(['getProjects']), ...mapActions(['fetchProjects']),
...mapActions({ setItem: 'setProject' }), ...mapActions({ setItem: 'setProject' }),
fetchSuccessHandler() { fetchSuccessHandler() {
if (this.defaultValue) { if (this.defaultValue) {
......
...@@ -38,13 +38,13 @@ export default { ...@@ -38,13 +38,13 @@ export default {
selectedProject() { selectedProject() {
this.isLoading = true; this.isLoading = true;
this.getZones() this.fetchZones()
.then(this.fetchSuccessHandler) .then(this.fetchSuccessHandler)
.catch(this.fetchFailureHandler); .catch(this.fetchFailureHandler);
}, },
}, },
methods: { methods: {
...mapActions(['getZones']), ...mapActions(['fetchZones']),
...mapActions({ setItem: 'setZone' }), ...mapActions({ setItem: 'setZone' }),
}, },
}; };
......
/* global gapi */ /* global gapi */
import * as types from './mutation_types'; import * as types from './mutation_types';
export const setProject = ({ commit }, selectedProject) => {
commit(types.SET_PROJECT, selectedProject);
};
export const setZone = ({ commit }, selectedZone) => {
commit(types.SET_ZONE, selectedZone);
};
export const setMachineType = ({ commit }, selectedMachineType) => {
commit(types.SET_MACHINE_TYPE, selectedMachineType);
};
const gapiRequest = ({ service, params, commit, mutation, payloadKey }) => const gapiRequest = ({ service, params, commit, mutation, payloadKey }) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const request = service.list(params); const request = service.list(params);
...@@ -31,7 +19,19 @@ const gapiRequest = ({ service, params, commit, mutation, payloadKey }) => ...@@ -31,7 +19,19 @@ const gapiRequest = ({ service, params, commit, mutation, payloadKey }) =>
); );
}); });
export const getProjects = ({ commit }) => export const setProject = ({ commit }, selectedProject) => {
commit(types.SET_PROJECT, selectedProject);
};
export const setZone = ({ commit }, selectedZone) => {
commit(types.SET_ZONE, selectedZone);
};
export const setMachineType = ({ commit }, selectedMachineType) => {
commit(types.SET_MACHINE_TYPE, selectedMachineType);
};
export const fetchProjects = ({ commit }) =>
gapiRequest({ gapiRequest({
service: gapi.client.cloudresourcemanager.projects, service: gapi.client.cloudresourcemanager.projects,
params: {}, params: {},
...@@ -40,7 +40,7 @@ export const getProjects = ({ commit }) => ...@@ -40,7 +40,7 @@ export const getProjects = ({ commit }) =>
payloadKey: 'projects', payloadKey: 'projects',
}); });
export const getZones = ({ commit, state }) => export const fetchZones = ({ commit, state }) =>
gapiRequest({ gapiRequest({
service: gapi.client.compute.zones, service: gapi.client.compute.zones,
params: { params: {
...@@ -51,7 +51,7 @@ export const getZones = ({ commit, state }) => ...@@ -51,7 +51,7 @@ export const getZones = ({ commit, state }) =>
payloadKey: 'items', payloadKey: 'items',
}); });
export const getMachineTypes = ({ commit, state }) => export const fetchMachineTypes = ({ commit, state }) =>
gapiRequest({ gapiRequest({
service: gapi.client.compute.machineTypes, service: gapi.client.compute.machineTypes,
params: { params: {
......
...@@ -51,10 +51,10 @@ describe('GCP Cluster Dropdown Store Actions', () => { ...@@ -51,10 +51,10 @@ describe('GCP Cluster Dropdown Store Actions', () => {
describe('async fetch methods', () => { describe('async fetch methods', () => {
window.gapi = gapi(); window.gapi = gapi();
describe('getProjects', () => { describe('fetchProjects', () => {
it('fetches projects from Google API', done => { it('fetches projects from Google API', done => {
store store
.dispatch('getProjects') .dispatch('fetchProjects')
.then(() => { .then(() => {
expect(store.state.projects[0].projectId).toEqual(selectedProjectMock.projectId); expect(store.state.projects[0].projectId).toEqual(selectedProjectMock.projectId);
expect(store.state.projects[0].name).toEqual(selectedProjectMock.name); expect(store.state.projects[0].name).toEqual(selectedProjectMock.name);
...@@ -65,10 +65,10 @@ describe('GCP Cluster Dropdown Store Actions', () => { ...@@ -65,10 +65,10 @@ describe('GCP Cluster Dropdown Store Actions', () => {
}); });
}); });
describe('getZones', () => { describe('fetchZones', () => {
it('fetches zones from Google API', done => { it('fetches zones from Google API', done => {
store store
.dispatch('getZones') .dispatch('fetchZones')
.then(() => { .then(() => {
expect(store.state.zones[0].name).toEqual(selectedZoneMock); expect(store.state.zones[0].name).toEqual(selectedZoneMock);
...@@ -78,10 +78,10 @@ describe('GCP Cluster Dropdown Store Actions', () => { ...@@ -78,10 +78,10 @@ describe('GCP Cluster Dropdown Store Actions', () => {
}); });
}); });
describe('getMachineTypes', () => { describe('fetchMachineTypes', () => {
it('fetches machine types from Google API', done => { it('fetches machine types from Google API', done => {
store store
.dispatch('getMachineTypes') .dispatch('fetchMachineTypes')
.then(() => { .then(() => {
expect(store.state.machineTypes[0].name).toEqual(selectedMachineTypeMock); expect(store.state.machineTypes[0].name).toEqual(selectedMachineTypeMock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment