Skip to content

Commit e1d6a06

Browse files
committed
Test action creator for alert
1 parent e4d955a commit e1d6a06

13 files changed

Lines changed: 109 additions & 42 deletions

.DS_Store

0 Bytes
Binary file not shown.

client/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
"html-webpack-plugin": "^3.2.0",
5656
"jest": "^24.8.0",
5757
"mini-css-extract-plugin": "^0.7.0",
58+
"mocha": "^6.2.0",
59+
"nock": "^10.0.6",
5860
"node-sass": "^4.12.0",
5961
"path": "^0.12.7",
6062
"redux-mock-store": "^1.5.3",

client/src/_actions/user.actions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export const userActions = {
1818
function login(username, password) {
1919
return dispatch => {
2020
dispatch(request({ username }));
21-
2221
userService.login(username, password).then(user => {
2322
if (user.success) {
2423
dispatch(success(user));

client/tests/alert.action.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as actions from "../src/_actions/alert.actions";
2+
import * as constants from "../src/_constants/alert.constants";
3+
4+
describe("alert actions", () => {
5+
it("should create an action to alert success", () => {
6+
const message = "success message";
7+
const expectedAction = {
8+
type: constants.alertConstants.SUCCESS,
9+
message
10+
};
11+
expect(actions.alertActions.success(message)).toEqual(expectedAction);
12+
});
13+
14+
it("should create an action to alert failure", () => {
15+
const message = "failure message";
16+
const expectedAction = {
17+
type: constants.alertConstants.ERROR,
18+
message
19+
};
20+
expect(actions.alertActions.error(message)).toEqual(expectedAction);
21+
});
22+
23+
it("should create an action to alert clear", () => {
24+
const expectedAction = {
25+
type: constants.alertConstants.CLEAR
26+
};
27+
expect(actions.alertActions.clear()).toEqual(expectedAction);
28+
});
29+
});

client/tests/user.action.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import configureMockStore from "redux-mock-store";
2+
import thunk from "redux-thunk";
3+
import * as actions from "../src/_actions/user.actions";
4+
import * as types from "../src/_constants/user.constants";
5+
import fetchMock from "fetch-mock";
6+
import expect from "expect"; // You can use any testing library
7+
import fetch from "isomorphic-fetch";
8+
9+
const middlewares = [thunk];
10+
const mockStore = configureMockStore(middlewares);
11+
12+
describe("async actions", () => {
13+
afterEach(() => {
14+
fetchMock.restore();
15+
});
16+
17+
it("creates LOGIN_SUCCESS when user login has been done", () => {
18+
// fetchMock.postOnce("/login/", {
19+
// body: { username: "a", password: "b" },
20+
// headers: { "content-type": "application/json" }
21+
// });
22+
23+
const expectedActions = [
24+
{ type: types.userConstants.LOGIN_REQUEST },
25+
{
26+
type: types.userConstants.LOGIN_SUCCESS,
27+
body: { users: { username: "a", password: "b" } }
28+
}
29+
];
30+
const store = mockStore({ users: [] });
31+
32+
return store.dispatch(actions.userActions.login("a", "b")).then(() => {
33+
// return of async actions
34+
expect(store.getActions()).toEqual(expectedActions);
35+
});
36+
});
37+
});
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import configureMockStore from "redux-mock-store";
22
import thunk from "redux-thunk";
3-
import * as actions from "../src/_actions/user.actions";
3+
import { shallow } from "enzyme";
44
import * as types from "../src/_constants/user.constants";
55
import * as services from "../src/_services/user.services";
6+
import * as actions from "../src/_actions/user.actions";
67
import fetchMock from "fetch-mock";
78

89
const middlewares = [thunk];
910
const mockStore = configureMockStore(middlewares);
1011

12+
beforeAll(() => {
13+
global.fetch = jest.fn();
14+
});
15+
1116
describe("register actions", () => {
1217
afterEach(() => {
1318
fetchMock.restore();
@@ -29,10 +34,9 @@ describe("register actions", () => {
2934
{ type: types.REGISTER_REQUEST },
3035
{ type: types.REGISTER_SUCCESS, body: { todos: ["do something"] } }
3136
];
32-
const store = mockStore({ todos: [] });
3337

34-
console.log(services.register(user));
35-
return store.dispatch(services.register(user)).then(() => {
38+
const store = mockStore({ todos: [] });
39+
return store.dispatch(actions.register(user)).then(() => {
3640
// return of async actions
3741
expect(store.getActions()).toEqual(expectedActions);
3842
});

server/.env.default

Lines changed: 0 additions & 1 deletion
This file was deleted.

server/routes/createservices.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const jsonParser = bodyParser.json();
55
const store = require("../store");
66
const utils = require("../helpers/utils");
77

8-
// const nodeCloud = require("nodecloud");
8+
const nodeCloud = require("nodecloud");
99
const provider = nodeCloud.getProviders(null);
1010
//Virtual Machine
1111
const vm = provider.azure.compute();

server/routes/getservices.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ router.get("/home", async function(req, response) {
2929
{
3030
1: function(callback) {
3131
vm.list(resourceGroupName).then(res => {
32-
console.log("vm", res);
3332
if (res.length > 0) {
3433
callback(null, res);
3534
} else {

server/server.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ app.use(cors());
1010

1111
const authRoutes = require("./routes/auth");
1212
app.use("/", authRoutes);
13-
// const serviceRoutes = require("./routes/getServices");
14-
// app.use("/", serviceRoutes);
15-
// const createRoutes = require("./routes/createservices");
16-
// app.use("/", createRoutes);
17-
// const deleteRoutes = require("./routes/deleteservices");
18-
// app.use("/", deleteRoutes);
13+
const serviceRoutes = require("./routes/getServices");
14+
app.use("/", serviceRoutes);
15+
const createRoutes = require("./routes/createservices");
16+
app.use("/", createRoutes);
17+
const deleteRoutes = require("./routes/deleteservices");
18+
app.use("/", deleteRoutes);
1919

2020
app.get("/", function(req, res) {
2121
return res.redirect("/login");

0 commit comments

Comments
 (0)