@webitel/api-services 26.12.27 → 26.12.28
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/package.json
CHANGED
|
@@ -94,6 +94,52 @@ describe('GatewaysAPI', () => {
|
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
+
// [Claude] the save responses are partial, the card gets the gateway read back
|
|
98
|
+
it('reads the gateway back after add and update', async () => {
|
|
99
|
+
instance.post.mockResolvedValue({
|
|
100
|
+
data: {
|
|
101
|
+
id: '7',
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
instance.get.mockResolvedValue({
|
|
105
|
+
data: {
|
|
106
|
+
id: '7',
|
|
107
|
+
name: 'gw',
|
|
108
|
+
register: true,
|
|
109
|
+
account: 'user',
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const added = await GatewaysAPI.add({
|
|
114
|
+
itemInstance: {
|
|
115
|
+
...common,
|
|
116
|
+
register: true,
|
|
117
|
+
account: 'user',
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
expect(instance.get).toHaveBeenCalledWith('/sip/gateways/7');
|
|
121
|
+
expect(added).toMatchObject({
|
|
122
|
+
id: '7',
|
|
123
|
+
name: 'gw',
|
|
124
|
+
register: true,
|
|
125
|
+
account: 'user',
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const updated = await GatewaysAPI.update({
|
|
129
|
+
itemId: '7',
|
|
130
|
+
itemInstance: {
|
|
131
|
+
...common,
|
|
132
|
+
register: true,
|
|
133
|
+
account: 'user',
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
expect(instance.get).toHaveBeenLastCalledWith('/sip/gateways/7');
|
|
137
|
+
expect(updated).toMatchObject({
|
|
138
|
+
id: '7',
|
|
139
|
+
account: 'user',
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
97
143
|
it('patches the changed field only', async () => {
|
|
98
144
|
await GatewaysAPI.patch({
|
|
99
145
|
id: '5',
|
|
@@ -152,17 +152,19 @@ const toRequestItem = (item: ApiParams) =>
|
|
|
152
152
|
]);
|
|
153
153
|
|
|
154
154
|
const addGateway = async ({ itemInstance }: AddItemParams) => {
|
|
155
|
+
let id: string | number;
|
|
155
156
|
try {
|
|
156
157
|
const response = await instance.post(baseUrl, toRequestItem(itemInstance));
|
|
157
|
-
|
|
158
|
-
snakeToCamel(),
|
|
159
|
-
]);
|
|
158
|
+
id = response.data.id;
|
|
160
159
|
} catch (err) {
|
|
161
160
|
throw applyTransform(err, [
|
|
162
161
|
translateError,
|
|
163
162
|
notify,
|
|
164
163
|
]);
|
|
165
164
|
}
|
|
165
|
+
return getGateway({
|
|
166
|
+
itemId: id,
|
|
167
|
+
});
|
|
166
168
|
};
|
|
167
169
|
const updateGateway = async ({
|
|
168
170
|
itemInstance,
|
|
@@ -170,16 +172,16 @@ const updateGateway = async ({
|
|
|
170
172
|
}: UpdateItemParams) => {
|
|
171
173
|
const url = `${baseUrl}/${id}`;
|
|
172
174
|
try {
|
|
173
|
-
|
|
174
|
-
return applyTransform(response.data, [
|
|
175
|
-
snakeToCamel(),
|
|
176
|
-
]);
|
|
175
|
+
await instance.put(url, toRequestItem(itemInstance));
|
|
177
176
|
} catch (err) {
|
|
178
177
|
throw applyTransform(err, [
|
|
179
178
|
translateError,
|
|
180
179
|
notify,
|
|
181
180
|
]);
|
|
182
181
|
}
|
|
182
|
+
return getGateway({
|
|
183
|
+
itemId: id,
|
|
184
|
+
});
|
|
183
185
|
};
|
|
184
186
|
|
|
185
187
|
/** [Claude] a patch carries only the changed fields, so the type is unknown here */
|