-
Notifications
You must be signed in to change notification settings - Fork 4
/
managePatrons-test.ts
73 lines (67 loc) · 1.76 KB
/
managePatrons-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { expect } from "chai";
import ManagePatrons from "../managePatrons";
import ActionCreator from "../../actions";
describe("ManagePatrons reducer", () => {
const initState = {
data: null,
isFetching: false,
isEditing: false,
fetchError: null,
formError: null,
responseBody: null,
successMessage: null,
isLoaded: false,
};
it("returns initial state for unrecognized action", () => {
expect(ManagePatrons(undefined, {})).to.deep.equal(initState);
});
it("handles CLEAR_PATRON_DATA_LOAD", () => {
const action = {
type: `${ActionCreator.CLEAR_PATRON_DATA}_LOAD`,
data: null,
};
const oldPatronState = {
url: "test url",
data: {
authorization_expires: "",
authorization_identifier: "1234",
authorization_identifiers: [],
block_reason: "",
external_type: "",
fines: "",
permanent_id: "1234",
},
isFetching: true,
fetchError: null,
editError: null,
isLoaded: true,
isEditing: false,
};
const oldErrorState = {
url: "test url",
data: null,
isFetching: true,
fetchError: {
status: 400,
response: "No patron found",
url: "",
},
editError: null,
isLoaded: true,
isEditing: false,
};
const newPatronState = Object.assign({}, oldPatronState, {
data: null,
isFetching: false,
isLoaded: true,
});
const newErrorState = Object.assign({}, oldErrorState, {
data: null,
isFetching: false,
isLoaded: true,
fetchError: null,
});
expect(ManagePatrons(oldPatronState, action)).to.deep.equal(newPatronState);
expect(ManagePatrons(oldErrorState, action)).to.deep.equal(newErrorState);
});
});