-
Notifications
You must be signed in to change notification settings - Fork 4
/
circulationEvents-test.ts
95 lines (85 loc) · 2.46 KB
/
circulationEvents-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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { expect } from "chai";
import reducer, { CirculationEventsState } from "../circulationEvents";
import { CirculationEventData } from "../../interfaces";
import ActionCreator from "../../actions";
describe("circulation events reducer", () => {
const eventsData: CirculationEventData[] = [
{
id: 1,
type: "check_in",
patron_id: "patron id",
time: "Wed, 01 Jun 2016 16:49:17 GMT",
book: {
title: "book 1 title",
url: "book 1 url",
},
},
{
id: 2,
type: "check_out",
patron_id: null,
time: "Wed, 01 Jun 2016 12:00:00 GMT",
book: {
title: "book 2 title",
url: "book 2 url",
},
},
];
const initState: CirculationEventsState = {
data: null,
isFetching: false,
fetchError: null,
isLoaded: false,
};
const errorState: CirculationEventsState = {
data: null,
isFetching: false,
fetchError: { status: 401, response: "test error", url: "test url" },
isLoaded: true,
};
it("returns initial state for unrecognized action", () => {
expect(reducer(undefined, {})).to.deep.equal(initState);
});
it("handles CIRCULATION_EVENTS_REQUEST", () => {
const action = {
type: ActionCreator.CIRCULATION_EVENTS_REQUEST,
url: "test url",
};
// start with empty state
let newState = Object.assign({}, initState, {
isFetching: true,
});
expect(reducer(initState, action)).to.deep.equal(newState);
// start with error state
newState = Object.assign({}, errorState, {
isFetching: true,
fetchError: null,
});
expect(reducer(errorState, action)).to.deep.equal(newState);
});
it("handles CIRCULATION_EVENTS_FAILURE", () => {
const action = {
type: ActionCreator.CIRCULATION_EVENTS_FAILURE,
error: "test error",
};
const oldState = Object.assign({}, initState, { isFetching: true });
const newState = Object.assign({}, oldState, {
fetchError: "test error",
isFetching: false,
isLoaded: true,
});
expect(reducer(oldState, action)).to.deep.equal(newState);
});
it("handles CIRCULATION_EVENTS_LOAD", () => {
const action = {
type: ActionCreator.CIRCULATION_EVENTS_LOAD,
data: { circulation_events: eventsData },
};
const newState = Object.assign({}, initState, {
data: eventsData,
isFetching: false,
isLoaded: true,
});
expect(reducer(initState, action)).to.deep.equal(newState);
});
});