@dhis2/app-service-data 3.2.4 → 3.2.8
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/build/cjs/__tests__/integration.test.js +19 -45
- package/build/cjs/__tests__/mutations.test.js +55 -64
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +18 -8
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +38 -10
- package/build/cjs/react/hooks/useDataMutation.test.js +320 -52
- package/build/cjs/react/hooks/useDataQuery.js +16 -9
- package/build/cjs/react/hooks/useDataQuery.test.js +143 -0
- package/build/es/__tests__/integration.test.js +19 -45
- package/build/es/__tests__/mutations.test.js +53 -64
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +13 -6
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +39 -11
- package/build/es/react/hooks/useDataMutation.test.js +315 -50
- package/build/es/react/hooks/useDataQuery.js +17 -10
- package/build/es/react/hooks/useDataQuery.test.js +143 -0
- package/build/types/links/RestAPILink/queryToRequestOptions/textPlainMatchers.d.ts +2 -1
- package/package.json +2 -2
|
@@ -10,8 +10,8 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
|
|
|
10
10
|
|
|
11
11
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
12
|
|
|
13
|
-
describe('
|
|
14
|
-
it('
|
|
13
|
+
describe('<DataQuery />', () => {
|
|
14
|
+
it('should render without failing', async () => {
|
|
15
15
|
const data = {
|
|
16
16
|
answer: 42
|
|
17
17
|
};
|
|
@@ -22,18 +22,8 @@ describe('Testing custom data provider and useQuery hook', () => {
|
|
|
22
22
|
data: data
|
|
23
23
|
}, children);
|
|
24
24
|
|
|
25
|
-
const renderFunction = jest.fn((
|
|
26
|
-
|
|
27
|
-
error,
|
|
28
|
-
data
|
|
29
|
-
}) => {
|
|
30
|
-
if (loading) return 'loading';
|
|
31
|
-
if (error) return /*#__PURE__*/React.createElement("div", null, "error: ", error.message);
|
|
32
|
-
return /*#__PURE__*/React.createElement("div", null, "data: ", data && data.answer);
|
|
33
|
-
});
|
|
34
|
-
const {
|
|
35
|
-
getByText
|
|
36
|
-
} = (0, _react.render)( /*#__PURE__*/React.createElement(_react3.DataQuery, {
|
|
25
|
+
const renderFunction = jest.fn(() => null);
|
|
26
|
+
(0, _react.render)( /*#__PURE__*/React.createElement(_react3.DataQuery, {
|
|
37
27
|
query: {
|
|
38
28
|
answer: {
|
|
39
29
|
resource: 'answer'
|
|
@@ -42,24 +32,21 @@ describe('Testing custom data provider and useQuery hook', () => {
|
|
|
42
32
|
}, renderFunction), {
|
|
43
33
|
wrapper
|
|
44
34
|
});
|
|
45
|
-
expect(getByText(/loading/i)).not.toBeUndefined();
|
|
46
35
|
expect(renderFunction).toHaveBeenCalledTimes(1);
|
|
47
36
|
expect(renderFunction).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
48
37
|
called: true,
|
|
49
38
|
loading: true
|
|
50
39
|
}));
|
|
51
40
|
await (0, _react.waitFor)(() => {
|
|
52
|
-
|
|
41
|
+
expect(renderFunction).toHaveBeenCalledTimes(2);
|
|
42
|
+
expect(renderFunction).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
43
|
+
called: true,
|
|
44
|
+
loading: false,
|
|
45
|
+
data
|
|
46
|
+
}));
|
|
53
47
|
});
|
|
54
|
-
expect(getByText(/data: /i)).toHaveTextContent("data: ".concat(data.answer));
|
|
55
|
-
expect(renderFunction).toHaveBeenCalledTimes(2);
|
|
56
|
-
expect(renderFunction).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
57
|
-
called: true,
|
|
58
|
-
loading: false,
|
|
59
|
-
data
|
|
60
|
-
}));
|
|
61
48
|
});
|
|
62
|
-
it('
|
|
49
|
+
it('should render an error', async () => {
|
|
63
50
|
const expectedError = new Error('Something went wrong');
|
|
64
51
|
const data = {
|
|
65
52
|
test: () => {
|
|
@@ -73,18 +60,8 @@ describe('Testing custom data provider and useQuery hook', () => {
|
|
|
73
60
|
data: data
|
|
74
61
|
}, children);
|
|
75
62
|
|
|
76
|
-
const renderFunction = jest.fn((
|
|
77
|
-
|
|
78
|
-
error,
|
|
79
|
-
data
|
|
80
|
-
}) => {
|
|
81
|
-
if (loading) return 'loading';
|
|
82
|
-
if (error) return /*#__PURE__*/React.createElement("div", null, "error: ", error.message);
|
|
83
|
-
return /*#__PURE__*/React.createElement("div", null, "data: ", data && data.test);
|
|
84
|
-
});
|
|
85
|
-
const {
|
|
86
|
-
getByText
|
|
87
|
-
} = (0, _react.render)( /*#__PURE__*/React.createElement(_react3.DataQuery, {
|
|
63
|
+
const renderFunction = jest.fn(() => null);
|
|
64
|
+
(0, _react.render)( /*#__PURE__*/React.createElement(_react3.DataQuery, {
|
|
88
65
|
query: {
|
|
89
66
|
test: {
|
|
90
67
|
resource: 'test'
|
|
@@ -93,21 +70,18 @@ describe('Testing custom data provider and useQuery hook', () => {
|
|
|
93
70
|
}, renderFunction), {
|
|
94
71
|
wrapper
|
|
95
72
|
});
|
|
96
|
-
expect(getByText(/loading/i)).not.toBeUndefined();
|
|
97
73
|
expect(renderFunction).toHaveBeenCalledTimes(1);
|
|
98
74
|
expect(renderFunction).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
99
75
|
called: true,
|
|
100
76
|
loading: true
|
|
101
77
|
}));
|
|
102
78
|
await (0, _react.waitFor)(() => {
|
|
103
|
-
|
|
79
|
+
expect(renderFunction).toHaveBeenCalledTimes(2);
|
|
80
|
+
expect(renderFunction).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
81
|
+
called: true,
|
|
82
|
+
loading: false,
|
|
83
|
+
error: expectedError
|
|
84
|
+
}));
|
|
104
85
|
});
|
|
105
|
-
expect(renderFunction).toHaveBeenCalledTimes(2);
|
|
106
|
-
expect(getByText(/error: /i)).toHaveTextContent("error: ".concat(expectedError.message));
|
|
107
|
-
expect(renderFunction).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
108
|
-
called: true,
|
|
109
|
-
loading: false,
|
|
110
|
-
error: expectedError
|
|
111
|
-
}));
|
|
112
86
|
});
|
|
113
87
|
});
|
|
@@ -2,82 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var React = _interopRequireWildcard(require("react"));
|
|
6
6
|
|
|
7
7
|
var _react3 = require("../react");
|
|
8
8
|
|
|
9
|
-
function
|
|
9
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return Promise.resolve({
|
|
19
|
-
answer: 42
|
|
20
|
-
});
|
|
21
|
-
})
|
|
22
|
-
};
|
|
23
|
-
describe('Test mutations', () => {
|
|
24
|
-
it('Should call the mock callback', async () => {
|
|
25
|
-
let doMutation;
|
|
26
|
-
const renderFunction = jest.fn(([mutate, {
|
|
27
|
-
called,
|
|
28
|
-
loading,
|
|
29
|
-
error,
|
|
30
|
-
data
|
|
31
|
-
}]) => {
|
|
32
|
-
doMutation = mutate;
|
|
33
|
-
if (!called) return 'uncalled';
|
|
34
|
-
if (loading) return 'loading';
|
|
35
|
-
if (error) return /*#__PURE__*/_react2.default.createElement("div", null, "error: ", error.message);
|
|
36
|
-
if (data) return /*#__PURE__*/_react2.default.createElement("div", null, "data: ", data.answer);
|
|
37
|
-
});
|
|
38
|
-
const testMutation = {
|
|
39
|
-
resource: 'target',
|
|
11
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
+
|
|
13
|
+
describe('<DataMutation />', () => {
|
|
14
|
+
it('should render without failing', async () => {
|
|
15
|
+
const endpointSpy = jest.fn(() => Promise.resolve(42));
|
|
16
|
+
const mutation = {
|
|
17
|
+
resource: 'answer',
|
|
40
18
|
type: 'create',
|
|
41
19
|
data: {
|
|
42
20
|
question: '?'
|
|
43
21
|
}
|
|
44
22
|
};
|
|
45
|
-
const {
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
23
|
+
const data = {
|
|
24
|
+
answer: endpointSpy
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const wrapper = ({
|
|
28
|
+
children
|
|
29
|
+
}) => /*#__PURE__*/React.createElement(_react3.CustomDataProvider, {
|
|
30
|
+
data: data
|
|
31
|
+
}, children);
|
|
32
|
+
|
|
33
|
+
const renderSpy = jest.fn(() => null);
|
|
34
|
+
(0, _react.render)( /*#__PURE__*/React.createElement(_react3.DataMutation, {
|
|
35
|
+
mutation: mutation
|
|
36
|
+
}, renderSpy), {
|
|
37
|
+
wrapper
|
|
38
|
+
});
|
|
39
|
+
expect(endpointSpy).toHaveBeenCalledTimes(0);
|
|
40
|
+
expect(renderSpy).toHaveBeenCalledTimes(1);
|
|
41
|
+
expect(renderSpy).toHaveBeenLastCalledWith([expect.any(Function), expect.objectContaining({
|
|
56
42
|
called: false,
|
|
57
43
|
loading: false,
|
|
58
44
|
engine: expect.any(Object)
|
|
59
|
-
}]);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
})]);
|
|
46
|
+
await (0, _react.act)(async () => {
|
|
47
|
+
const firstRenderSpyCall = renderSpy.mock.calls[0];
|
|
48
|
+
const firstRenderSpyArgument = firstRenderSpyCall[0];
|
|
49
|
+
const [mutate] = firstRenderSpyArgument;
|
|
50
|
+
await mutate();
|
|
51
|
+
});
|
|
52
|
+
(0, _react.waitFor)(() => {
|
|
53
|
+
expect(endpointSpy).toHaveBeenCalledTimes(1);
|
|
54
|
+
expect(renderSpy).toHaveBeenCalledTimes(2);
|
|
55
|
+
expect(renderSpy).toHaveBeenLastCalledWith([expect.any(Function), expect.objectContaining({
|
|
56
|
+
called: true,
|
|
57
|
+
loading: true,
|
|
58
|
+
engine: expect.any(Object)
|
|
59
|
+
})]);
|
|
60
|
+
});
|
|
61
|
+
(0, _react.waitFor)(() => {
|
|
62
|
+
expect(endpointSpy).toHaveBeenCalledTimes(1);
|
|
63
|
+
expect(renderSpy).toHaveBeenCalledTimes(3);
|
|
64
|
+
expect(renderSpy).toHaveBeenLastCalledWith([expect.any(Function), expect.objectContaining({
|
|
65
|
+
called: true,
|
|
66
|
+
loading: false,
|
|
67
|
+
data: {
|
|
68
|
+
answer: 42
|
|
69
|
+
},
|
|
70
|
+
engine: expect.any(Object)
|
|
71
|
+
})]);
|
|
63
72
|
});
|
|
64
|
-
expect(renderFunction).toHaveBeenCalledTimes(2);
|
|
65
|
-
expect(renderFunction).toHaveBeenLastCalledWith([doMutation, {
|
|
66
|
-
called: true,
|
|
67
|
-
loading: true,
|
|
68
|
-
engine: expect.any(Object)
|
|
69
|
-
}]);
|
|
70
|
-
expect(mockBackend.target).toHaveBeenCalledTimes(1);
|
|
71
|
-
await (0, _react.waitFor)(() => getByText(/data: /i));
|
|
72
|
-
expect(renderFunction).toHaveBeenCalledTimes(3);
|
|
73
|
-
expect(renderFunction).toHaveBeenLastCalledWith([doMutation, {
|
|
74
|
-
called: true,
|
|
75
|
-
loading: false,
|
|
76
|
-
data: {
|
|
77
|
-
answer: 42
|
|
78
|
-
},
|
|
79
|
-
engine: expect.any(Object)
|
|
80
|
-
}]);
|
|
81
|
-
expect(getByText(/data: /i)).toHaveTextContent("data: 42");
|
|
82
73
|
});
|
|
83
74
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isMetadataPackageInstallation = exports.addOrUpdateConfigurationProperty = exports.isAddOrUpdateSystemOrUserSetting = exports.isInterpretationCommentUpdate = exports.isCommentOnInterpretation = exports.
|
|
6
|
+
exports.isMetadataPackageInstallation = exports.addOrUpdateConfigurationProperty = exports.isAddOrUpdateSystemOrUserSetting = exports.isInterpretationCommentUpdate = exports.isCommentOnInterpretation = exports.isUpdateInterpretation = exports.isCreateInterpretation = exports.isCreateFeedbackMessage = exports.isReplyToMessageConversation = void 0;
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
* Requests that expect a "text/plain" Content-Type have been collected by scanning
|
|
@@ -28,33 +28,43 @@ exports.isReplyToMessageConversation = isReplyToMessageConversation;
|
|
|
28
28
|
|
|
29
29
|
const isCreateFeedbackMessage = (type, {
|
|
30
30
|
resource
|
|
31
|
-
}) => type === 'create' && resource === 'messageConversations/feedback'; // POST
|
|
31
|
+
}) => type === 'create' && resource === 'messageConversations/feedback'; // POST `interpretations/${objectType}/${id}` (add an interpretation to a visualization)
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
exports.isCreateFeedbackMessage = isCreateFeedbackMessage;
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const isCreateInterpretation = (type, {
|
|
37
|
+
resource
|
|
38
|
+
}) => {
|
|
39
|
+
const pattern = /^interpretations\/(?:reportTable|chart|visualization|map|eventVisualization|eventReport|eventChart|dataSetReport)\/[a-zA-Z0-9]{11}$/;
|
|
40
|
+
return type === 'create' && pattern.test(resource);
|
|
41
|
+
}; // PUT to `interpretations/${id}` (update an interpretation)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
exports.isCreateInterpretation = isCreateInterpretation;
|
|
45
|
+
|
|
46
|
+
const isUpdateInterpretation = (type, {
|
|
37
47
|
resource,
|
|
38
48
|
id
|
|
39
49
|
}) => {
|
|
40
|
-
if (type !== '
|
|
50
|
+
if (type !== 'replace') {
|
|
41
51
|
return false;
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
let resourcePattern;
|
|
45
55
|
|
|
46
|
-
if (
|
|
47
|
-
resourcePattern = /^interpretations
|
|
56
|
+
if (id) {
|
|
57
|
+
resourcePattern = /^interpretations$/;
|
|
48
58
|
const idPattern = /^[a-zA-Z0-9]{11}$/;
|
|
49
59
|
return resourcePattern.test(resource) && idPattern.test(id);
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
resourcePattern = /^interpretations\/
|
|
62
|
+
resourcePattern = /^interpretations\/[a-zA-Z0-9]{11}$/;
|
|
53
63
|
return resourcePattern.test(resource);
|
|
54
64
|
}; // POST to `interpretations/${id}/comments` (comment on an interpretation)
|
|
55
65
|
|
|
56
66
|
|
|
57
|
-
exports.
|
|
67
|
+
exports.isUpdateInterpretation = isUpdateInterpretation;
|
|
58
68
|
|
|
59
69
|
const isCommentOnInterpretation = (type, {
|
|
60
70
|
resource
|
|
@@ -26,30 +26,58 @@ describe('isCreateFeedbackMessage', () => {
|
|
|
26
26
|
})).toEqual(false);
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
|
-
describe('
|
|
29
|
+
describe('isCreateInterpretation', () => {
|
|
30
30
|
it('returns true for a POST to "interpretations/chart/${id}"', () => {
|
|
31
|
-
expect((0, _textPlainMatchers.
|
|
31
|
+
expect((0, _textPlainMatchers.isCreateInterpretation)('create', {
|
|
32
32
|
resource: 'interpretations/chart/oXD88WWSQpR'
|
|
33
33
|
})).toEqual(true);
|
|
34
34
|
});
|
|
35
|
-
it('returns
|
|
36
|
-
expect((0, _textPlainMatchers.
|
|
35
|
+
it('returns false for a PUT to "interpretations/chart/${id}"', () => {
|
|
36
|
+
expect((0, _textPlainMatchers.isCreateInterpretation)('replace', {
|
|
37
37
|
resource: 'interpretations/chart/oXD88WWSQpR'
|
|
38
|
+
})).toEqual(false);
|
|
39
|
+
});
|
|
40
|
+
it('retuns false for PATCH requests with a valid query', () => {
|
|
41
|
+
expect((0, _textPlainMatchers.isCreateInterpretation)('update', {
|
|
42
|
+
resource: 'interpretations/chart/oXD88WWSQpR'
|
|
43
|
+
})).toEqual(false);
|
|
44
|
+
});
|
|
45
|
+
it('returns false for a request to a different resource', () => {
|
|
46
|
+
expect((0, _textPlainMatchers.isCreateInterpretation)('create', {
|
|
47
|
+
resource: 'interpretations/dummy/oXD88WWSQpR'
|
|
48
|
+
})).toEqual(false);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('isUpdateInterpretation', () => {
|
|
52
|
+
it('returns true for a PUT to "interpretations/${id}"', () => {
|
|
53
|
+
expect((0, _textPlainMatchers.isUpdateInterpretation)('replace', {
|
|
54
|
+
resource: 'interpretations/oXD88WWSQpR'
|
|
38
55
|
})).toEqual(true);
|
|
39
56
|
});
|
|
40
57
|
it('returns true for PUT with populated query.id', () => {
|
|
41
|
-
expect((0, _textPlainMatchers.
|
|
42
|
-
resource: 'interpretations
|
|
58
|
+
expect((0, _textPlainMatchers.isUpdateInterpretation)('replace', {
|
|
59
|
+
resource: 'interpretations',
|
|
43
60
|
id: 'oXD88WWSQpR'
|
|
44
61
|
})).toEqual(true);
|
|
45
62
|
});
|
|
46
|
-
it('
|
|
47
|
-
expect((0, _textPlainMatchers.
|
|
48
|
-
resource: 'interpretations/
|
|
63
|
+
it('returns false for a POST to "interpretations/${id}"', () => {
|
|
64
|
+
expect((0, _textPlainMatchers.isUpdateInterpretation)('create', {
|
|
65
|
+
resource: 'interpretations/oXD88WWSQpR'
|
|
66
|
+
})).toEqual(false);
|
|
67
|
+
});
|
|
68
|
+
it('returns false for a PATCH to "interpretations/${id}"', () => {
|
|
69
|
+
expect((0, _textPlainMatchers.isUpdateInterpretation)('update', {
|
|
70
|
+
resource: 'interpretations/oXD88WWSQpR'
|
|
71
|
+
})).toEqual(false);
|
|
72
|
+
});
|
|
73
|
+
it('returns false for PATCH with populated query.id', () => {
|
|
74
|
+
expect((0, _textPlainMatchers.isUpdateInterpretation)('update', {
|
|
75
|
+
resource: 'interpretations',
|
|
76
|
+
id: 'oXD88WWSQpR'
|
|
49
77
|
})).toEqual(false);
|
|
50
78
|
});
|
|
51
79
|
it('returns false for a request to a different resource', () => {
|
|
52
|
-
expect((0, _textPlainMatchers.
|
|
80
|
+
expect((0, _textPlainMatchers.isUpdateInterpretation)('create', {
|
|
53
81
|
resource: 'interpretations/dummy/oXD88WWSQpR'
|
|
54
82
|
})).toEqual(false);
|
|
55
83
|
});
|