groupcore-utils 1.2.0 → 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.
Files changed (3) hide show
  1. package/Utils.js +26 -2
  2. package/Utils.spec.js +38 -12
  3. package/package.json +4 -4
package/Utils.js CHANGED
@@ -119,7 +119,6 @@ class Utils {
119
119
  * @returns {Object.<{error: string}>|Promise.<Object>} - Returns an error or a promise that resolves to an object
120
120
  */
121
121
  async getGroupInventory({ groupId }) {
122
- console.log('group id', groupId);
123
122
  if (_isUndefined(groupId)) {
124
123
  return { error: 'Missing some required params' };
125
124
  }
@@ -133,7 +132,32 @@ class Utils {
133
132
  },
134
133
  });
135
134
 
136
- return response[0];
135
+ return response.data[0];
136
+ } catch (e) {
137
+ return { error: 'API error' };
138
+ }
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;
137
161
  } catch (e) {
138
162
  return { error: 'API error' };
139
163
  }
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
- id: 13,
98
- item: '{"item":"test","price":12.34}',
99
- inventoryGroup: 6,
100
- status: 0,
101
- dateAdded: 0,
102
- cost: 8,
103
- data: {
104
- test: 'test',
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "groupcore-utils",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Utilities for working with some Core features",
5
5
  "main": "Utils.js",
6
6
  "scripts": {
@@ -8,14 +8,14 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/TheGroupC/groupcore-utils.git"
11
+ "url": "https://bitbucket.org/thegroupc/groupcore-utils/src/master"
12
12
  },
13
13
  "author": "Ken",
14
14
  "license": "ISC",
15
15
  "bugs": {
16
- "url": "https://github.com/TheGroupC/groupcore-utils/issues"
16
+ "url": "https://bitbucket.org/thegroupc/groupcore-utils/src/master"
17
17
  },
18
- "homepage": "https://github.com/TheGroupC/groupcore-utils#readme",
18
+ "homepage": "https://bitbucket.org/thegroupc/groupcore-utils/src/master",
19
19
  "dependencies": {
20
20
  "axios": "^0.23.0",
21
21
  "lodash": "^4.17.21"