-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrelationships.test.js
More file actions
185 lines (159 loc) · 5.21 KB
/
relationships.test.js
File metadata and controls
185 lines (159 loc) · 5.21 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import {
loadRelationships,
loadSearchRelationships,
} from "actionCreators/relationships"
import * as sinopiaApi from "sinopiaApi"
import configureMockStore from "redux-mock-store"
import thunk from "redux-thunk"
import { createState } from "stateUtils"
const mockStore = configureMockStore([thunk])
const relationships = {
bfAdminMetadataInferredRefs: [
"http://localhost:3000/resource/72f2f457-31f5-432c-8acf-b4037f7754g",
],
bfItemInferredRefs: [],
bfInstanceInferredRefs: [],
bfWorkInferredRefs: [
"http://localhost:3000/resource/83f2f457-31f5-432c-8acf-b4037f7754h",
],
bfAdminMetadataRefs: [
"http://localhost:3000/resource/94f2f457-31f5-432c-8acf-b4037f7754i",
],
bfItemRefs: [
"http://localhost:3000/resource/05f2f457-31f5-432c-8acf-b4037f7754j",
],
bfInstanceRefs: [],
bfWorkRefs: [],
sinopiaLocalAdminMetadataForRefs: [],
sinopiaHasLocalAdminMetadataInferredRefs: [],
bfAdminMetadataAllRefs: [
"http://localhost:3000/resource/72f2f457-31f5-432c-8acf-b4037f7754g",
"http://localhost:3000/resource/94f2f457-31f5-432c-8acf-b4037f7754i",
],
bfItemAllRefs: [
"http://localhost:3000/resource/05f2f457-31f5-432c-8acf-b4037f7754j",
],
bfInstanceAllRefs: [],
bfWorkAllRefs: [
"http://localhost:3000/resource/83f2f457-31f5-432c-8acf-b4037f7754h",
],
id: "c7db5404-7d7d-40ac-b38e-c821d2c3ae3f",
}
describe("loadRelationships()", () => {
beforeEach(() => {
sinopiaApi.fetchResourceRelationships = jest
.fn()
.mockResolvedValue(relationships)
})
it("fetches from Sinopia API and dispatches", async () => {
const store = mockStore(createState())
await store.dispatch(
loadRelationships(
"7d7d-40ac-b38e",
"http://localhost:3000/resource/c7db5404-7d7d-40ac-b38e-c821d2c3ae3f",
"testerrorkey"
)
)
const actions = store.getActions()
expect(actions).toHaveLength(2)
expect(actions).toHaveAction("CLEAR_ERRORS")
expect(actions).toHaveAction("SET_RELATIONSHIPS", {
resourceKey: "7d7d-40ac-b38e",
relationships: {
bfAdminMetadataRefs: [
"http://localhost:3000/resource/72f2f457-31f5-432c-8acf-b4037f7754g",
],
sinopiaLocalAdminMetadataRefs: [],
bfItemRefs: [],
bfInstanceRefs: [],
bfWorkRefs: [
"http://localhost:3000/resource/83f2f457-31f5-432c-8acf-b4037f7754h",
],
},
})
expect(sinopiaApi.fetchResourceRelationships).toHaveBeenCalledWith(
"http://localhost:3000/resource/c7db5404-7d7d-40ac-b38e-c821d2c3ae3f"
)
})
describe("when an error", () => {
beforeEach(() => {
sinopiaApi.fetchResourceRelationships = jest
.fn()
.mockRejectedValue("Ooops")
})
it("dispatches error", async () => {
const store = mockStore(createState())
await store.dispatch(
loadRelationships(
"7d7d-40ac-b38e",
"http://localhost:3000/resource/c7db5404-7d7d-40ac-b38e-c821d2c3ae3f",
"testerrorkey"
)
)
const actions = store.getActions()
expect(actions).toHaveLength(2)
expect(actions).toHaveAction("CLEAR_ERRORS")
expect(actions).toHaveAction("ADD_ERROR", {
errorKey: "testerrorkey",
error:
"Error retrieving relationships for http://localhost:3000/resource/c7db5404-7d7d-40ac-b38e-c821d2c3ae3f: Ooops",
})
})
})
})
describe("loadSearchRelationships()", () => {
beforeEach(() => {
sinopiaApi.fetchResourceRelationships = jest
.fn()
.mockResolvedValue(relationships)
})
it("fetches from Sinopia API and dispatches", async () => {
const store = mockStore(createState())
await store.dispatch(
loadSearchRelationships(
"http://localhost:3000/resource/c7db5404-7d7d-40ac-b38e-c821d2c3ae3f",
"testerrorkey"
)
)
const actions = store.getActions()
expect(actions).toHaveLength(1)
expect(actions).toHaveAction("SET_SEARCH_RELATIONSHIPS", {
uri: "http://localhost:3000/resource/c7db5404-7d7d-40ac-b38e-c821d2c3ae3f",
relationships: {
bfItemRefs: [
"http://localhost:3000/resource/05f2f457-31f5-432c-8acf-b4037f7754j",
],
bfInstanceRefs: [],
bfWorkRefs: [
"http://localhost:3000/resource/83f2f457-31f5-432c-8acf-b4037f7754h",
],
},
})
expect(sinopiaApi.fetchResourceRelationships).toHaveBeenCalledWith(
"http://localhost:3000/resource/c7db5404-7d7d-40ac-b38e-c821d2c3ae3f"
)
})
describe("when an error", () => {
beforeEach(() => {
sinopiaApi.fetchResourceRelationships = jest
.fn()
.mockRejectedValue("Ooops")
})
it("dispatches error", async () => {
const store = mockStore(createState())
await store.dispatch(
loadSearchRelationships(
"http://localhost:3000/resource/c7db5404-7d7d-40ac-b38e-c821d2c3ae3f",
"testerrorkey"
)
)
const actions = store.getActions()
expect(actions).toHaveLength(1)
expect(actions).toHaveAction("ADD_ERROR", {
errorKey: "testerrorkey",
error:
"Error retrieving relationships for http://localhost:3000/resource/c7db5404-7d7d-40ac-b38e-c821d2c3ae3f: Ooops",
})
})
})
})