2020-04-08 14:13:33 +05:30
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2020-04-22 19:07:51 +05:30
|
|
|
import createState from '~/create_cluster/gke_cluster/store/state';
|
|
|
|
import * as types from '~/create_cluster/gke_cluster/store/mutation_types';
|
2019-12-04 20:38:33 +05:30
|
|
|
import * as actions from '~/create_cluster/gke_cluster/store/actions';
|
2020-04-08 14:13:33 +05:30
|
|
|
import gapi from '../helpers';
|
2020-04-22 19:07:51 +05:30
|
|
|
import {
|
|
|
|
selectedProjectMock,
|
|
|
|
selectedZoneMock,
|
|
|
|
selectedMachineTypeMock,
|
|
|
|
gapiProjectsResponseMock,
|
|
|
|
gapiZonesResponseMock,
|
|
|
|
gapiMachineTypesResponseMock,
|
|
|
|
} from '../mock_data';
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
describe('GCP Cluster Dropdown Store Actions', () => {
|
|
|
|
describe('setProject', () => {
|
|
|
|
it('should set project', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setProject,
|
|
|
|
selectedProjectMock,
|
|
|
|
{ selectedProject: {} },
|
|
|
|
[{ type: 'SET_PROJECT', payload: selectedProjectMock }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setZone', () => {
|
|
|
|
it('should set zone', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setZone,
|
|
|
|
selectedZoneMock,
|
|
|
|
{ selectedZone: '' },
|
|
|
|
[{ type: 'SET_ZONE', payload: selectedZoneMock }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setMachineType', () => {
|
|
|
|
it('should set machine type', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setMachineType,
|
|
|
|
selectedMachineTypeMock,
|
|
|
|
{ selectedMachineType: '' },
|
|
|
|
[{ type: 'SET_MACHINE_TYPE', payload: selectedMachineTypeMock }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setIsValidatingProjectBilling', () => {
|
|
|
|
it('should set machine type', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setIsValidatingProjectBilling,
|
|
|
|
true,
|
|
|
|
{ isValidatingProjectBilling: null },
|
|
|
|
[{ type: 'SET_IS_VALIDATING_PROJECT_BILLING', payload: true }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('async fetch methods', () => {
|
2019-12-21 20:55:43 +05:30
|
|
|
let originalGapi;
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
beforeAll(() => {
|
|
|
|
originalGapi = window.gapi;
|
2020-04-08 14:13:33 +05:30
|
|
|
window.gapi = gapi;
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
window.gapi = originalGapi;
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
describe('fetchProjects', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
it('fetches projects from Google API', () => {
|
|
|
|
const state = createState();
|
|
|
|
|
|
|
|
return testAction(
|
|
|
|
actions.fetchProjects,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[{ type: types.SET_PROJECTS, payload: gapiProjectsResponseMock.projects }],
|
|
|
|
[],
|
|
|
|
);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('validateProjectBilling', () => {
|
|
|
|
it('checks project billing status from Google API', done => {
|
|
|
|
testAction(
|
|
|
|
actions.validateProjectBilling,
|
|
|
|
true,
|
|
|
|
{
|
|
|
|
selectedProject: selectedProjectMock,
|
|
|
|
selectedZone: '',
|
|
|
|
selectedMachineType: '',
|
|
|
|
projectHasBillingEnabled: null,
|
|
|
|
},
|
|
|
|
[
|
|
|
|
{ type: 'SET_ZONE', payload: '' },
|
|
|
|
{ type: 'SET_MACHINE_TYPE', payload: '' },
|
|
|
|
{ type: 'SET_PROJECT_BILLING_STATUS', payload: true },
|
|
|
|
],
|
|
|
|
[{ type: 'setIsValidatingProjectBilling', payload: false }],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchZones', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
it('fetches zones from Google API', () => {
|
|
|
|
const state = createState();
|
|
|
|
|
|
|
|
return testAction(
|
|
|
|
actions.fetchZones,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[{ type: types.SET_ZONES, payload: gapiZonesResponseMock.items }],
|
|
|
|
[],
|
|
|
|
);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchMachineTypes', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
it('fetches machine types from Google API', () => {
|
|
|
|
const state = createState();
|
|
|
|
|
|
|
|
return testAction(
|
|
|
|
actions.fetchMachineTypes,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[{ type: types.SET_MACHINE_TYPES, payload: gapiMachineTypesResponseMock.items }],
|
|
|
|
[],
|
|
|
|
);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|