diff --git a/test/actions/api/linodes.spec.js b/test/actions/api/linodes.spec.js new file mode 100644 index 00000000000..6e257bf275e --- /dev/null +++ b/test/actions/api/linodes.spec.js @@ -0,0 +1,72 @@ +import sinon from 'sinon'; +import { expect } from 'chai'; +import * as fetch from '~/fetch'; +import { + powerOnLinode, + powerOffLinode, + rebootLinode +} from '../../../src/actions/api/linodes'; +import * as linode_actions from '../../../src/actions/api/linodes'; +import { mock_context } from '../../api-store.spec.js'; + +describe("actions/linodes/power", sinon.test(() => { + it('returns linode power boot status', async () => { + await mock_context(async ({ + auth, dispatch, getState, fetchStub + }) => { + const f = powerOnLinode("foo"); + + await f(dispatch, getState); + + sinon.assert.calledWith(fetchStub, + auth.token, '/linodes/foo/boot', { method: "POST" }); + sinon.assert.calledWith(dispatch, { + type: linode_actions.UPDATE_LINODE, + linode: { id: "foo", state: "booting" } + }); + }, { + type: linode_actions.UPDATE_LINODE, + linode: { id: "foo", state: "booting" } + }); + }); + + it('returns linode power shutdown status', async () => { + await mock_context(async ({ + auth, dispatch, getState, fetchStub + }) => { + const f = powerOffLinode("foo"); + + await f(dispatch, getState); + + sinon.assert.calledWith(fetchStub, + auth.token, '/linodes/foo/shutdown', { method: "POST" }); + sinon.assert.calledWith(dispatch, { + type: linode_actions.UPDATE_LINODE, + linode: { id: "foo", state: "shutting_down" } + }); + }, { + type: linode_actions.UPDATE_LINODE, + linode: { id: "foo", state: "shutting_down" } + }); + }); + + it('returns linode power reboot status', async () => { + await mock_context(async ({ + auth, dispatch, getState, fetchStub + }) => { + const f = rebootLinode("foo"); + + await f(dispatch, getState); + + sinon.assert.calledWith(fetchStub, + auth.token, '/linodes/foo/reboot', { method: "POST" }); + sinon.assert.calledWith(dispatch, { + type: linode_actions.UPDATE_LINODE, + linode: { id: "foo", state: "rebooting" } + }); + }, { + type: linode_actions.UPDATE_LINODE, + linode: { id: "foo", state: "rebooting" } + }); + }); +})); diff --git a/test/api-store.spec.js b/test/api-store.spec.js index 6ce16b56468..a630d87692b 100644 --- a/test/api-store.spec.js +++ b/test/api-store.spec.js @@ -193,7 +193,7 @@ describe("api-store/make_api_list", () => { }); -const mock_context = async (f, rsp, state={}) => { +export const mock_context = async (f, rsp, state={}) => { const auth = { token: 'token' }; let getState = sinon.stub().returns({ authentication: auth,