@truedat/dd 4.48.11 → 4.49.0

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +5 -5
  3. package/src/api/fragments.js +2 -2
  4. package/src/api/mutations.js +33 -11
  5. package/src/api/queries.js +37 -10
  6. package/src/api.js +0 -4
  7. package/src/components/DictionaryRoutes.js +4 -4
  8. package/src/components/StructureSummary.js +12 -22
  9. package/src/components/StructureTag.js +83 -54
  10. package/src/components/StructureTagForm.js +149 -89
  11. package/src/components/StructureTags.js +57 -27
  12. package/src/components/Tag.js +62 -0
  13. package/src/components/TagCards.js +85 -0
  14. package/src/components/TagCrumbs.js +25 -0
  15. package/src/components/TagForm.js +101 -0
  16. package/src/components/TagStructureButton.js +58 -0
  17. package/src/components/Tags.js +33 -0
  18. package/src/components/TagsRoutes.js +39 -0
  19. package/src/components/__tests__/StructureSummary.spec.js +0 -7
  20. package/src/components/__tests__/StructureTag.spec.js +79 -5
  21. package/src/components/__tests__/StructureTagForm.spec.js +99 -50
  22. package/src/components/__tests__/Tag.spec.js +11 -0
  23. package/src/components/__tests__/{StructureTagsCards.spec.js → TagCards.spec.js} +10 -10
  24. package/src/components/__tests__/TagCrumbs.spec.js +10 -0
  25. package/src/components/__tests__/TagForm.spec.js +72 -0
  26. package/src/components/__tests__/Tags.spec.js +10 -0
  27. package/src/components/__tests__/__snapshots__/StructureSummary.spec.js.snap +18 -42
  28. package/src/components/__tests__/__snapshots__/StructureTag.spec.js.snap +10 -30
  29. package/src/components/__tests__/__snapshots__/StructureTagForm.spec.js.snap +255 -51
  30. package/src/components/__tests__/__snapshots__/Tag.spec.js.snap +36 -0
  31. package/src/components/__tests__/__snapshots__/{StructureTagsCards.spec.js.snap → TagCards.spec.js.snap} +1 -1
  32. package/src/components/__tests__/__snapshots__/TagCrumbs.spec.js.snap +102 -0
  33. package/src/components/__tests__/__snapshots__/TagForm.spec.js.snap +70 -0
  34. package/src/components/__tests__/__snapshots__/{StructureTags.spec.js.snap → Tags.spec.js.snap} +1 -1
  35. package/src/messages/en.js +25 -30
  36. package/src/messages/es.js +25 -30
  37. package/src/reducers/__tests__/{editableStructureTags.spec.js → availableTags.spec.js} +7 -11
  38. package/src/reducers/__tests__/structureTagSaving.spec.js +36 -0
  39. package/src/reducers/__tests__/tagSaving.spec.js +32 -0
  40. package/src/reducers/{editableStructureTags.js → availableTags.js} +2 -2
  41. package/src/reducers/index.js +6 -12
  42. package/src/reducers/structureRedirect.js +7 -7
  43. package/src/reducers/structureTagSaving.js +12 -10
  44. package/src/reducers/tagSaving.js +18 -0
  45. package/src/routines.js +5 -6
  46. package/src/sagas/__tests__/createTag.spec.js +81 -0
  47. package/src/sagas/__tests__/deleteStructureTag.spec.js +11 -12
  48. package/src/sagas/__tests__/deleteTag.spec.js +76 -0
  49. package/src/sagas/__tests__/tagStructure.spec.js +86 -0
  50. package/src/sagas/__tests__/updateTag.spec.js +81 -0
  51. package/src/sagas/createTag.js +29 -0
  52. package/src/sagas/deleteStructureTag.js +12 -9
  53. package/src/sagas/deleteTag.js +34 -0
  54. package/src/sagas/index.js +15 -18
  55. package/src/sagas/tagStructure.js +37 -0
  56. package/src/sagas/updateTag.js +23 -0
  57. package/src/components/LinkStructureTagForm.js +0 -163
  58. package/src/components/LinkedStructureTag.js +0 -124
  59. package/src/components/StructureLinkTagButton.js +0 -47
  60. package/src/components/StructureTagsCards.js +0 -92
  61. package/src/components/StructureTagsCrumbs.js +0 -44
  62. package/src/components/StructureTagsRoutes.js +0 -45
  63. package/src/components/TagsHeader.js +0 -32
  64. package/src/components/__tests__/LinkStructureTagForm.spec.js +0 -184
  65. package/src/components/__tests__/LinkedStructureTag.spec.js +0 -133
  66. package/src/components/__tests__/StructureTags.spec.js +0 -14
  67. package/src/components/__tests__/StructureTagsCrumbs.spec.js +0 -13
  68. package/src/components/__tests__/__snapshots__/LinkStructureTagForm.spec.js.snap +0 -456
  69. package/src/components/__tests__/__snapshots__/LinkedStructureTag.spec.js.snap +0 -16
  70. package/src/components/__tests__/__snapshots__/StructureTagsCrumbs.spec.js.snap +0 -36
  71. package/src/reducers/__tests__/deletingStructureTags.spec.js +0 -30
  72. package/src/reducers/__tests__/linkedStructureTags.spec.js +0 -69
  73. package/src/reducers/__tests__/linkedStructureTagsLoading.spec.js +0 -32
  74. package/src/reducers/__tests__/linkingStructureTags.spec.js +0 -30
  75. package/src/reducers/__tests__/structureTagsSaving.spec.js +0 -40
  76. package/src/reducers/deletingStructureTags.js +0 -16
  77. package/src/reducers/linkedStructureTags.js +0 -28
  78. package/src/reducers/linkedStructureTagsLoading.js +0 -16
  79. package/src/reducers/linkingStructureTags.js +0 -16
  80. package/src/sagas/__tests__/createStructureTag.spec.js +0 -85
  81. package/src/sagas/__tests__/deleteLinkStructureTag.spec.js +0 -96
  82. package/src/sagas/__tests__/fetchLinksStructureTags.spec.js +0 -105
  83. package/src/sagas/__tests__/linkStructureTag.spec.js +0 -102
  84. package/src/sagas/__tests__/updateStructureTag.spec.js +0 -84
  85. package/src/sagas/createStructureTag.js +0 -29
  86. package/src/sagas/deleteLinkStructureTag.js +0 -29
  87. package/src/sagas/fetchLinksStructureTags.js +0 -31
  88. package/src/sagas/linkStructureTag.js +0 -30
  89. package/src/sagas/updateStructureTag.js +0 -23
@@ -1,69 +0,0 @@
1
- import {
2
- clearStructure,
3
- fetchStructure,
4
- fetchLinksStructureTags,
5
- updateStructure,
6
- } from "../../routines";
7
- import { linkedStructureTags } from "..";
8
-
9
- const fooState = { foo: "bar" };
10
- const tags = [
11
- {
12
- id: 1,
13
- description: "foo",
14
- inserted_at: "foo",
15
- updated_at: "foo",
16
- _embedded: {
17
- data_structure: { id: 1, external_id: "baz" },
18
- data_structure_tag: { id: 1, name: "bar", description: "qux" },
19
- },
20
- },
21
- ];
22
- const data = { tags };
23
-
24
- describe("reducers: linkedStructureTags", () => {
25
- const initialState = [];
26
-
27
- it("should provide the initial state", () => {
28
- expect(linkedStructureTags(undefined, {})).toEqual(initialState);
29
- });
30
-
31
- it("should handle the clearStructure.TRIGGER action", () => {
32
- expect(
33
- linkedStructureTags(fooState, {
34
- type: clearStructure.TRIGGER,
35
- })
36
- ).toMatchObject(initialState);
37
- });
38
-
39
- it("should handle the fetchLinksStructureTags.SUCCESS action", () => {
40
- expect(
41
- linkedStructureTags(fooState, {
42
- type: fetchLinksStructureTags.SUCCESS,
43
- payload: { data: tags },
44
- })
45
- ).toMatchObject(tags);
46
- });
47
-
48
- it("should handle the fetchStructure.SUCCESS action", () => {
49
- expect(
50
- linkedStructureTags(fooState, {
51
- type: fetchStructure.SUCCESS,
52
- payload: { data },
53
- })
54
- ).toMatchObject(tags);
55
- });
56
-
57
- it("should handle the updateStructure.SUCCESS action", () => {
58
- expect(
59
- linkedStructureTags(fooState, {
60
- type: updateStructure.SUCCESS,
61
- payload: { data },
62
- })
63
- ).toMatchObject(tags);
64
- });
65
-
66
- it("should ignore unknown actions", () => {
67
- expect(linkedStructureTags(fooState, { type: "FOO" })).toBe(fooState);
68
- });
69
- });
@@ -1,32 +0,0 @@
1
- import { fetchLinksStructureTags } from "../../routines";
2
- import { linkedStructureTagsLoading } from "..";
3
-
4
- const fooState = { foo: "bar" };
5
-
6
- describe("reducers: linkedStructureTagsLoading", () => {
7
- it("should provide the initial state", () => {
8
- expect(linkedStructureTagsLoading(undefined, {})).toBe(false);
9
- });
10
-
11
- it("should be true after receiving the fetchLinksStructureTags.TRIGGER action", () => {
12
- expect(
13
- linkedStructureTagsLoading(fooState, {
14
- type: fetchLinksStructureTags.TRIGGER
15
- })
16
- ).toBe(true);
17
- });
18
-
19
- it("should be false after receiving the fetchLinksStructureTags.FULFILL action", () => {
20
- expect(
21
- linkedStructureTagsLoading(fooState, {
22
- type: fetchLinksStructureTags.FULFILL
23
- })
24
- ).toBe(false);
25
- });
26
-
27
- it("should ignore unhandled actions", () => {
28
- expect(linkedStructureTagsLoading(fooState, { type: "FOO" })).toBe(
29
- fooState
30
- );
31
- });
32
- });
@@ -1,30 +0,0 @@
1
- import { linkStructureTag } from "../../routines";
2
- import { linkingStructureTags } from "..";
3
-
4
- const fooState = { foo: "bar" };
5
-
6
- describe("reducers: linkingStructureTags", () => {
7
- it("should provide the initial state", () => {
8
- expect(linkingStructureTags(undefined, {})).toBe(false);
9
- });
10
-
11
- it("should be true after receiving the fetchLinksStructureTags.TRIGGER action", () => {
12
- expect(
13
- linkingStructureTags(fooState, {
14
- type: linkStructureTag.TRIGGER
15
- })
16
- ).toBe(true);
17
- });
18
-
19
- it("should be false after receiving the fetchLinksStructureTags.FULFILL action", () => {
20
- expect(
21
- linkingStructureTags(fooState, {
22
- type: linkStructureTag.FULFILL
23
- })
24
- ).toBe(false);
25
- });
26
-
27
- it("should ignore unhandled actions", () => {
28
- expect(linkingStructureTags(fooState, { type: "FOO" })).toBe(fooState);
29
- });
30
- });
@@ -1,40 +0,0 @@
1
- import { createStructureTag, updateStructureTag } from "../../routines";
2
- import { structureTagSaving } from "..";
3
-
4
- const fooState = { foo: "bar" };
5
-
6
- describe("reducers: structureTagSaving", () => {
7
- const initialState = false;
8
-
9
- it("should provide the initial state", () => {
10
- expect(structureTagSaving(undefined, {})).toBe(initialState);
11
- });
12
-
13
- it("should handle the createStructureTag.TRIGGER action", () => {
14
- expect(
15
- structureTagSaving(fooState, { type: createStructureTag.TRIGGER })
16
- ).toBe(true);
17
- });
18
-
19
- it("should handle the createStructureTag.FULFILL action", () => {
20
- expect(
21
- structureTagSaving(fooState, { type: createStructureTag.FULFILL })
22
- ).toBe(false);
23
- });
24
-
25
- it("should handle the updateStructureTag.TRIGGER action", () => {
26
- expect(
27
- structureTagSaving(fooState, { type: updateStructureTag.TRIGGER })
28
- ).toBe(true);
29
- });
30
-
31
- it("should handle the updateStructureTag.FULFILL action", () => {
32
- expect(
33
- structureTagSaving(fooState, { type: updateStructureTag.FULFILL })
34
- ).toBe(false);
35
- });
36
-
37
- it("should ignore unknown actions", () => {
38
- expect(structureTagSaving(fooState, { type: "FOO" })).toBe(fooState);
39
- });
40
- });
@@ -1,16 +0,0 @@
1
- import { deleteLinkStructureTag } from "../routines";
2
-
3
- const initialState = false;
4
-
5
- const deletingStructureTags = (state = initialState, { type }) => {
6
- switch (type) {
7
- case deleteLinkStructureTag.TRIGGER:
8
- return true;
9
- case deleteLinkStructureTag.FULFILL:
10
- return initialState;
11
- default:
12
- return state;
13
- }
14
- };
15
-
16
- export { deletingStructureTags };
@@ -1,28 +0,0 @@
1
- import _ from "lodash/fp";
2
- import {
3
- clearStructure,
4
- fetchStructure,
5
- fetchLinksStructureTags,
6
- updateStructure,
7
- } from "../routines";
8
-
9
- const initialState = [];
10
-
11
- const linkedStructureTags = (state = initialState, { type, payload }) => {
12
- switch (type) {
13
- case clearStructure.TRIGGER:
14
- return initialState;
15
- case fetchStructure.TRIGGER:
16
- return state;
17
- case fetchLinksStructureTags.SUCCESS:
18
- return payload.data;
19
- case fetchStructure.SUCCESS:
20
- return _.pathOr([], "data.tags")(payload);
21
- case updateStructure.SUCCESS:
22
- return _.pathOr([], "data.tags")(payload);
23
- default:
24
- return state;
25
- }
26
- };
27
-
28
- export { linkedStructureTags };
@@ -1,16 +0,0 @@
1
- import { fetchLinksStructureTags } from "../routines";
2
-
3
- const initialState = false;
4
-
5
- const linkedStructureTagsLoading = (state = initialState, { type }) => {
6
- switch (type) {
7
- case fetchLinksStructureTags.TRIGGER:
8
- return true;
9
- case fetchLinksStructureTags.FULFILL:
10
- return initialState;
11
- default:
12
- return state;
13
- }
14
- };
15
-
16
- export { linkedStructureTagsLoading };
@@ -1,16 +0,0 @@
1
- import { linkStructureTag } from "../routines";
2
-
3
- const initialState = false;
4
-
5
- const linkingStructureTags = (state = initialState, { type }) => {
6
- switch (type) {
7
- case linkStructureTag.TRIGGER:
8
- return true;
9
- case linkStructureTag.FULFILL:
10
- return initialState;
11
- default:
12
- return state;
13
- }
14
- };
15
-
16
- export { linkingStructureTags };
@@ -1,85 +0,0 @@
1
- import { testSaga } from "redux-saga-test-plan";
2
- import {
3
- createStructureTagRequestSaga,
4
- createStructureTagSaga,
5
- onSuccess,
6
- } from "../createStructureTag";
7
- import { CREATE_STRUCTURE_TAG } from "../../api/mutations";
8
- import { createStructureTag } from "../../routines";
9
-
10
- describe("sagas: createStructureTagRequestSaga", () => {
11
- it("should invoke createStructureTagSaga on createStructureTag.TRIGGER", () => {
12
- expect(() => {
13
- testSaga(createStructureTagRequestSaga)
14
- .next()
15
- .takeLatest(createStructureTag.TRIGGER, createStructureTagSaga)
16
- .finish()
17
- .isDone();
18
- }).not.toThrow();
19
- });
20
-
21
- it("should throw exception if an unhandled action is received", () => {
22
- expect(() => {
23
- testSaga(createStructureTagRequestSaga)
24
- .next()
25
- .takeLatest("FOO", createStructureTagRequestSaga);
26
- }).toThrow();
27
- });
28
- });
29
-
30
- describe("sagas: createStructureTagSaga", () => {
31
- const client = { mutate: jest.fn() };
32
- const structureTag = {
33
- name: "tag1",
34
- domainIds: ["1", "2"],
35
- };
36
- const payload = structureTag;
37
- const data = { foo: "bar" };
38
-
39
- it("should put a success action when a response is returned", () => {
40
- expect(() => {
41
- testSaga(createStructureTagSaga, { payload })
42
- .next()
43
- .getContext("client")
44
- .next(client)
45
- .put(createStructureTag.request(payload))
46
- .next()
47
- .call(client.mutate, {
48
- mutation: CREATE_STRUCTURE_TAG,
49
- update: onSuccess,
50
- variables: { structureTag },
51
- })
52
- .next({ data })
53
- .put(createStructureTag.success(data))
54
- .next()
55
- .put(createStructureTag.fulfill())
56
- .next()
57
- .isDone();
58
- }).not.toThrow();
59
- });
60
-
61
- it("should put a failure action when the call returns an error", () => {
62
- const message = "Request failed";
63
- const error = { message };
64
-
65
- expect(() => {
66
- testSaga(createStructureTagSaga, { payload })
67
- .next()
68
- .getContext("client")
69
- .next(client)
70
- .put(createStructureTag.request(payload))
71
- .next()
72
- .call(client.mutate, {
73
- mutation: CREATE_STRUCTURE_TAG,
74
- update: onSuccess,
75
- variables: { structureTag },
76
- })
77
- .throw(error)
78
- .put(createStructureTag.failure(message))
79
- .next()
80
- .put(createStructureTag.fulfill())
81
- .next()
82
- .isDone();
83
- }).not.toThrow();
84
- });
85
- });
@@ -1,96 +0,0 @@
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
- deleteLinkStructureTagSaga,
6
- deleteLinkStructureTagRequestSaga
7
- } from "../deleteLinkStructureTag";
8
- import {
9
- fetchLinksStructureTags,
10
- deleteLinkStructureTag
11
- } from "../../routines";
12
- import { API_STRUCTURES_TAG } from "../../api";
13
-
14
- describe("sagas: deleteLinkStructureTagRequestSaga", () => {
15
- it("should invoke deleteLinkStructureTagSaga on deleteLinkStructureTag.TRIGGER", () => {
16
- expect(() => {
17
- testSaga(deleteLinkStructureTagRequestSaga)
18
- .next()
19
- .takeLatest(deleteLinkStructureTag.TRIGGER, deleteLinkStructureTagSaga)
20
- .finish()
21
- .isDone();
22
- }).not.toThrow();
23
- });
24
-
25
- it("should throw exception if an unhandled action is received", () => {
26
- expect(() => {
27
- testSaga(deleteLinkStructureTagRequestSaga)
28
- .next()
29
- .takeLatest("FOO", deleteLinkStructureTagSaga);
30
- }).toThrow();
31
- });
32
- });
33
-
34
- describe("sagas: deleteLinkStructureTagSaga", () => {
35
- const payload = { structureId: 1, tagId: 2 };
36
- const data = { id: 1 };
37
- const { structureId: data_structure_id, tagId: id } = payload;
38
- const url = compile(API_STRUCTURES_TAG)({ data_structure_id, id });
39
-
40
- it("should put a success action when a response is returned", () => {
41
- expect(() => {
42
- testSaga(deleteLinkStructureTagSaga, { payload })
43
- .next()
44
- .put(deleteLinkStructureTag.request())
45
- .next()
46
- .call(apiJsonDelete, url, JSON_OPTS)
47
- .next({ data })
48
- .put(deleteLinkStructureTag.success(data))
49
- .next()
50
- .put(fetchLinksStructureTags.trigger(payload))
51
- .next()
52
- .put(deleteLinkStructureTag.fulfill())
53
- .next()
54
- .isDone();
55
- }).not.toThrow();
56
- });
57
-
58
- it("should put a failure action when the call returns an error with message", () => {
59
- const message = "Request failed";
60
- const error = { message };
61
-
62
- expect(() => {
63
- testSaga(deleteLinkStructureTagSaga, { payload })
64
- .next()
65
- .put(deleteLinkStructureTag.request())
66
- .next()
67
- .call(apiJsonDelete, url, JSON_OPTS)
68
- .throw(error)
69
- .put(deleteLinkStructureTag.failure(message))
70
- .next()
71
- .put(deleteLinkStructureTag.fulfill())
72
- .next()
73
- .isDone();
74
- }).not.toThrow();
75
- });
76
-
77
- it("should put a failure action when the call returns an error with response", () => {
78
- const status = "foo";
79
- const data = "bar";
80
- const error = { response: { status, data } };
81
-
82
- expect(() => {
83
- testSaga(deleteLinkStructureTagSaga, { payload })
84
- .next()
85
- .put(deleteLinkStructureTag.request())
86
- .next()
87
- .call(apiJsonDelete, url, JSON_OPTS)
88
- .throw(error)
89
- .put(deleteLinkStructureTag.failure({ status, data }))
90
- .next()
91
- .put(deleteLinkStructureTag.fulfill())
92
- .next()
93
- .isDone();
94
- }).not.toThrow();
95
- });
96
- });
@@ -1,105 +0,0 @@
1
- import { compile } from "path-to-regexp";
2
- import { testSaga } from "redux-saga-test-plan";
3
- import { apiJson, JSON_OPTS } from "@truedat/core/services/api";
4
- import {
5
- fetchLinksStructureTagsRequestSaga,
6
- fetchLinksStructureTagsSaga
7
- } from "../fetchLinksStructureTags";
8
- import { fetchLinksStructureTags } from "../../routines";
9
- import { API_STRUCTURES_TAGS } from "../../api";
10
-
11
- describe("sagas: fetchLinksStructureTagsRequestSaga", () => {
12
- it("should invoke fetchLinksStructureTagsSaga on trigger", () => {
13
- expect(() => {
14
- testSaga(fetchLinksStructureTagsRequestSaga)
15
- .next()
16
- .takeLatest(
17
- fetchLinksStructureTags.TRIGGER,
18
- fetchLinksStructureTagsSaga
19
- )
20
- .finish()
21
- .isDone();
22
- }).not.toThrow();
23
- });
24
-
25
- it("should throw exception if an unhandled action is received", () => {
26
- expect(() => {
27
- testSaga(fetchLinksStructureTagsRequestSaga)
28
- .next()
29
- .takeLatest("FOO", fetchLinksStructureTags);
30
- }).toThrow();
31
- });
32
- });
33
-
34
- describe("sagas: fetchLinksStructureTagsSaga", () => {
35
- const payload = { structureId: 1 };
36
- const { structureId: data_structure_id } = payload;
37
- const data = [
38
- {
39
- id: 1,
40
- description: "foo",
41
- inserted_at: "foo",
42
- updated_at: "foo",
43
- _embedded: {
44
- data_structure: { id: 1, external_id: "baz" },
45
- data_structure_tag: { id: 1, name: "bar" }
46
- }
47
- }
48
- ];
49
- const url = compile(API_STRUCTURES_TAGS)({ data_structure_id });
50
-
51
- it("should put a success action when a response is returned", () => {
52
- expect(() => {
53
- testSaga(fetchLinksStructureTagsSaga, { payload })
54
- .next()
55
- .put(fetchLinksStructureTags.request())
56
- .next()
57
- .call(apiJson, url, JSON_OPTS)
58
- .next({ data })
59
- .put(fetchLinksStructureTags.success(data))
60
- .next()
61
- .put(fetchLinksStructureTags.fulfill())
62
- .next()
63
- .isDone();
64
- }).not.toThrow();
65
- });
66
-
67
- it("should put a failure action when the call returns an error with message", () => {
68
- const message = "Request failed";
69
- const error = { message };
70
-
71
- expect(() => {
72
- testSaga(fetchLinksStructureTagsSaga, { payload })
73
- .next()
74
- .put(fetchLinksStructureTags.request())
75
- .next()
76
- .call(apiJson, url, JSON_OPTS)
77
- .throw(error)
78
- .put(fetchLinksStructureTags.failure(message))
79
- .next()
80
- .put(fetchLinksStructureTags.fulfill())
81
- .next()
82
- .isDone();
83
- }).not.toThrow();
84
- });
85
-
86
- it("should put a failure action when the call returns an error with response", () => {
87
- const status = "foo";
88
- const data = "bar";
89
- const error = { response: { status, data } };
90
-
91
- expect(() => {
92
- testSaga(fetchLinksStructureTagsSaga, { payload })
93
- .next()
94
- .put(fetchLinksStructureTags.request())
95
- .next()
96
- .call(apiJson, url, JSON_OPTS)
97
- .throw(error)
98
- .put(fetchLinksStructureTags.failure({ status, data }))
99
- .next()
100
- .put(fetchLinksStructureTags.fulfill())
101
- .next()
102
- .isDone();
103
- }).not.toThrow();
104
- });
105
- });
@@ -1,102 +0,0 @@
1
- import { compile } from "path-to-regexp";
2
- import { testSaga } from "redux-saga-test-plan";
3
- import { apiJsonPatch, JSON_OPTS } from "@truedat/core/services/api";
4
- import {
5
- linkStructureTagRequestSaga,
6
- linkStructureTagSaga
7
- } from "../linkStructureTag";
8
- import { fetchLinksStructureTags, linkStructureTag } from "../../routines";
9
- import { API_STRUCTURES_TAG } from "../../api";
10
-
11
- describe("sagas: linkStructureTagRequestSaga", () => {
12
- it("should invoke linkStructureTagSaga on trigger", () => {
13
- expect(() => {
14
- testSaga(linkStructureTagRequestSaga)
15
- .next()
16
- .takeLatest(linkStructureTag.TRIGGER, linkStructureTagSaga)
17
- .finish()
18
- .isDone();
19
- }).not.toThrow();
20
- });
21
-
22
- it("should throw exception if an unhandled action is received", () => {
23
- expect(() => {
24
- testSaga(linkStructureTagRequestSaga)
25
- .next()
26
- .takeLatest("FOO", linkStructureTagSaga);
27
- }).toThrow();
28
- });
29
- });
30
-
31
- describe("sagas: linkStructureTagSaga", () => {
32
- const tag = { description: "foo" };
33
- const payload = { structureId: 1, tagId: 2, tag };
34
- const { structureId: data_structure_id, tagId: id } = payload;
35
- const url = compile(API_STRUCTURES_TAG)({ data_structure_id, id });
36
- const requestData = { tag };
37
- const data = {
38
- id: 1,
39
- description: "foo",
40
- _embedded: {
41
- data_structure: { id: 1, external_id: "bar" },
42
- data_structure_tag: { id: 2, name: "xyz" }
43
- }
44
- };
45
-
46
- it("should put a success action when a response is returned", () => {
47
- expect(() => {
48
- testSaga(linkStructureTagSaga, { payload })
49
- .next()
50
- .put(linkStructureTag.request())
51
- .next()
52
- .call(apiJsonPatch, url, requestData, JSON_OPTS)
53
- .next({ data })
54
- .put(linkStructureTag.success(data))
55
- .next()
56
- .put(fetchLinksStructureTags.trigger(payload))
57
- .next()
58
- .put(linkStructureTag.fulfill())
59
- .next()
60
- .isDone();
61
- }).not.toThrow();
62
- });
63
-
64
- it("should put a failure action when the call returns an error message", () => {
65
- const message = "Request failed";
66
- const error = { message };
67
-
68
- expect(() => {
69
- testSaga(linkStructureTagSaga, { payload })
70
- .next()
71
- .put(linkStructureTag.request())
72
- .next()
73
- .call(apiJsonPatch, url, requestData, JSON_OPTS)
74
- .throw(error)
75
- .put(linkStructureTag.failure(message))
76
- .next()
77
- .put(linkStructureTag.fulfill())
78
- .next()
79
- .isDone();
80
- }).not.toThrow();
81
- });
82
-
83
- it("should put a failure action when the call returns an error response", () => {
84
- const status = "foo";
85
- const data = "bar";
86
- const error = { response: { status, data } };
87
-
88
- expect(() => {
89
- testSaga(linkStructureTagSaga, { payload })
90
- .next()
91
- .put(linkStructureTag.request())
92
- .next()
93
- .call(apiJsonPatch, url, requestData, JSON_OPTS)
94
- .throw(error)
95
- .put(linkStructureTag.failure({ status, data }))
96
- .next()
97
- .put(linkStructureTag.fulfill())
98
- .next()
99
- .isDone();
100
- }).not.toThrow();
101
- });
102
- });