2019-07-31 22:56:46 +05:30
|
|
|
import {
|
|
|
|
APPLICATION_STATUS,
|
|
|
|
UNINSTALL_EVENT,
|
|
|
|
UPDATE_EVENT,
|
|
|
|
INSTALL_EVENT,
|
|
|
|
} from '~/clusters/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import transitionApplicationState from '~/clusters/services/application_state_machine';
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
const {
|
|
|
|
NO_STATUS,
|
|
|
|
SCHEDULED,
|
|
|
|
NOT_INSTALLABLE,
|
|
|
|
INSTALLABLE,
|
|
|
|
INSTALLING,
|
|
|
|
INSTALLED,
|
|
|
|
ERROR,
|
|
|
|
UPDATING,
|
|
|
|
UPDATED,
|
|
|
|
UPDATE_ERRORED,
|
|
|
|
UNINSTALLING,
|
|
|
|
UNINSTALL_ERRORED,
|
2020-10-24 23:57:45 +05:30
|
|
|
UNINSTALLED,
|
2019-07-31 22:56:46 +05:30
|
|
|
} = APPLICATION_STATUS;
|
|
|
|
|
|
|
|
const NO_EFFECTS = 'no effects';
|
|
|
|
|
|
|
|
describe('applicationStateMachine', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
const noEffectsToEmptyObject = (effects) => (typeof effects === 'string' ? {} : effects);
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
describe(`current state is ${NO_STATUS}`, () => {
|
|
|
|
it.each`
|
|
|
|
expectedState | event | effects
|
|
|
|
${INSTALLING} | ${SCHEDULED} | ${NO_EFFECTS}
|
|
|
|
${NOT_INSTALLABLE} | ${NOT_INSTALLABLE} | ${NO_EFFECTS}
|
|
|
|
${INSTALLABLE} | ${INSTALLABLE} | ${NO_EFFECTS}
|
|
|
|
${INSTALLING} | ${INSTALLING} | ${NO_EFFECTS}
|
|
|
|
${INSTALLED} | ${INSTALLED} | ${NO_EFFECTS}
|
|
|
|
${INSTALLABLE} | ${ERROR} | ${{ installFailed: true }}
|
|
|
|
${UPDATING} | ${UPDATING} | ${NO_EFFECTS}
|
|
|
|
${INSTALLED} | ${UPDATED} | ${NO_EFFECTS}
|
|
|
|
${INSTALLED} | ${UPDATE_ERRORED} | ${{ updateFailed: true }}
|
|
|
|
${UNINSTALLING} | ${UNINSTALLING} | ${NO_EFFECTS}
|
|
|
|
${INSTALLED} | ${UNINSTALL_ERRORED} | ${{ uninstallFailed: true }}
|
2020-10-24 23:57:45 +05:30
|
|
|
${UNINSTALLED} | ${UNINSTALLED} | ${NO_EFFECTS}
|
2021-03-08 18:12:59 +05:30
|
|
|
`(`transitions to $expectedState on $event event and applies $effects`, (data) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const { expectedState, event, effects } = data;
|
|
|
|
const currentAppState = {
|
|
|
|
status: NO_STATUS,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(transitionApplicationState(currentAppState, event)).toEqual({
|
|
|
|
status: expectedState,
|
|
|
|
...noEffectsToEmptyObject(effects),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`current state is ${NOT_INSTALLABLE}`, () => {
|
|
|
|
it.each`
|
|
|
|
expectedState | event | effects
|
|
|
|
${INSTALLABLE} | ${INSTALLABLE} | ${NO_EFFECTS}
|
2021-03-08 18:12:59 +05:30
|
|
|
`(`transitions to $expectedState on $event event and applies $effects`, (data) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const { expectedState, event, effects } = data;
|
|
|
|
const currentAppState = {
|
|
|
|
status: NOT_INSTALLABLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(transitionApplicationState(currentAppState, event)).toEqual({
|
|
|
|
status: expectedState,
|
|
|
|
...noEffectsToEmptyObject(effects),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`current state is ${INSTALLABLE}`, () => {
|
|
|
|
it.each`
|
2019-09-30 21:07:59 +05:30
|
|
|
expectedState | event | effects
|
|
|
|
${INSTALLING} | ${INSTALL_EVENT} | ${{ installFailed: false }}
|
2020-10-24 23:57:45 +05:30
|
|
|
${INSTALLED} | ${INSTALLED} | ${{ installFailed: false }}
|
2019-09-30 21:07:59 +05:30
|
|
|
${NOT_INSTALLABLE} | ${NOT_INSTALLABLE} | ${NO_EFFECTS}
|
2020-10-24 23:57:45 +05:30
|
|
|
${UNINSTALLED} | ${UNINSTALLED} | ${{ installFailed: false }}
|
2021-03-08 18:12:59 +05:30
|
|
|
`(`transitions to $expectedState on $event event and applies $effects`, (data) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const { expectedState, event, effects } = data;
|
|
|
|
const currentAppState = {
|
|
|
|
status: INSTALLABLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(transitionApplicationState(currentAppState, event)).toEqual({
|
|
|
|
status: expectedState,
|
|
|
|
...noEffectsToEmptyObject(effects),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`current state is ${INSTALLING}`, () => {
|
|
|
|
it.each`
|
|
|
|
expectedState | event | effects
|
|
|
|
${INSTALLED} | ${INSTALLED} | ${NO_EFFECTS}
|
|
|
|
${INSTALLABLE} | ${ERROR} | ${{ installFailed: true }}
|
2021-03-08 18:12:59 +05:30
|
|
|
`(`transitions to $expectedState on $event event and applies $effects`, (data) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const { expectedState, event, effects } = data;
|
|
|
|
const currentAppState = {
|
|
|
|
status: INSTALLING,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(transitionApplicationState(currentAppState, event)).toEqual({
|
|
|
|
status: expectedState,
|
|
|
|
...noEffectsToEmptyObject(effects),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`current state is ${INSTALLED}`, () => {
|
|
|
|
it.each`
|
2019-09-30 21:07:59 +05:30
|
|
|
expectedState | event | effects
|
|
|
|
${UPDATING} | ${UPDATE_EVENT} | ${{ updateFailed: false, updateSuccessful: false }}
|
|
|
|
${UNINSTALLING} | ${UNINSTALL_EVENT} | ${{ uninstallFailed: false, uninstallSuccessful: false }}
|
|
|
|
${NOT_INSTALLABLE} | ${NOT_INSTALLABLE} | ${NO_EFFECTS}
|
2020-10-24 23:57:45 +05:30
|
|
|
${UNINSTALLED} | ${UNINSTALLED} | ${NO_EFFECTS}
|
|
|
|
${INSTALLABLE} | ${ERROR} | ${{ installFailed: true }}
|
2021-03-08 18:12:59 +05:30
|
|
|
`(`transitions to $expectedState on $event event and applies $effects`, (data) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const { expectedState, event, effects } = data;
|
|
|
|
const currentAppState = {
|
|
|
|
status: INSTALLED,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(transitionApplicationState(currentAppState, event)).toEqual({
|
|
|
|
status: expectedState,
|
2019-09-30 21:07:59 +05:30
|
|
|
...noEffectsToEmptyObject(effects),
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`current state is ${UPDATING}`, () => {
|
|
|
|
it.each`
|
|
|
|
expectedState | event | effects
|
2019-09-04 21:01:54 +05:30
|
|
|
${INSTALLED} | ${UPDATED} | ${{ updateSuccessful: true }}
|
2019-07-31 22:56:46 +05:30
|
|
|
${INSTALLED} | ${UPDATE_ERRORED} | ${{ updateFailed: true }}
|
2021-03-08 18:12:59 +05:30
|
|
|
`(`transitions to $expectedState on $event event and applies $effects`, (data) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const { expectedState, event, effects } = data;
|
|
|
|
const currentAppState = {
|
|
|
|
status: UPDATING,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(transitionApplicationState(currentAppState, event)).toEqual({
|
|
|
|
status: expectedState,
|
|
|
|
...effects,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`current state is ${UNINSTALLING}`, () => {
|
|
|
|
it.each`
|
|
|
|
expectedState | event | effects
|
|
|
|
${INSTALLABLE} | ${INSTALLABLE} | ${{ uninstallSuccessful: true }}
|
|
|
|
${INSTALLED} | ${UNINSTALL_ERRORED} | ${{ uninstallFailed: true }}
|
2021-03-08 18:12:59 +05:30
|
|
|
`(`transitions to $expectedState on $event event and applies $effects`, (data) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const { expectedState, event, effects } = data;
|
|
|
|
const currentAppState = {
|
|
|
|
status: UNINSTALLING,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(transitionApplicationState(currentAppState, event)).toEqual({
|
|
|
|
status: expectedState,
|
|
|
|
...effects,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe(`current state is ${UNINSTALLED}`, () => {
|
|
|
|
it.each`
|
|
|
|
expectedState | event | effects
|
|
|
|
${INSTALLED} | ${INSTALLED} | ${NO_EFFECTS}
|
|
|
|
${INSTALLABLE} | ${ERROR} | ${{ installFailed: true }}
|
2021-03-08 18:12:59 +05:30
|
|
|
`(`transitions to $expectedState on $event event and applies $effects`, (data) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
const { expectedState, event, effects } = data;
|
|
|
|
const currentAppState = {
|
|
|
|
status: UNINSTALLED,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(transitionApplicationState(currentAppState, event)).toEqual({
|
|
|
|
status: expectedState,
|
|
|
|
...noEffectsToEmptyObject(effects),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
describe('current state is undefined', () => {
|
|
|
|
it('returns the current state without having any effects', () => {
|
|
|
|
const currentAppState = {};
|
|
|
|
expect(transitionApplicationState(currentAppState, INSTALLABLE)).toEqual(currentAppState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with event is undefined', () => {
|
|
|
|
it('returns the current state without having any effects', () => {
|
|
|
|
const currentAppState = {
|
|
|
|
status: NO_STATUS,
|
|
|
|
};
|
|
|
|
expect(transitionApplicationState(currentAppState, undefined)).toEqual(currentAppState);
|
|
|
|
});
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|