@truedat/cx 4.41.3 → 4.41.4

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 (108) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/package.json +4 -4
  3. package/src/jobs/components/Job.js +11 -11
  4. package/src/jobs/components/JobRoutes.js +2 -2
  5. package/src/jobs/components/JobRow.js +7 -3
  6. package/src/jobs/components/Jobs.js +16 -28
  7. package/src/jobs/components/JobsTable.js +80 -92
  8. package/src/jobs/components/JobsView.js +23 -0
  9. package/src/jobs/components/SourceJobs.js +29 -0
  10. package/src/jobs/components/__tests__/JobRow.spec.js +44 -23
  11. package/src/jobs/components/__tests__/Jobs.spec.js +33 -8
  12. package/src/jobs/components/__tests__/JobsTable.spec.js +50 -81
  13. package/src/jobs/components/__tests__/JobsView.spec.js +39 -0
  14. package/src/jobs/components/__tests__/SourceJobs.spec.js +38 -0
  15. package/src/jobs/components/__tests__/__snapshots__/Job.spec.js.snap +3 -4
  16. package/src/jobs/components/__tests__/__snapshots__/JobRow.spec.js.snap +40 -32
  17. package/src/jobs/components/__tests__/__snapshots__/Jobs.spec.js.snap +136 -35
  18. package/src/jobs/components/__tests__/__snapshots__/JobsTable.spec.js.snap +104 -227
  19. package/src/jobs/components/__tests__/__snapshots__/JobsView.spec.js.snap +167 -0
  20. package/src/jobs/components/__tests__/__snapshots__/SourceJobs.spec.js.snap +115 -0
  21. package/src/jobs/components/index.js +1 -3
  22. package/src/jobs/selectors/index.js +4 -2
  23. package/src/jobs/selectors/{getJobColumns.js → jobColumnsSelector.js} +11 -27
  24. package/src/jobs/selectors/jobRowsSelector.js +14 -0
  25. package/src/jobs/selectors/sourceJobColumnsSelector.js +35 -0
  26. package/src/messages/en.js +9 -1
  27. package/src/messages/es.js +9 -1
  28. package/src/reducers/cxMessage.js +15 -1
  29. package/src/sources/api/fragments.js +48 -0
  30. package/src/sources/api/mutations.js +51 -0
  31. package/src/sources/api/queries.js +52 -0
  32. package/src/sources/api.js +1 -2
  33. package/src/sources/components/EditSource.js +5 -29
  34. package/src/sources/components/JobForm.js +2 -2
  35. package/src/sources/components/NewJob.js +10 -23
  36. package/src/sources/components/Source.js +12 -76
  37. package/src/sources/components/SourceActions.js +13 -21
  38. package/src/sources/components/SourceBreadcrumbs.js +1 -1
  39. package/src/sources/components/SourceConfiguration.js +60 -0
  40. package/src/sources/components/SourceDetail.js +90 -0
  41. package/src/sources/components/SourceForm.js +50 -53
  42. package/src/sources/components/SourceHeader.js +29 -0
  43. package/src/sources/components/SourceRoutes.js +25 -89
  44. package/src/sources/components/SourceSelector.js +53 -44
  45. package/src/sources/components/SourceTabs.js +54 -0
  46. package/src/sources/components/Sources.js +7 -20
  47. package/src/sources/components/SourcesTable.js +3 -4
  48. package/src/sources/components/__tests__/EditSource.spec.js +1 -2
  49. package/src/sources/components/__tests__/Source.spec.js +1 -1
  50. package/src/sources/components/__tests__/SourceActions.spec.js +3 -1
  51. package/src/sources/components/__tests__/SourceDetail.spec.js +45 -0
  52. package/src/sources/components/__tests__/SourceForm.spec.js +16 -31
  53. package/src/sources/components/__tests__/SourceHeader.spec.js +16 -0
  54. package/src/sources/components/__tests__/SourceSelector.spec.js +44 -0
  55. package/src/sources/components/__tests__/SourceTabs.spec.js +21 -0
  56. package/src/sources/components/__tests__/Sources.spec.js +5 -2
  57. package/src/sources/components/__tests__/__snapshots__/EditSource.spec.js.snap +12 -35
  58. package/src/sources/components/__tests__/__snapshots__/NewSource.spec.js.snap +1 -1
  59. package/src/sources/components/__tests__/__snapshots__/Source.spec.js.snap +23 -65
  60. package/src/sources/components/__tests__/__snapshots__/SourceActions.spec.js.snap +1 -1
  61. package/src/sources/components/__tests__/__snapshots__/SourceDetail.spec.js.snap +154 -0
  62. package/src/sources/components/__tests__/__snapshots__/SourceForm.spec.js.snap +37 -14
  63. package/src/sources/components/__tests__/__snapshots__/SourceHeader.spec.js.snap +85 -0
  64. package/src/sources/components/__tests__/__snapshots__/SourceSelector.spec.js.snap +68 -0
  65. package/src/sources/components/__tests__/__snapshots__/SourceTabs.spec.js.snap +22 -0
  66. package/src/sources/components/__tests__/__snapshots__/Sources.spec.js.snap +2 -2
  67. package/src/sources/components/__tests__/__snapshots__/SourcesTable.spec.js.snap +5 -5
  68. package/src/sources/components/index.js +1 -4
  69. package/src/sources/reducers/__tests__/sourceRedirect.spec.js +26 -21
  70. package/src/sources/reducers/__tests__/sourceUpdateStatus.spec.js +9 -9
  71. package/src/sources/reducers/index.js +1 -12
  72. package/src/sources/reducers/sourceRedirect.js +20 -10
  73. package/src/sources/reducers/sourceUpdateStatus.js +5 -5
  74. package/src/sources/routines.js +0 -3
  75. package/src/sources/sagas/__tests__/createSource.spec.js +35 -20
  76. package/src/sources/sagas/__tests__/deleteSource.spec.js +29 -14
  77. package/src/sources/sagas/__tests__/disableSource.spec.js +2 -8
  78. package/src/sources/sagas/__tests__/enableSource.spec.js +2 -8
  79. package/src/sources/sagas/__tests__/updateSource.spec.js +33 -15
  80. package/src/sources/sagas/createSource.js +24 -14
  81. package/src/sources/sagas/deleteSource.js +14 -15
  82. package/src/sources/sagas/disableSource.js +1 -17
  83. package/src/sources/sagas/enableSource.js +1 -17
  84. package/src/sources/sagas/index.js +0 -9
  85. package/src/sources/sagas/updateSource.js +18 -15
  86. package/src/sources/components/DynamicSourceForm.js +0 -60
  87. package/src/sources/components/SourceLoader.js +0 -59
  88. package/src/sources/components/SourcesLoader.js +0 -39
  89. package/src/sources/components/__tests__/DynamicSourceForm.spec.js +0 -89
  90. package/src/sources/components/__tests__/SourceLoader.spec.js +0 -54
  91. package/src/sources/components/__tests__/SourcesLoader.spec.js +0 -53
  92. package/src/sources/components/__tests__/__snapshots__/DynamicSourceForm.spec.js.snap +0 -8
  93. package/src/sources/components/__tests__/__snapshots__/SourceLoader.spec.js.snap +0 -3
  94. package/src/sources/components/__tests__/__snapshots__/SourcesLoader.spec.js.snap +0 -3
  95. package/src/sources/reducers/__tests__/source.spec.js +0 -44
  96. package/src/sources/reducers/__tests__/sourceLoading.spec.js +0 -30
  97. package/src/sources/reducers/__tests__/sources.spec.js +0 -37
  98. package/src/sources/reducers/__tests__/sourcesLoading.spec.js +0 -30
  99. package/src/sources/reducers/source.js +0 -35
  100. package/src/sources/reducers/sourceLoading.js +0 -16
  101. package/src/sources/reducers/sources.js +0 -28
  102. package/src/sources/reducers/sourcesLoading.js +0 -16
  103. package/src/sources/sagas/__tests__/fetchSource.spec.js +0 -71
  104. package/src/sources/sagas/__tests__/fetchSources.spec.js +0 -69
  105. package/src/sources/sagas/__tests__/updateSourceConfig.spec.js +0 -73
  106. package/src/sources/sagas/fetchSource.js +0 -30
  107. package/src/sources/sagas/fetchSources.js +0 -26
  108. package/src/sources/sagas/updateSourceConfig.js +0 -29
@@ -1,59 +0,0 @@
1
- import React from "react";
2
- import { withRouter } from "react-router-dom";
3
- import PropTypes from "prop-types";
4
- import { compose } from "redux";
5
- import { connect } from "react-redux";
6
- import { Loading } from "@truedat/core/components";
7
- import { clearSource, fetchSource } from "../routines";
8
-
9
- export class SourceLoader extends React.Component {
10
- static propTypes = {
11
- fetchSource: PropTypes.func.isRequired,
12
- clearSource: PropTypes.func.isRequired,
13
- match: PropTypes.object.isRequired,
14
- sourceLoading: PropTypes.bool.isRequired,
15
- };
16
-
17
- componentDidMount() {
18
- const { clearSource, fetchSource, match } = this.props;
19
- if (match) {
20
- const { external_id } = match.params;
21
- if (external_id) {
22
- fetchSource({ external_id });
23
- } else {
24
- clearSource();
25
- }
26
- }
27
- }
28
-
29
- componentDidUpdate(prevProps) {
30
- const { clearSource, fetchSource, match } = this.props;
31
- if (match) {
32
- const { external_id } = match.params;
33
- if (prevProps.match.params.external_id !== external_id) {
34
- if (external_id) {
35
- fetchSource({ external_id });
36
- } else {
37
- clearSource();
38
- }
39
- }
40
- }
41
- }
42
-
43
- componentWillUnmount() {
44
- const { clearSource } = this.props;
45
- clearSource();
46
- }
47
-
48
- render() {
49
- const { sourceLoading } = this.props;
50
- return sourceLoading ? <Loading /> : null;
51
- }
52
- }
53
-
54
- const mapStateToProps = ({ sourceLoading }) => ({ sourceLoading });
55
-
56
- export default compose(
57
- withRouter,
58
- connect(mapStateToProps, { clearSource, fetchSource })
59
- )(SourceLoader);
@@ -1,39 +0,0 @@
1
- import React from "react";
2
- import PropTypes from "prop-types";
3
- import { connect } from "react-redux";
4
- import { Loading } from "@truedat/core/components";
5
- import { fetchSources, clearSources } from "../routines";
6
-
7
- export class SourcesLoader extends React.Component {
8
- static propTypes = {
9
- fetchSources: PropTypes.func,
10
- clearSources: PropTypes.func,
11
- sourcesLoading: PropTypes.bool,
12
- };
13
-
14
- componentDidMount() {
15
- const { fetchSources } = this.props;
16
- fetchSources();
17
- }
18
-
19
- componentWillUnmount() {
20
- const { clearSources } = this.props;
21
- clearSources();
22
- }
23
-
24
- render() {
25
- const { sourcesLoading } = this.props;
26
-
27
- if (sourcesLoading) {
28
- return <Loading />;
29
- } else {
30
- return null;
31
- }
32
- }
33
- }
34
-
35
- export const mapStateToProps = ({ sourcesLoading }) => ({ sourcesLoading });
36
-
37
- export default connect(mapStateToProps, { clearSources, fetchSources })(
38
- SourcesLoader
39
- );
@@ -1,89 +0,0 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
3
- import { DynamicSourceForm } from "../DynamicSourceForm";
4
-
5
- describe("<DynamicSourceForm />", () => {
6
- const selectTemplate = jest.fn();
7
- const source = {
8
- external_id: "Micro1",
9
- config: { a: 1 },
10
- type: "micro"
11
- };
12
- const template = {
13
- content: [
14
- {
15
- cardinality: "1",
16
- disabled: true,
17
- group: "New Group 1",
18
- label: "a",
19
- name: "a",
20
- type: "string",
21
- widget: "string"
22
- }
23
- ],
24
- id: 36,
25
- label: "app-admin",
26
- name: "micro",
27
- scope: "cx"
28
- };
29
- const templates = [
30
- {
31
- content: [
32
- {
33
- cardinality: "1",
34
- disabled: true,
35
- group: "New Group 1",
36
- label: "a",
37
- name: "a",
38
- type: "string",
39
- widget: "string"
40
- }
41
- ],
42
- id: 36,
43
- label: "app-admin",
44
- name: "micro",
45
- scope: "cx"
46
- },
47
- {
48
- content: [
49
- {
50
- cardinality: "*",
51
- disabled: true,
52
- group: "New Group 1",
53
- label: "url",
54
- name: "url_cx",
55
- type: "url",
56
- widget: "pair_list"
57
- },
58
- {
59
- cardinality: "?",
60
- disabled: true,
61
- group: "New Group 1",
62
- label: "a",
63
- name: "a",
64
- type: "string",
65
- widget: "string"
66
- },
67
- {
68
- cardinality: "+",
69
- disabled: true,
70
- group: "New Group 1",
71
- label: "lista",
72
- name: "lista",
73
- type: "string",
74
- widget: "string"
75
- }
76
- ],
77
- id: 35,
78
- label: "a",
79
- name: "a",
80
- scope: "cx"
81
- }
82
- ];
83
- const props = { selectTemplate, source, template, templates };
84
-
85
- it("matches the latest snapshot", () => {
86
- const wrapper = shallow(<DynamicSourceForm {...props} />);
87
- expect(wrapper).toMatchSnapshot();
88
- });
89
- });
@@ -1,54 +0,0 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
3
- import { SourceLoader } from "../SourceLoader";
4
-
5
- describe("<SourceLoader />", () => {
6
- const sourceLoading = false;
7
- const fetchSource = jest.fn();
8
- const clearSource = jest.fn();
9
- const match = { params: { external_id: 1 } };
10
-
11
- it("matches the latest snapshot", () => {
12
- const sourceLoading = true;
13
- const props = { clearSource, fetchSource, sourceLoading, match };
14
- const wrapper = shallow(<SourceLoader {...props} />);
15
- expect(wrapper).toMatchSnapshot();
16
- });
17
-
18
- it("renders a loader if sourceLoading is true", () => {
19
- const sourceLoading = true;
20
- const props = { clearSource, fetchSource, sourceLoading, match };
21
- const wrapper = shallow(<SourceLoader {...props} />);
22
- expect(wrapper.find("Loading").length).toBe(1);
23
- });
24
-
25
- it("renders null if sourceLoading is false", () => {
26
- const props = { clearSource, fetchSource, sourceLoading, match };
27
- const wrapper = shallow(<SourceLoader {...props} />);
28
- expect(wrapper.getElement()).toBeNull();
29
- });
30
-
31
- it("calls fetchSource when component mounts but not when it unmounts", () => {
32
- const fetchSource = jest.fn();
33
- const props = { clearSource, fetchSource, sourceLoading, match };
34
- jest.spyOn(SourceLoader.prototype, "componentDidMount");
35
- const wrapper = shallow(<SourceLoader {...props} />);
36
- expect(SourceLoader.prototype.componentDidMount.mock.calls.length).toBe(1);
37
- expect(fetchSource.mock.calls.length).toBe(1);
38
- wrapper.unmount();
39
- expect(fetchSource.mock.calls.length).toBe(1);
40
- });
41
-
42
- it("calls clearSource when component unmounts but not when it mounts", () => {
43
- const clearSource = jest.fn();
44
- const props = { clearSource, fetchSource, sourceLoading, match };
45
- jest.spyOn(SourceLoader.prototype, "componentWillUnmount");
46
- const wrapper = shallow(<SourceLoader {...props} />);
47
- expect(clearSource.mock.calls.length).toBe(0);
48
- wrapper.unmount();
49
- expect(SourceLoader.prototype.componentWillUnmount.mock.calls.length).toBe(
50
- 1
51
- );
52
- expect(clearSource.mock.calls.length).toBe(1);
53
- });
54
- });
@@ -1,53 +0,0 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
3
- import { SourcesLoader } from "../SourcesLoader";
4
-
5
- describe("<SourcesLoader />", () => {
6
- const sourcesLoading = false;
7
- const fetchSources = jest.fn();
8
- const clearSources = jest.fn();
9
-
10
- it("matches the latest snapshot", () => {
11
- const sourcesLoading = true;
12
- const props = { clearSources, fetchSources, sourcesLoading };
13
- const wrapper = shallow(<SourcesLoader {...props} />);
14
- expect(wrapper).toMatchSnapshot();
15
- });
16
-
17
- it("renders a loader if sourcesLoading is true", () => {
18
- const sourcesLoading = true;
19
- const props = { clearSources, fetchSources, sourcesLoading };
20
- const wrapper = shallow(<SourcesLoader {...props} />);
21
- expect(wrapper.find("Loading").length).toBe(1);
22
- });
23
-
24
- it("renders null if sourcesLoading is false", () => {
25
- const props = { clearSources, fetchSources, sourcesLoading };
26
- const wrapper = shallow(<SourcesLoader {...props} />);
27
- expect(wrapper.getElement()).toBeNull();
28
- });
29
-
30
- it("calls fetchSources when component mounts but not when it unmounts", () => {
31
- const fetchSources = jest.fn();
32
- const props = { clearSources, fetchSources, sourcesLoading };
33
- jest.spyOn(SourcesLoader.prototype, "componentDidMount");
34
- const wrapper = shallow(<SourcesLoader {...props} />);
35
- expect(SourcesLoader.prototype.componentDidMount.mock.calls.length).toBe(1);
36
- expect(fetchSources.mock.calls.length).toBe(1);
37
- wrapper.unmount();
38
- expect(fetchSources.mock.calls.length).toBe(1);
39
- });
40
-
41
- it("calls clearSources when component unmounts but not when it mounts", () => {
42
- const clearSources = jest.fn();
43
- const props = { clearSources, fetchSources, sourcesLoading };
44
- jest.spyOn(SourcesLoader.prototype, "componentWillUnmount");
45
- const wrapper = shallow(<SourcesLoader {...props} />);
46
- expect(clearSources.mock.calls.length).toBe(0);
47
- wrapper.unmount();
48
- expect(SourcesLoader.prototype.componentWillUnmount.mock.calls.length).toBe(
49
- 1
50
- );
51
- expect(clearSources.mock.calls.length).toBe(1);
52
- });
53
- });
@@ -1,8 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`<DynamicSourceForm /> matches the latest snapshot 1`] = `
4
- <Fragment>
5
- <lazy />
6
- <lazy />
7
- </Fragment>
8
- `;
@@ -1,3 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`<SourceLoader /> matches the latest snapshot 1`] = `<Loading />`;
@@ -1,3 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`<SourcesLoader /> matches the latest snapshot 1`] = `<Loading />`;
@@ -1,44 +0,0 @@
1
- import { clearSource, fetchSource } from "../../routines";
2
- import { source } from "..";
3
-
4
- const fooState = { foo: "bar" };
5
-
6
- describe("reducers: source", () => {
7
- const initialState = {};
8
-
9
- it("should provide the initial state", () => {
10
- expect(source(undefined, {})).toEqual(initialState);
11
- });
12
-
13
- it("should handle the fetchSource.TRIGGER action", () => {
14
- expect(source(fooState, { type: fetchSource.TRIGGER })).toEqual(
15
- initialState
16
- );
17
- });
18
-
19
- it("should handle the fetchSource.SUCCESS action", () => {
20
- const source_obj = {
21
- external_id: "Micro1",
22
- config: { a: 1 },
23
- type: "micro"
24
- };
25
- expect(
26
- source(fooState, {
27
- type: fetchSource.SUCCESS,
28
- payload: { data: source_obj }
29
- })
30
- ).toMatchObject(source_obj);
31
- });
32
-
33
- it("should handle the clearSource action", () => {
34
- expect(
35
- source(fooState, {
36
- type: clearSource.TRIGGER
37
- })
38
- ).toEqual({});
39
- });
40
-
41
- it("should ignore unknown actions", () => {
42
- expect(source(fooState, { type: "FOO" })).toBe(fooState);
43
- });
44
- });
@@ -1,30 +0,0 @@
1
- import { fetchSource } from "../../routines";
2
- import { sourceLoading } from "..";
3
-
4
- const fooState = { foo: "bar" };
5
-
6
- describe("reducers: source", () => {
7
- const initialState = false;
8
-
9
- it("should provide the initial state", () => {
10
- expect(sourceLoading(undefined, {})).toEqual(initialState);
11
- });
12
-
13
- it("should handle the fetchSource.TRIGGER action", () => {
14
- expect(sourceLoading(fooState, { type: fetchSource.TRIGGER })).toEqual(
15
- true
16
- );
17
- });
18
-
19
- it("should handle the fetchSource.FULFILL action", () => {
20
- expect(
21
- sourceLoading(true, {
22
- type: fetchSource.FULFILL
23
- })
24
- ).toBe(false);
25
- });
26
-
27
- it("should ignore unknown actions", () => {
28
- expect(sourceLoading(fooState, { type: "FOO" })).toBe(fooState);
29
- });
30
- });
@@ -1,37 +0,0 @@
1
- import { fetchSources, clearSources } from "../../routines";
2
- import { sources } from "..";
3
-
4
- const fooState = { foo: "bar" };
5
-
6
- describe("reducers: sources", () => {
7
- const initialState = [];
8
- const data = [
9
- {
10
- external_id: "Micro1",
11
- config: { a: 1 },
12
- type: "micro"
13
- }
14
- ];
15
-
16
- it("should provide the initial state", () => {
17
- expect(sources(undefined, {})).toEqual(initialState);
18
- });
19
-
20
- it("should handle the fetchSources.TRIGGER action", () => {
21
- expect(sources(fooState, { type: fetchSources.TRIGGER })).toEqual(
22
- initialState
23
- );
24
- });
25
-
26
- it("should handle the fetchSources.SUCCESS action", () => {
27
- expect(
28
- sources(fooState, { type: fetchSources.SUCCESS, payload: { data } })
29
- ).toEqual(data);
30
- });
31
-
32
- it("should handle the clearSources.TRIGGER action", () => {
33
- expect(sources(fooState, { type: clearSources.TRIGGER })).toEqual(
34
- initialState
35
- );
36
- });
37
- });
@@ -1,30 +0,0 @@
1
- import { fetchSources } from "../../routines";
2
- import { sourcesLoading } from "..";
3
-
4
- const fooState = { foo: "bar" };
5
-
6
- describe("reducers: source", () => {
7
- const initialState = false;
8
-
9
- it("should provide the initial state", () => {
10
- expect(sourcesLoading(undefined, {})).toEqual(initialState);
11
- });
12
-
13
- it("should handle the fetchSources.TRIGGER action", () => {
14
- expect(sourcesLoading(fooState, { type: fetchSources.TRIGGER })).toEqual(
15
- true
16
- );
17
- });
18
-
19
- it("should handle the fetchSources.FULFILL action", () => {
20
- expect(
21
- sourcesLoading(true, {
22
- type: fetchSources.FULFILL
23
- })
24
- ).toBe(false);
25
- });
26
-
27
- it("should ignore unknown actions", () => {
28
- expect(sourcesLoading(fooState, { type: "FOO" })).toBe(fooState);
29
- });
30
- });
@@ -1,35 +0,0 @@
1
- import _ from "lodash/fp";
2
- import { fetchSource, clearSource, updateSourceConfig } from "../routines";
3
-
4
- const pickFields = _.pick([
5
- "active",
6
- "config",
7
- "external_id",
8
- "id",
9
- "job_types",
10
- "type",
11
- ]);
12
-
13
- const initialState = {};
14
-
15
- const source = (state = initialState, { type, payload }) => {
16
- switch (type) {
17
- case clearSource.TRIGGER:
18
- return initialState;
19
- case fetchSource.TRIGGER:
20
- return initialState;
21
- case fetchSource.SUCCESS: {
22
- const data = _.propOr({}, "data")(payload);
23
- return pickFields(data);
24
- }
25
- case updateSourceConfig.SUCCESS:
26
- const data = _.propOr({}, "data")(payload);
27
- return pickFields(data);
28
- case fetchSource.FAILURE:
29
- return initialState;
30
- default:
31
- return state;
32
- }
33
- };
34
-
35
- export { source };
@@ -1,16 +0,0 @@
1
- import { fetchSource } from "../routines";
2
-
3
- const sourceLoading = (state = false, { type }) => {
4
- switch (type) {
5
- case fetchSource.TRIGGER:
6
- return true;
7
- case fetchSource.REQUEST:
8
- return true;
9
- case fetchSource.FULFILL:
10
- return false;
11
- default:
12
- return state;
13
- }
14
- };
15
-
16
- export { sourceLoading };
@@ -1,28 +0,0 @@
1
- import _ from "lodash/fp";
2
- import { fetchSources, clearSources } from "../routines";
3
-
4
- const pickFields = _.pick(["external_id", "type", "config", "active", "id"]);
5
-
6
- const initialState = [];
7
-
8
- const sources = (state = initialState, { type, payload }) => {
9
- switch (type) {
10
- case clearSources.TRIGGER:
11
- return initialState;
12
- case fetchSources.TRIGGER:
13
- return initialState;
14
- case fetchSources.SUCCESS: {
15
- const data = _.propOr({}, "data")(payload);
16
- return _.flow(
17
- _.map(pickFields),
18
- _.sortBy(s => _.deburr(s.external_id))
19
- )(data);
20
- }
21
- case fetchSources.FAILURE:
22
- return initialState;
23
- default:
24
- return state;
25
- }
26
- };
27
-
28
- export { sources };
@@ -1,16 +0,0 @@
1
- import { fetchSources } from "../routines";
2
-
3
- const sourcesLoading = (state = false, { type }) => {
4
- switch (type) {
5
- case fetchSources.TRIGGER:
6
- return true;
7
- case fetchSources.REQUEST:
8
- return true;
9
- case fetchSources.FULFILL:
10
- return false;
11
- default:
12
- return state;
13
- }
14
- };
15
-
16
- export { sourcesLoading };
@@ -1,71 +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 { fetchSourceRequestSaga, fetchSourceSaga } from "../fetchSource";
5
- import { fetchSource } from "../../routines";
6
- import { API_SOURCE } from "../../api";
7
-
8
- describe("sagas: fetchSourceRequestSaga", () => {
9
- it("should invoke fetchSourceSaga on trigger", () => {
10
- expect(() => {
11
- testSaga(fetchSourceRequestSaga)
12
- .next()
13
- .takeLatest(fetchSource.TRIGGER, fetchSourceSaga)
14
- .finish()
15
- .isDone();
16
- }).not.toThrow();
17
- });
18
-
19
- it("should throw exception if an unhandled action is received", () => {
20
- expect(() => {
21
- testSaga(fetchSourceRequestSaga)
22
- .next()
23
- .takeLatest("FOO", fetchSourceSaga);
24
- }).toThrow();
25
- });
26
- });
27
-
28
- describe("sagas: fetchSourceSaga", () => {
29
- it("should put a success action when a response is returned", () => {
30
- const external_id = "Micro1";
31
- const url = compile(API_SOURCE)({ external_id });
32
- const payload = { external_id };
33
- const data = { type: "Micro", external_id: "Micro1", config: { a: 1 } };
34
-
35
- expect(() => {
36
- testSaga(fetchSourceSaga, { payload })
37
- .next()
38
- .put(fetchSource.request())
39
- .next()
40
- .call(apiJson, url, JSON_OPTS)
41
- .next({ data })
42
- .put(fetchSource.success(data))
43
- .next()
44
- .put(fetchSource.fulfill())
45
- .next()
46
- .isDone();
47
- }).not.toThrow();
48
- });
49
-
50
- it("should put a failure action when the call returns an error", () => {
51
- const message = "Request failed";
52
- const error = { message };
53
- const external_id = "Micro1";
54
- const url = compile(API_SOURCE)({ external_id });
55
- const payload = { external_id };
56
-
57
- expect(() => {
58
- testSaga(fetchSourceSaga, { payload })
59
- .next()
60
- .put(fetchSource.request())
61
- .next()
62
- .call(apiJson, url, JSON_OPTS)
63
- .throw(error)
64
- .put(fetchSource.failure(message))
65
- .next()
66
- .put(fetchSource.fulfill())
67
- .next()
68
- .isDone();
69
- }).not.toThrow();
70
- });
71
- });