@truedat/dd 4.36.9 → 4.37.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +5 -5
- package/src/api.js +6 -7
- package/src/components/StructureSelectedFilters.js +12 -9
- package/src/components/StructureSelector.js +2 -2
- package/src/components/StructureSelectorInputField.js +2 -2
- package/src/components/StructuresRoutes.js +2 -2
- package/src/components/UserSearchFiltersLoader.js +29 -0
- package/src/components/__tests__/StructureSelectorInputField.spec.js +11 -14
- package/src/components/__tests__/UserSearchFiltersLoader.spec.js +27 -0
- package/src/components/__tests__/__snapshots__/StructureSelector.spec.js.snap +3 -1
- package/src/components/__tests__/__snapshots__/UserSearchFiltersLoader.spec.js.snap +3 -0
- package/src/messages/en.js +2 -2
- package/src/messages/es.js +2 -2
- package/src/reducers/__tests__/grantQuery.spec.js +0 -9
- package/src/reducers/__tests__/selectedUserSearchFilter.spec.js +62 -0
- package/src/reducers/__tests__/structureActiveFilters.spec.js +12 -12
- package/src/reducers/__tests__/structureQuery.spec.js +10 -10
- package/src/reducers/__tests__/structureUserFilters.spec.js +26 -26
- package/src/reducers/index.js +4 -4
- package/src/reducers/selectedUserSearchFilter.js +48 -0
- package/src/reducers/structureActiveFilters.js +4 -4
- package/src/reducers/structureQuery.js +2 -2
- package/src/reducers/{structureUserFilters.js → userSearchFilters.js} +11 -14
- package/src/routines.js +8 -12
- package/src/sagas/__tests__/deleteUserSearchFilter.spec.js +72 -0
- package/src/sagas/__tests__/fetchUserSearchFilters.spec.js +69 -0
- package/src/sagas/__tests__/saveUserSearchFilters.spec.js +78 -0
- package/src/sagas/deleteUserSearchFilter.js +31 -0
- package/src/sagas/fetchUserSearchFilters.js +26 -0
- package/src/sagas/index.js +9 -9
- package/src/sagas/saveUserSearchFilters.js +30 -0
- package/src/components/StructureUserFiltersLoader.js +0 -30
- package/src/components/__tests__/StructureUserFiltersLoader.spec.js +0 -27
- package/src/components/__tests__/__snapshots__/StructureUserFiltersLoader.spec.js.snap +0 -3
- package/src/reducers/__tests__/structureSelectedUserFilter.spec.js +0 -64
- package/src/reducers/structureSelectedUserFilter.js +0 -34
- package/src/sagas/__tests__/deleteStructureUserFilter.spec.js +0 -75
- package/src/sagas/__tests__/fetchStructureUserFilters.spec.js +0 -70
- package/src/sagas/__tests__/saveStructureUserFilters.spec.js +0 -73
- package/src/sagas/deleteStructureUserFilter.js +0 -34
- package/src/sagas/fetchStructureUserFilters.js +0 -29
- package/src/sagas/saveStructureUserFilters.js +0 -31
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import { accentInsensitivePathOrder } from "@truedat/core/services/sort";
|
|
3
|
-
import { initialState } from "../
|
|
3
|
+
import { initialState } from "../userSearchFilters";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
fetchUserSearchFilters,
|
|
6
|
+
clearUserSearchFilters,
|
|
7
|
+
deleteUserSearchFilter,
|
|
8
|
+
saveUserSearchFilters,
|
|
9
9
|
} from "../../routines";
|
|
10
|
-
import {
|
|
10
|
+
import { userSearchFilters } from "..";
|
|
11
11
|
|
|
12
12
|
const fooState = { foo: "bar" };
|
|
13
13
|
|
|
14
14
|
describe("reducers: structureActiveFilters", () => {
|
|
15
15
|
it("should provide the initial state", () => {
|
|
16
|
-
expect(
|
|
16
|
+
expect(userSearchFilters(undefined, {})).toEqual(initialState);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
it("should handle the
|
|
19
|
+
it("should handle the fetchUserSearchFilters.SUCCESS action", () => {
|
|
20
20
|
const filters = [
|
|
21
21
|
{ name: "b", id: 1, filters: { country: ["S"] } },
|
|
22
|
-
{ name: "a", id: 2, filters: { country: ["S2"] } }
|
|
22
|
+
{ name: "a", id: 2, filters: { country: ["S2"] } },
|
|
23
23
|
];
|
|
24
24
|
const sortedFilters = _.sortBy(accentInsensitivePathOrder("name"))(filters);
|
|
25
25
|
expect(
|
|
26
|
-
|
|
27
|
-
type:
|
|
28
|
-
payload: { data: filters }
|
|
26
|
+
userSearchFilters(fooState, {
|
|
27
|
+
type: fetchUserSearchFilters.SUCCESS,
|
|
28
|
+
payload: { data: filters },
|
|
29
29
|
})
|
|
30
30
|
).toEqual(sortedFilters);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
it("should handle the
|
|
33
|
+
it("should handle the saveUserSearchFilters.SUCCESS action", () => {
|
|
34
34
|
const filters = [
|
|
35
35
|
{ name: "b", id: 1, filters: { country: ["S"] } },
|
|
36
|
-
{ name: "a", id: 2, filters: { country: ["S2"] } }
|
|
36
|
+
{ name: "a", id: 2, filters: { country: ["S2"] } },
|
|
37
37
|
];
|
|
38
38
|
const newFilter = { name: "c", id: 3, filters: { country: ["S3"] } };
|
|
39
39
|
const sortedFilters = _.flow(
|
|
@@ -42,35 +42,35 @@ describe("reducers: structureActiveFilters", () => {
|
|
|
42
42
|
)(filters);
|
|
43
43
|
|
|
44
44
|
expect(
|
|
45
|
-
|
|
46
|
-
type:
|
|
47
|
-
payload: { data: newFilter }
|
|
45
|
+
userSearchFilters(filters, {
|
|
46
|
+
type: saveUserSearchFilters.SUCCESS,
|
|
47
|
+
payload: { data: newFilter },
|
|
48
48
|
})
|
|
49
49
|
).toEqual(sortedFilters);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
it("should handle the
|
|
52
|
+
it("should handle the deleteUserSearchFilter.SUCCESS action", () => {
|
|
53
53
|
const filters = [
|
|
54
54
|
{ name: "b", id: 1, filters: { country: ["S"] } },
|
|
55
|
-
{ name: "a", id: 2, filters: { country: ["S2"] } }
|
|
55
|
+
{ name: "a", id: 2, filters: { country: ["S2"] } },
|
|
56
56
|
];
|
|
57
57
|
expect(
|
|
58
|
-
|
|
59
|
-
type:
|
|
60
|
-
meta: { id: 1 }
|
|
58
|
+
userSearchFilters(filters, {
|
|
59
|
+
type: deleteUserSearchFilter.SUCCESS,
|
|
60
|
+
meta: { id: 1 },
|
|
61
61
|
})
|
|
62
62
|
).toEqual([{ name: "a", id: 2, filters: { country: ["S2"] } }]);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
it("should handle the
|
|
65
|
+
it("should handle the clearUserSearchFilters.TRIGGER action", () => {
|
|
66
66
|
expect(
|
|
67
|
-
|
|
68
|
-
type:
|
|
67
|
+
userSearchFilters(fooState, {
|
|
68
|
+
type: clearUserSearchFilters.TRIGGER,
|
|
69
69
|
})
|
|
70
70
|
).toEqual(initialState);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("should ignore unknown actions", () => {
|
|
74
|
-
expect(
|
|
74
|
+
expect(userSearchFilters(fooState, { type: "FOO" })).toBe(fooState);
|
|
75
75
|
});
|
|
76
76
|
});
|
package/src/reducers/index.js
CHANGED
|
@@ -59,7 +59,7 @@ import { structureProfile } from "./structureProfile";
|
|
|
59
59
|
import { structureQuery } from "./structureQuery";
|
|
60
60
|
import { structureRedirect } from "./structureRedirect";
|
|
61
61
|
import { structureSelectedFilter } from "./structureSelectedFilter";
|
|
62
|
-
import {
|
|
62
|
+
import { selectedUserSearchFilter } from "./selectedUserSearchFilter";
|
|
63
63
|
import { structureSiblings } from "./structureSiblings";
|
|
64
64
|
import { structuresSiblings } from "./structureSiblings";
|
|
65
65
|
import { structureSystem } from "./structureSystem";
|
|
@@ -72,7 +72,7 @@ import { structureTypeLoading } from "./structureTypeLoading";
|
|
|
72
72
|
import { structureTypes } from "./structureTypes";
|
|
73
73
|
import { structureTypesLoading } from "./structureTypesLoading";
|
|
74
74
|
import { structureUpdating } from "./structureUpdating";
|
|
75
|
-
import {
|
|
75
|
+
import { userSearchFilters } from "./userSearchFilters";
|
|
76
76
|
import { structureVersion } from "./structureVersion";
|
|
77
77
|
import { structureVersions } from "./structureVersions";
|
|
78
78
|
import { structures } from "./structures";
|
|
@@ -155,7 +155,7 @@ export {
|
|
|
155
155
|
structureQuery,
|
|
156
156
|
structureRedirect,
|
|
157
157
|
structureSelectedFilter,
|
|
158
|
-
|
|
158
|
+
selectedUserSearchFilter,
|
|
159
159
|
structureSiblings,
|
|
160
160
|
structureSystem,
|
|
161
161
|
structuresSiblings,
|
|
@@ -169,7 +169,7 @@ export {
|
|
|
169
169
|
structureTypes,
|
|
170
170
|
structureTypesLoading,
|
|
171
171
|
structureUpdating,
|
|
172
|
-
|
|
172
|
+
userSearchFilters,
|
|
173
173
|
structureVersion,
|
|
174
174
|
structureVersions,
|
|
175
175
|
structures,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearRuleFilters,
|
|
3
|
+
resetRuleFilters,
|
|
4
|
+
clearImplementationFilters,
|
|
5
|
+
resetImplementationFilters,
|
|
6
|
+
} from "@truedat/dq/routines";
|
|
7
|
+
import {
|
|
8
|
+
applyUserSearchFilter,
|
|
9
|
+
clearUserSearchFilters,
|
|
10
|
+
removeStructureFilter,
|
|
11
|
+
resetStructureFilters,
|
|
12
|
+
} from "../routines";
|
|
13
|
+
|
|
14
|
+
/** @type {string} */
|
|
15
|
+
export const initialState = null;
|
|
16
|
+
|
|
17
|
+
export const selectedUserSearchFilter = (
|
|
18
|
+
state = initialState,
|
|
19
|
+
{ type, payload }
|
|
20
|
+
) => {
|
|
21
|
+
switch (type) {
|
|
22
|
+
case applyUserSearchFilter.TRIGGER:
|
|
23
|
+
const {
|
|
24
|
+
userFilter: { name: name },
|
|
25
|
+
} = payload;
|
|
26
|
+
if (state == name) {
|
|
27
|
+
return initialState;
|
|
28
|
+
} else {
|
|
29
|
+
return name;
|
|
30
|
+
}
|
|
31
|
+
case clearUserSearchFilters.TRIGGER:
|
|
32
|
+
return initialState;
|
|
33
|
+
case removeStructureFilter.TRIGGER:
|
|
34
|
+
return initialState;
|
|
35
|
+
case resetStructureFilters.TRIGGER:
|
|
36
|
+
return initialState;
|
|
37
|
+
case clearRuleFilters.TRIGGER:
|
|
38
|
+
return initialState;
|
|
39
|
+
case resetRuleFilters.TRIGGER:
|
|
40
|
+
return initialState;
|
|
41
|
+
case clearImplementationFilters.TRIGGER:
|
|
42
|
+
return initialState;
|
|
43
|
+
case resetImplementationFilters.TRIGGER:
|
|
44
|
+
return initialState;
|
|
45
|
+
default:
|
|
46
|
+
return state;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "lodash/fp";
|
|
11
11
|
import {
|
|
12
12
|
addStructureFilter,
|
|
13
|
-
|
|
13
|
+
applyUserSearchFilter,
|
|
14
14
|
clearStructureFilters,
|
|
15
15
|
closeStructureFilter,
|
|
16
16
|
removeStructureFilter,
|
|
@@ -31,9 +31,9 @@ export const structureActiveFilters = (
|
|
|
31
31
|
const { filter } = payload;
|
|
32
32
|
return { ...state, [filter]: [] };
|
|
33
33
|
}
|
|
34
|
-
case
|
|
35
|
-
const { userFilter } = payload;
|
|
36
|
-
return prop("filters")(userFilter);
|
|
34
|
+
case applyUserSearchFilter.TRIGGER: {
|
|
35
|
+
const { userFilter, scope } = payload;
|
|
36
|
+
return scope === "data_structure" ? prop("filters")(userFilter) : state;
|
|
37
37
|
}
|
|
38
38
|
case closeStructureFilter.TRIGGER: {
|
|
39
39
|
const { filter } = payload;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
applyUserSearchFilter,
|
|
4
4
|
clearStructureFilters,
|
|
5
5
|
removeStructureFilter,
|
|
6
6
|
searchStructures,
|
|
@@ -31,7 +31,7 @@ const structureQuery = (state = initialState, { type, payload }) => {
|
|
|
31
31
|
const page = defaultPage;
|
|
32
32
|
return { ...state, page };
|
|
33
33
|
}
|
|
34
|
-
case
|
|
34
|
+
case applyUserSearchFilter.TRIGGER: {
|
|
35
35
|
const page = defaultPage;
|
|
36
36
|
return { ...state, page };
|
|
37
37
|
}
|
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import { accentInsensitivePathOrder } from "@truedat/core/services/sort";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
fetchUserSearchFilters,
|
|
5
|
+
clearUserSearchFilters,
|
|
6
|
+
deleteUserSearchFilter,
|
|
7
|
+
saveUserSearchFilters,
|
|
8
8
|
} from "../routines";
|
|
9
9
|
|
|
10
10
|
export const initialState = [];
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
state = initialState,
|
|
14
|
-
{ type, payload, meta }
|
|
15
|
-
) => {
|
|
12
|
+
const userSearchFilters = (state = initialState, { type, payload, meta }) => {
|
|
16
13
|
switch (type) {
|
|
17
|
-
case
|
|
14
|
+
case clearUserSearchFilters.TRIGGER:
|
|
18
15
|
return initialState;
|
|
19
|
-
case
|
|
16
|
+
case fetchUserSearchFilters.SUCCESS: {
|
|
20
17
|
const userFilters = _.propOr([], "data")(payload);
|
|
21
18
|
return _.sortBy(accentInsensitivePathOrder("name"))(userFilters);
|
|
22
19
|
}
|
|
23
|
-
case
|
|
20
|
+
case fetchUserSearchFilters.FAILURE:
|
|
24
21
|
return initialState;
|
|
25
|
-
case
|
|
22
|
+
case saveUserSearchFilters.SUCCESS:
|
|
26
23
|
const userFilter = _.propOr({}, "data")(payload);
|
|
27
24
|
return _.flow(
|
|
28
25
|
_.concat([userFilter]),
|
|
29
26
|
_.sortBy(accentInsensitivePathOrder("name"))
|
|
30
27
|
)(state);
|
|
31
|
-
case
|
|
28
|
+
case deleteUserSearchFilter.SUCCESS:
|
|
32
29
|
const { id } = meta;
|
|
33
30
|
return _.reject(_.propEq("id", id))(state);
|
|
34
31
|
default:
|
|
@@ -36,4 +33,4 @@ const structureUserFilters = (
|
|
|
36
33
|
}
|
|
37
34
|
};
|
|
38
35
|
|
|
39
|
-
export {
|
|
36
|
+
export { userSearchFilters };
|
package/src/routines.js
CHANGED
|
@@ -9,9 +9,7 @@ export const applyGrantDateFilter = createRoutine("APPLY_GRANT_DATE_FILTER");
|
|
|
9
9
|
export const applyStructureDateFilter = createRoutine(
|
|
10
10
|
"APPLY_STRUCTURE_DATE_FILTER"
|
|
11
11
|
);
|
|
12
|
-
export const
|
|
13
|
-
"APPLY_STRUCTURE_USER_FILTER"
|
|
14
|
-
);
|
|
12
|
+
export const applyUserSearchFilter = createRoutine("APPLY_USER_SEARCH_FILTER");
|
|
15
13
|
export const bulkUpdateStructures = createRoutine("BULK_UPDATE_STRUCTURES");
|
|
16
14
|
export const cancelPoll = createRoutine("CANCEL_POLL");
|
|
17
15
|
export const clearGrantFilters = createRoutine("CLEAR_GRANT_FILTERS");
|
|
@@ -32,8 +30,8 @@ export const clearStructureTag = createRoutine("CLEAR_STRUCTURE_TAG");
|
|
|
32
30
|
export const clearStructureTags = createRoutine("CLEAR_STRUCTURE_TAGS");
|
|
33
31
|
export const clearStructureType = createRoutine("CLEAR_STRUCTURE_TYPE");
|
|
34
32
|
export const clearStructureTypes = createRoutine("CLEAR_STRUCTURE_TYPES");
|
|
35
|
-
export const
|
|
36
|
-
"
|
|
33
|
+
export const clearUserSearchFilters = createRoutine(
|
|
34
|
+
"CLEAR_USER_SEARCH_FILTERS"
|
|
37
35
|
);
|
|
38
36
|
export const clearStructures = createRoutine("CLEAR_STRUCTURES");
|
|
39
37
|
export const clearStructuresSort = createRoutine("CLEAR_STRUCTURES_SORT");
|
|
@@ -53,8 +51,8 @@ export const deleteLinkStructureTag = createRoutine(
|
|
|
53
51
|
"DELETE_LINK_STRUCTURE_TAG"
|
|
54
52
|
);
|
|
55
53
|
export const deleteStructureTag = createRoutine("DELETE_STRUCTURE_TAG");
|
|
56
|
-
export const
|
|
57
|
-
"
|
|
54
|
+
export const deleteUserSearchFilter = createRoutine(
|
|
55
|
+
"DELETE_USER_SEARCH_FILTER"
|
|
58
56
|
);
|
|
59
57
|
export const doStructureNoteAction = createRoutine("DO_STRUCTURE_NOTE_ACTION");
|
|
60
58
|
export const downloadCsvGraph = createRoutine("DOWNLOAD_CSV_GRAPH");
|
|
@@ -84,8 +82,8 @@ export const fetchStructureTag = createRoutine("FETCH_STRUCTURE_TAG");
|
|
|
84
82
|
export const fetchStructureTags = createRoutine("FETCH_STRUCTURE_TAGS");
|
|
85
83
|
export const fetchStructureType = createRoutine("FETCH_STRUCTURE_TYPE");
|
|
86
84
|
export const fetchStructureTypes = createRoutine("FETCH_STRUCTURE_TYPES");
|
|
87
|
-
export const
|
|
88
|
-
"
|
|
85
|
+
export const fetchUserSearchFilters = createRoutine(
|
|
86
|
+
"FETCH_USER_SEARCH_FILTERS"
|
|
89
87
|
);
|
|
90
88
|
export const fetchStructures = createRoutine("FETCH_STRUCTURES");
|
|
91
89
|
export const fetchSystem = createRoutine("FETCH_SYSTEM");
|
|
@@ -106,9 +104,7 @@ export const removeStructureSelectedFilter = createRoutine(
|
|
|
106
104
|
);
|
|
107
105
|
export const resetGrantFilters = createRoutine("RESET_GRANT_FILTERS");
|
|
108
106
|
export const resetStructureFilters = createRoutine("RESET_STRUCTURE_FILTERS");
|
|
109
|
-
export const
|
|
110
|
-
"SAVE_STRUCTURE_USER_FILTERS"
|
|
111
|
-
);
|
|
107
|
+
export const saveUserSearchFilters = createRoutine("SAVE_USER_SEARCH_FILTERS");
|
|
112
108
|
export const searchGrants = createRoutine("SEARCH_GRANTS");
|
|
113
109
|
export const searchStructures = createRoutine("SEARCH_STRUCTURES");
|
|
114
110
|
export const selectGrantPage = createRoutine("SELECT_GRANT_PAGE");
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { compile } from "path-to-regexp";
|
|
2
|
+
import { testSaga } from "redux-saga-test-plan";
|
|
3
|
+
import { apiJsonDelete, JSON_OPTS } from "@truedat/core/services/api";
|
|
4
|
+
import {
|
|
5
|
+
deleteUserSearchFilterSaga,
|
|
6
|
+
deleteUserSearchFilterRequestSaga,
|
|
7
|
+
} from "../deleteUserSearchFilter";
|
|
8
|
+
import { deleteUserSearchFilter } from "../../routines";
|
|
9
|
+
import { API_USER_SEARCH_FILTER } from "../../api";
|
|
10
|
+
|
|
11
|
+
describe("sagas: deleteUserSearchFilterRequestSaga", () => {
|
|
12
|
+
it("should invoke deleteUserSearchFilterSaga on deleteUserSearchFilter.TRIGGER", () => {
|
|
13
|
+
expect(() => {
|
|
14
|
+
testSaga(deleteUserSearchFilterRequestSaga)
|
|
15
|
+
.next()
|
|
16
|
+
.takeLatest(deleteUserSearchFilter.TRIGGER, deleteUserSearchFilterSaga)
|
|
17
|
+
.finish()
|
|
18
|
+
.isDone();
|
|
19
|
+
}).not.toThrow();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should throw exception if an unhandled action is received", () => {
|
|
23
|
+
expect(() => {
|
|
24
|
+
testSaga(deleteUserSearchFilterRequestSaga)
|
|
25
|
+
.next()
|
|
26
|
+
.takeLatest("FOO", deleteUserSearchFilterRequestSaga);
|
|
27
|
+
}).toThrow();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("sagas: deleteUserSearchFilterSaga", () => {
|
|
32
|
+
const payload = { id: 1 };
|
|
33
|
+
const { id } = payload;
|
|
34
|
+
const url = compile(API_USER_SEARCH_FILTER)({ id });
|
|
35
|
+
const meta = { id };
|
|
36
|
+
|
|
37
|
+
it("should put a success action when a response is returned", () => {
|
|
38
|
+
expect(() => {
|
|
39
|
+
testSaga(deleteUserSearchFilterSaga, { payload })
|
|
40
|
+
.next()
|
|
41
|
+
.put({ meta, ...deleteUserSearchFilter.request() })
|
|
42
|
+
.next()
|
|
43
|
+
.call(apiJsonDelete, url, JSON_OPTS)
|
|
44
|
+
.next({ data: payload })
|
|
45
|
+
.put({ meta, ...deleteUserSearchFilter.success(payload) })
|
|
46
|
+
.next()
|
|
47
|
+
.put(deleteUserSearchFilter.fulfill())
|
|
48
|
+
.next()
|
|
49
|
+
.isDone();
|
|
50
|
+
}).not.toThrow();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should put a failure action when the call returns an error", () => {
|
|
54
|
+
const message = "Request failed";
|
|
55
|
+
const error = { message };
|
|
56
|
+
const meta = { id: 1 };
|
|
57
|
+
|
|
58
|
+
expect(() => {
|
|
59
|
+
testSaga(deleteUserSearchFilterSaga, { payload })
|
|
60
|
+
.next()
|
|
61
|
+
.put({ meta, ...deleteUserSearchFilter.request() })
|
|
62
|
+
.next()
|
|
63
|
+
.call(apiJsonDelete, url, JSON_OPTS)
|
|
64
|
+
.throw(error)
|
|
65
|
+
.put(deleteUserSearchFilter.failure(message))
|
|
66
|
+
.next()
|
|
67
|
+
.put(deleteUserSearchFilter.fulfill())
|
|
68
|
+
.next()
|
|
69
|
+
.isDone();
|
|
70
|
+
}).not.toThrow();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { testSaga } from "redux-saga-test-plan";
|
|
2
|
+
import { apiJson, JSON_OPTS } from "@truedat/core/services/api";
|
|
3
|
+
import {
|
|
4
|
+
fetchUserSearchFiltersRequestSaga,
|
|
5
|
+
fetchUserSearchFiltersSaga,
|
|
6
|
+
} from "../fetchUserSearchFilters";
|
|
7
|
+
import { fetchUserSearchFilters } from "../../routines";
|
|
8
|
+
import { API_GET_USER_SEARCH_FILTERS } from "../../api";
|
|
9
|
+
|
|
10
|
+
describe("sagas: fetchUserSearchFiltersRequestSaga", () => {
|
|
11
|
+
it("should invoke fetchUserSearchFiltersSaga on fetchUserSearchFilters.TRIGGER", () => {
|
|
12
|
+
expect(() => {
|
|
13
|
+
testSaga(fetchUserSearchFiltersRequestSaga)
|
|
14
|
+
.next()
|
|
15
|
+
.takeLatest(fetchUserSearchFilters.TRIGGER, fetchUserSearchFiltersSaga)
|
|
16
|
+
.finish()
|
|
17
|
+
.isDone();
|
|
18
|
+
}).not.toThrow();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should throw exception if an unhandled action is received", () => {
|
|
22
|
+
expect(() => {
|
|
23
|
+
testSaga(fetchUserSearchFiltersRequestSaga)
|
|
24
|
+
.next()
|
|
25
|
+
.takeLatest("FOO", fetchUserSearchFiltersRequestSaga);
|
|
26
|
+
}).toThrow();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("sagas: fetchUserSearchFiltersSaga", () => {
|
|
31
|
+
const data = [{ id: 1, name: "a" }];
|
|
32
|
+
const payload = "test_scope";
|
|
33
|
+
const url = `${API_GET_USER_SEARCH_FILTERS}?scope=${payload}`;
|
|
34
|
+
|
|
35
|
+
it("should put a success action when a response is returned", () => {
|
|
36
|
+
expect(() => {
|
|
37
|
+
testSaga(fetchUserSearchFiltersSaga, { payload })
|
|
38
|
+
.next()
|
|
39
|
+
.put(fetchUserSearchFilters.request())
|
|
40
|
+
.next()
|
|
41
|
+
.call(apiJson, url, JSON_OPTS)
|
|
42
|
+
.next({ data })
|
|
43
|
+
.put(fetchUserSearchFilters.success(data))
|
|
44
|
+
.next()
|
|
45
|
+
.put(fetchUserSearchFilters.fulfill())
|
|
46
|
+
.next()
|
|
47
|
+
.isDone();
|
|
48
|
+
}).not.toThrow();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should put a failure action when the call returns an error", () => {
|
|
52
|
+
const message = "Request failed";
|
|
53
|
+
const error = { message };
|
|
54
|
+
|
|
55
|
+
expect(() => {
|
|
56
|
+
testSaga(fetchUserSearchFiltersSaga, { payload })
|
|
57
|
+
.next()
|
|
58
|
+
.put(fetchUserSearchFilters.request())
|
|
59
|
+
.next()
|
|
60
|
+
.call(apiJson, url, JSON_OPTS)
|
|
61
|
+
.throw(error)
|
|
62
|
+
.put(fetchUserSearchFilters.failure(message))
|
|
63
|
+
.next()
|
|
64
|
+
.put(fetchUserSearchFilters.fulfill())
|
|
65
|
+
.next()
|
|
66
|
+
.isDone();
|
|
67
|
+
}).not.toThrow();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { testSaga } from "redux-saga-test-plan";
|
|
2
|
+
import { apiJsonPost, JSON_OPTS } from "@truedat/core/services/api";
|
|
3
|
+
import {
|
|
4
|
+
saveUserSearchFiltersRequestSaga,
|
|
5
|
+
saveUserSearchFiltersSaga,
|
|
6
|
+
} from "../saveUserSearchFilters";
|
|
7
|
+
import { saveUserSearchFilters } from "../../routines";
|
|
8
|
+
import { API_USER_SEARCH_FILTERS } from "../../api";
|
|
9
|
+
|
|
10
|
+
describe("sagas: saveStructureFiltersRequestSaga", () => {
|
|
11
|
+
it("should invoke saveStructureFiltersSaga on saveStructureFilters.TRIGGER", () => {
|
|
12
|
+
expect(() => {
|
|
13
|
+
testSaga(saveUserSearchFiltersRequestSaga)
|
|
14
|
+
.next()
|
|
15
|
+
.takeLatest(saveUserSearchFilters.TRIGGER, saveUserSearchFiltersSaga)
|
|
16
|
+
.finish()
|
|
17
|
+
.isDone();
|
|
18
|
+
}).not.toThrow();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should throw exception if an unhandled action is received", () => {
|
|
22
|
+
expect(() => {
|
|
23
|
+
testSaga(saveUserSearchFiltersRequestSaga)
|
|
24
|
+
.next()
|
|
25
|
+
.takeLatest("FOO", saveUserSearchFiltersRequestSaga);
|
|
26
|
+
}).toThrow();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("sagas: saveStructureFiltersSaga", () => {
|
|
31
|
+
const data = { user_search_filter: { id: 1, name: "a" } };
|
|
32
|
+
const payload = {
|
|
33
|
+
filterName: "a",
|
|
34
|
+
filters: { country: ["A"] },
|
|
35
|
+
scope: "data_structure",
|
|
36
|
+
};
|
|
37
|
+
const requestData = {
|
|
38
|
+
user_search_filter: {
|
|
39
|
+
name: "a",
|
|
40
|
+
filters: { country: ["A"] },
|
|
41
|
+
scope: "data_structure",
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
it("should put a success action when a response is returned", () => {
|
|
45
|
+
expect(() => {
|
|
46
|
+
testSaga(saveUserSearchFiltersSaga, { payload })
|
|
47
|
+
.next()
|
|
48
|
+
.put(saveUserSearchFilters.request())
|
|
49
|
+
.next()
|
|
50
|
+
.call(apiJsonPost, API_USER_SEARCH_FILTERS, requestData, JSON_OPTS)
|
|
51
|
+
.next({ data })
|
|
52
|
+
.put(saveUserSearchFilters.success(data))
|
|
53
|
+
.next()
|
|
54
|
+
.put(saveUserSearchFilters.fulfill())
|
|
55
|
+
.next()
|
|
56
|
+
.isDone();
|
|
57
|
+
}).not.toThrow();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should put a failure action when the call returns an error", () => {
|
|
61
|
+
const message = "Request failed";
|
|
62
|
+
const error = { message };
|
|
63
|
+
|
|
64
|
+
expect(() => {
|
|
65
|
+
testSaga(saveUserSearchFiltersSaga, { payload })
|
|
66
|
+
.next()
|
|
67
|
+
.put(saveUserSearchFilters.request())
|
|
68
|
+
.next()
|
|
69
|
+
.call(apiJsonPost, API_USER_SEARCH_FILTERS, requestData, JSON_OPTS)
|
|
70
|
+
.throw(error)
|
|
71
|
+
.put(saveUserSearchFilters.failure(message))
|
|
72
|
+
.next()
|
|
73
|
+
.put(saveUserSearchFilters.fulfill())
|
|
74
|
+
.next()
|
|
75
|
+
.isDone();
|
|
76
|
+
}).not.toThrow();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { compile } from "path-to-regexp";
|
|
2
|
+
import { call, put, takeLatest } from "redux-saga/effects";
|
|
3
|
+
import { apiJsonDelete, JSON_OPTS } from "@truedat/core/services/api";
|
|
4
|
+
import { deleteUserSearchFilter } from "../routines";
|
|
5
|
+
import { API_USER_SEARCH_FILTER } from "../api";
|
|
6
|
+
|
|
7
|
+
const toApiPath = compile(API_USER_SEARCH_FILTER);
|
|
8
|
+
|
|
9
|
+
export function* deleteUserSearchFilterSaga({ payload }) {
|
|
10
|
+
try {
|
|
11
|
+
const url = toApiPath(payload);
|
|
12
|
+
const { id } = payload;
|
|
13
|
+
const meta = { id };
|
|
14
|
+
yield put({ meta, ...deleteUserSearchFilter.request() });
|
|
15
|
+
const { data } = yield call(apiJsonDelete, url, JSON_OPTS);
|
|
16
|
+
yield put({ meta, ...deleteUserSearchFilter.success(data) });
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error.response) {
|
|
19
|
+
const { status, data } = error.response;
|
|
20
|
+
yield put(deleteUserSearchFilter.failure({ status, data }));
|
|
21
|
+
} else {
|
|
22
|
+
yield put(deleteUserSearchFilter.failure(error.message));
|
|
23
|
+
}
|
|
24
|
+
} finally {
|
|
25
|
+
yield put(deleteUserSearchFilter.fulfill());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function* deleteUserSearchFilterRequestSaga() {
|
|
30
|
+
yield takeLatest(deleteUserSearchFilter.TRIGGER, deleteUserSearchFilterSaga);
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { call, put, takeLatest } from "redux-saga/effects";
|
|
2
|
+
import { apiJson, JSON_OPTS } from "@truedat/core/services/api";
|
|
3
|
+
import { fetchUserSearchFilters } from "../routines";
|
|
4
|
+
import { API_GET_USER_SEARCH_FILTERS } from "../api";
|
|
5
|
+
|
|
6
|
+
export function* fetchUserSearchFiltersSaga({ payload }) {
|
|
7
|
+
try {
|
|
8
|
+
const url = `${API_GET_USER_SEARCH_FILTERS}?scope=${payload}`;
|
|
9
|
+
yield put(fetchUserSearchFilters.request());
|
|
10
|
+
const { data } = yield call(apiJson, url, JSON_OPTS);
|
|
11
|
+
yield put(fetchUserSearchFilters.success(data));
|
|
12
|
+
} catch (error) {
|
|
13
|
+
if (error.response) {
|
|
14
|
+
const { status, data } = error.response;
|
|
15
|
+
yield put(fetchUserSearchFilters.failure({ status, data }));
|
|
16
|
+
} else {
|
|
17
|
+
yield put(fetchUserSearchFilters.failure(error.message));
|
|
18
|
+
}
|
|
19
|
+
} finally {
|
|
20
|
+
yield put(fetchUserSearchFilters.fulfill());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function* fetchUserSearchFiltersRequestSaga() {
|
|
25
|
+
yield takeLatest(fetchUserSearchFilters.TRIGGER, fetchUserSearchFiltersSaga);
|
|
26
|
+
}
|