-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a pool and attach machines to it.
- Loading branch information
Showing
10 changed files
with
238 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { call } from "redux-saga/effects"; | ||
|
||
import { | ||
machine as machineActions, | ||
resourcepool as resourcePoolActions, | ||
} from "app/base/actions"; | ||
|
||
/** | ||
* Generate functions that will use the response to create the dispatchable | ||
* action to set the pool for each machine. | ||
* @param {Array} machines - A list of machine ids. | ||
* @returns {Array} The list of action creator functions. | ||
*/ | ||
export const generateActionCreators = (machines) => | ||
machines.map((machineID) => (result) => | ||
machineActions.setPool(machineID, result.id) | ||
); | ||
|
||
/** | ||
* Handle creating a pool and then attaching machines to that pool. | ||
* @param {Object} socketClient - The websocket client instance. | ||
* @param {Function} sendMessage - The saga that handles sending websocket messages. | ||
* @param {Object} action - The redux action with pool and machine data. | ||
*/ | ||
export function* createPoolWithMachines( | ||
socketClient, | ||
sendMessage, | ||
{ payload } | ||
) { | ||
const { machines, pool } = payload.params; | ||
const actionCreators = yield call(generateActionCreators, machines); | ||
// Send the initial action via the websocket. | ||
yield call( | ||
sendMessage, | ||
socketClient, | ||
resourcePoolActions.create(pool), | ||
actionCreators | ||
); | ||
} | ||
|
||
// Sagas to be handled by the websocket channel. | ||
export default [ | ||
{ | ||
action: "CREATE_RESOURCEPOOL_WITH_MACHINES", | ||
method: createPoolWithMachines, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { expectSaga } from "redux-saga-test-plan"; | ||
import * as matchers from "redux-saga-test-plan/matchers"; | ||
|
||
import { createPoolWithMachines, generateActionCreators } from "./actions"; | ||
|
||
jest.mock("../../../websocket-client"); | ||
|
||
describe("websocket sagas", () => { | ||
it("can send a message to create a pool then attach machines", () => { | ||
const socketClient = jest.fn(); | ||
const sendMessage = jest.fn(); | ||
const actionCreators = [jest.fn()]; | ||
const pool = { name: "pool1", description: "a pool" }; | ||
const action = { payload: { params: { machines: ["machine1"], pool } } }; | ||
return expectSaga(createPoolWithMachines, socketClient, sendMessage, action) | ||
.provide([[matchers.call.fn(generateActionCreators), actionCreators]]) | ||
.call( | ||
sendMessage, | ||
socketClient, | ||
{ | ||
type: "CREATE_RESOURCEPOOL", | ||
payload: { | ||
params: pool, | ||
}, | ||
meta: { | ||
model: "resourcepool", | ||
method: "create", | ||
}, | ||
}, | ||
actionCreators | ||
) | ||
.run(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.