groupcore-utils 1.2.3 → 1.3.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.
- package/Utils.js +25 -0
- package/Utils.spec.js +38 -12
- package/package.json +1 -1
package/Utils.js
CHANGED
@@ -137,6 +137,31 @@ class Utils {
|
|
137
137
|
return { error: 'API error' };
|
138
138
|
}
|
139
139
|
}
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Get content from the Core content management system, by section
|
143
|
+
* @param {number} groupId - The ID of the Core inventory group
|
144
|
+
* @returns {Object.<{error: string}>|Promise.<Object>} - Returns an error or a promise that resolves to an object
|
145
|
+
*/
|
146
|
+
async getSectionContent({ groupId }) {
|
147
|
+
if (_isUndefined(groupId)) {
|
148
|
+
return { error: 'Missing some required params' };
|
149
|
+
}
|
150
|
+
|
151
|
+
try {
|
152
|
+
const response = await axios({
|
153
|
+
method: 'GET',
|
154
|
+
url: `${this.apiUrl}/cms/sections?group=${groupId}`,
|
155
|
+
headers: {
|
156
|
+
token: this.token,
|
157
|
+
},
|
158
|
+
});
|
159
|
+
|
160
|
+
return response.data;
|
161
|
+
} catch (e) {
|
162
|
+
return { error: 'API error' };
|
163
|
+
}
|
164
|
+
}
|
140
165
|
}
|
141
166
|
|
142
167
|
module.exports = Utils;
|
package/Utils.spec.js
CHANGED
@@ -92,19 +92,21 @@ describe('Testing Utils.addLead()', () => {
|
|
92
92
|
|
93
93
|
describe('Testing Utils.getGroupInventory', () => {
|
94
94
|
it('Should return the right response', async () => {
|
95
|
-
axios.mockResolvedValue(
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
95
|
+
axios.mockResolvedValue({
|
96
|
+
data: [
|
97
|
+
{
|
98
|
+
id: 13,
|
99
|
+
item: '{"item":"test","price":12.34}',
|
100
|
+
inventoryGroup: 6,
|
101
|
+
status: 0,
|
102
|
+
dateAdded: 0,
|
103
|
+
cost: 8,
|
104
|
+
data: {
|
105
|
+
test: 'test',
|
106
|
+
},
|
105
107
|
},
|
106
|
-
|
107
|
-
|
108
|
+
],
|
109
|
+
});
|
108
110
|
|
109
111
|
const response = await util.getGroupInventory({ groupId: 6 });
|
110
112
|
expect(response.id).toEqual(13);
|
@@ -121,3 +123,27 @@ describe('Testing Utils.getGroupInventory', () => {
|
|
121
123
|
expect(response).toEqual({ error: 'API error' });
|
122
124
|
});
|
123
125
|
});
|
126
|
+
|
127
|
+
describe('Testing Utils.getSectionContent', () => {
|
128
|
+
it('Should return the right response', async () => {
|
129
|
+
axios.mockResolvedValue({
|
130
|
+
data: {
|
131
|
+
testLabel: 'this is a test label',
|
132
|
+
},
|
133
|
+
});
|
134
|
+
|
135
|
+
const response = await util.getSectionContent({ groupId: 6 });
|
136
|
+
expect(response.testLabel).toEqual('this is a test label');
|
137
|
+
});
|
138
|
+
|
139
|
+
it('Should validate the group ID param', async () => {
|
140
|
+
const response = await util.getSectionContent({ groups: 6 });
|
141
|
+
expect(response).toEqual({ error: 'Missing some required params' });
|
142
|
+
});
|
143
|
+
|
144
|
+
it('Should catch any errors during API call', async () => {
|
145
|
+
axios.mockRejectedValue();
|
146
|
+
const response = await util.getSectionContent({ groupId: 6 });
|
147
|
+
expect(response).toEqual({ error: 'API error' });
|
148
|
+
});
|
149
|
+
});
|