@webitel/api-services 26.12.18 → 26.12.20
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 +1 -1
- package/src/api/clients/dialplans/__tests__/dialplans.spec.ts +139 -0
- package/src/api/clients/dialplans/dialplans.ts +38 -45
- package/src/api/clients/flows/__tests__/flow.spec.ts +148 -0
- package/src/api/clients/flows/flow.ts +82 -112
- package/src/validations/_shared/regExp.validations.ts +17 -0
- package/src/validations/dialplan/__tests__/dialplan.validations.spec.ts +58 -0
- package/src/validations/dialplan/dialplan.validations.ts +22 -0
- package/src/validations/flow/__tests__/flow.validations.spec.ts +46 -0
- package/src/validations/flow/flow.validations.ts +30 -0
- package/src/validations/index.ts +3 -0
- package/types/.tsbuildinfo +1 -1
- package/types/validations/_shared/regExp.validations.d.ts +3 -0
- package/types/validations/dialplan/dialplan.validations.d.ts +15 -0
- package/types/validations/flow/flow.validations.d.ts +24 -0
- package/types/validations/index.d.ts +3 -0
package/package.json
CHANGED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const wireDialplan = {
|
|
4
|
+
id: '1',
|
|
5
|
+
name: 'Outbound',
|
|
6
|
+
pattern: '^1$',
|
|
7
|
+
allow_transfer: true,
|
|
8
|
+
domain_id: '10',
|
|
9
|
+
schema: {
|
|
10
|
+
id: '2',
|
|
11
|
+
name: 'IVR',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const searchRoutingOutboundCall = vi.fn(() =>
|
|
16
|
+
Promise.resolve({
|
|
17
|
+
data: {
|
|
18
|
+
items: [
|
|
19
|
+
{
|
|
20
|
+
id: '1',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
next: false,
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
const createRoutingOutboundCall = vi.fn(() =>
|
|
28
|
+
Promise.resolve({
|
|
29
|
+
data: wireDialplan,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
const updateRoutingOutboundCall = vi.fn(() =>
|
|
33
|
+
Promise.resolve({
|
|
34
|
+
data: wireDialplan,
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
const patchRoutingOutboundCall = vi.fn(() =>
|
|
38
|
+
Promise.resolve({
|
|
39
|
+
data: wireDialplan,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
vi.mock('../../../../gen-wire', async (importOriginal) => ({
|
|
44
|
+
...(await importOriginal<Record<string, unknown>>()),
|
|
45
|
+
getRoutingOutboundCallService: () => ({
|
|
46
|
+
searchRoutingOutboundCall,
|
|
47
|
+
createRoutingOutboundCall,
|
|
48
|
+
updateRoutingOutboundCall,
|
|
49
|
+
patchRoutingOutboundCall,
|
|
50
|
+
}),
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
const { DialplansAPI } = await import('../dialplans');
|
|
54
|
+
|
|
55
|
+
const card = {
|
|
56
|
+
id: '1',
|
|
57
|
+
name: 'Outbound',
|
|
58
|
+
pattern: '^1$',
|
|
59
|
+
allowTransfer: true,
|
|
60
|
+
description: '',
|
|
61
|
+
domainId: '10',
|
|
62
|
+
createdAt: '5',
|
|
63
|
+
schema: {
|
|
64
|
+
id: '2',
|
|
65
|
+
name: 'IVR',
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
describe('DialplansAPI', () => {
|
|
70
|
+
beforeEach(() => vi.clearAllMocks());
|
|
71
|
+
|
|
72
|
+
it('getList sends search as q and allowTransfer as allow_transfer', async () => {
|
|
73
|
+
await DialplansAPI.getList({
|
|
74
|
+
search: 'out',
|
|
75
|
+
allowTransfer: true,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(searchRoutingOutboundCall).toHaveBeenCalledWith(
|
|
79
|
+
expect.objectContaining({
|
|
80
|
+
q: 'out*',
|
|
81
|
+
allow_transfer: true,
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('getList defaults disabled to false', async () => {
|
|
87
|
+
const { items } = await DialplansAPI.getList({});
|
|
88
|
+
expect(items[0]).toMatchObject({
|
|
89
|
+
disabled: false,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('add sends only body fields, never domain_id', async () => {
|
|
94
|
+
await DialplansAPI.add({
|
|
95
|
+
itemInstance: card,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(createRoutingOutboundCall).toHaveBeenCalledWith({
|
|
99
|
+
name: 'Outbound',
|
|
100
|
+
pattern: '^1$',
|
|
101
|
+
allow_transfer: true,
|
|
102
|
+
description: '',
|
|
103
|
+
schema: {
|
|
104
|
+
id: '2',
|
|
105
|
+
name: 'IVR',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('update sends the same body to the item id', async () => {
|
|
111
|
+
const response = await DialplansAPI.update({
|
|
112
|
+
itemId: '1',
|
|
113
|
+
itemInstance: card,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
expect(updateRoutingOutboundCall).toHaveBeenCalledWith(
|
|
117
|
+
'1',
|
|
118
|
+
expect.not.objectContaining({
|
|
119
|
+
domain_id: expect.anything(),
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
expect(response).toMatchObject({
|
|
123
|
+
allowTransfer: true,
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('patch sends just the changed field', async () => {
|
|
128
|
+
await DialplansAPI.patch({
|
|
129
|
+
id: '1',
|
|
130
|
+
changes: {
|
|
131
|
+
disabled: true,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
expect(patchRoutingOutboundCall).toHaveBeenCalledWith('1', {
|
|
136
|
+
disabled: true,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
getRoutingOutboundCallService,
|
|
3
|
-
|
|
5
|
+
SearchRoutingOutboundCallQueryParams,
|
|
6
|
+
UpdateRoutingOutboundCallBody,
|
|
4
7
|
} from '../../../gen-wire';
|
|
5
8
|
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
6
9
|
import {
|
|
@@ -9,7 +12,7 @@ import {
|
|
|
9
12
|
merge,
|
|
10
13
|
mergeEach,
|
|
11
14
|
notify,
|
|
12
|
-
|
|
15
|
+
sanitizeToWire,
|
|
13
16
|
snakeToCamel,
|
|
14
17
|
starToSearch,
|
|
15
18
|
} from '../../transformers';
|
|
@@ -23,45 +26,45 @@ import type {
|
|
|
23
26
|
UpdateItemParams,
|
|
24
27
|
} from '../_shared/types';
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
'description',
|
|
31
|
-
'disabled',
|
|
32
|
-
'allowTransfer',
|
|
33
|
-
];
|
|
29
|
+
/** [Claude] the body fields minus `domain_id`: the domain comes from the session, never from the form */
|
|
30
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
31
|
+
UpdateRoutingOutboundCallBody,
|
|
32
|
+
).filter((field) => field !== 'domain_id');
|
|
34
33
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const toRequestItem = (item: ApiParams) =>
|
|
35
|
+
applyTransform(item, [
|
|
36
|
+
sanitizeToWire(fieldsToSend),
|
|
37
|
+
camelToSnake(),
|
|
38
|
+
]);
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
const getDialplansList = async (params: ApiParams) => {
|
|
41
|
+
const requestParams = applyTransform(params, [
|
|
42
|
+
merge(getDefaultGetParams()),
|
|
43
|
+
starToSearch('search'),
|
|
44
|
+
(params: ApiParams) => ({
|
|
45
|
+
...params,
|
|
46
|
+
q: params.search,
|
|
47
|
+
}),
|
|
48
|
+
sanitizeToWire(
|
|
49
|
+
getShallowFieldsToSendFromZodSchema(SearchRoutingOutboundCallQueryParams),
|
|
50
|
+
),
|
|
51
|
+
camelToSnake(),
|
|
52
|
+
]);
|
|
45
53
|
|
|
46
54
|
try {
|
|
47
55
|
const response =
|
|
48
|
-
await getRoutingOutboundCallService().searchRoutingOutboundCall(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// the generated param is `q`; `search` is what the datalist store sends
|
|
52
|
-
q: search,
|
|
53
|
-
sort,
|
|
54
|
-
fields,
|
|
55
|
-
id,
|
|
56
|
-
allow_transfer: allowTransfer,
|
|
57
|
-
} as SearchRoutingOutboundCallParams);
|
|
56
|
+
await getRoutingOutboundCallService().searchRoutingOutboundCall(
|
|
57
|
+
requestParams,
|
|
58
|
+
);
|
|
58
59
|
const { items, next } = applyTransform(response.data, [
|
|
59
60
|
snakeToCamel(),
|
|
60
61
|
merge(getDefaultGetListResponse()),
|
|
61
62
|
]);
|
|
62
63
|
return {
|
|
63
64
|
items: applyTransform(items, [
|
|
64
|
-
mergeEach(
|
|
65
|
+
mergeEach({
|
|
66
|
+
disabled: false,
|
|
67
|
+
}),
|
|
65
68
|
]),
|
|
66
69
|
next,
|
|
67
70
|
};
|
|
@@ -87,13 +90,11 @@ const getDialplan = async ({ itemId: id }: GetItemParams) => {
|
|
|
87
90
|
};
|
|
88
91
|
|
|
89
92
|
const addDialplan = async ({ itemInstance }: AddItemParams) => {
|
|
90
|
-
const item = applyTransform(itemInstance, [
|
|
91
|
-
sanitize(fieldsToSend),
|
|
92
|
-
camelToSnake(),
|
|
93
|
-
]);
|
|
94
93
|
try {
|
|
95
94
|
const response =
|
|
96
|
-
await getRoutingOutboundCallService().createRoutingOutboundCall(
|
|
95
|
+
await getRoutingOutboundCallService().createRoutingOutboundCall(
|
|
96
|
+
toRequestItem(itemInstance),
|
|
97
|
+
);
|
|
97
98
|
return applyTransform(response.data, [
|
|
98
99
|
snakeToCamel(),
|
|
99
100
|
]);
|
|
@@ -108,15 +109,11 @@ const updateDialplan = async ({
|
|
|
108
109
|
itemInstance,
|
|
109
110
|
itemId: id,
|
|
110
111
|
}: UpdateItemParams) => {
|
|
111
|
-
const item = applyTransform(itemInstance, [
|
|
112
|
-
sanitize(fieldsToSend),
|
|
113
|
-
camelToSnake(),
|
|
114
|
-
]);
|
|
115
112
|
try {
|
|
116
113
|
const response =
|
|
117
114
|
await getRoutingOutboundCallService().updateRoutingOutboundCall(
|
|
118
115
|
String(id),
|
|
119
|
-
|
|
116
|
+
toRequestItem(itemInstance),
|
|
120
117
|
);
|
|
121
118
|
return applyTransform(response.data, [
|
|
122
119
|
snakeToCamel(),
|
|
@@ -129,15 +126,11 @@ const updateDialplan = async ({
|
|
|
129
126
|
};
|
|
130
127
|
|
|
131
128
|
const patchDialplan = async ({ changes, id }: PatchItemParams) => {
|
|
132
|
-
const body = applyTransform(changes, [
|
|
133
|
-
sanitize(fieldsToSend),
|
|
134
|
-
camelToSnake(),
|
|
135
|
-
]);
|
|
136
129
|
try {
|
|
137
130
|
const response =
|
|
138
131
|
await getRoutingOutboundCallService().patchRoutingOutboundCall(
|
|
139
132
|
String(id),
|
|
140
|
-
|
|
133
|
+
toRequestItem(changes),
|
|
141
134
|
);
|
|
142
135
|
return applyTransform(response.data, [
|
|
143
136
|
snakeToCamel(),
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const wireFlow = {
|
|
4
|
+
id: '1',
|
|
5
|
+
name: 'IVR',
|
|
6
|
+
created_at: '10',
|
|
7
|
+
schema: [
|
|
8
|
+
{
|
|
9
|
+
set_var: 'x',
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
payload: {
|
|
13
|
+
some_key: 1,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const searchRoutingSchema = vi.fn(() =>
|
|
18
|
+
Promise.resolve({
|
|
19
|
+
data: {
|
|
20
|
+
items: [
|
|
21
|
+
{
|
|
22
|
+
id: '1',
|
|
23
|
+
name: 'IVR',
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
next: false,
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
const readRoutingSchema = vi.fn(() =>
|
|
31
|
+
Promise.resolve({
|
|
32
|
+
data: wireFlow,
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
const createRoutingSchema = vi.fn(() =>
|
|
36
|
+
Promise.resolve({
|
|
37
|
+
data: wireFlow,
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
const updateRoutingSchema = vi.fn(() =>
|
|
41
|
+
Promise.resolve({
|
|
42
|
+
data: wireFlow,
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
vi.mock('../../../../gen-wire', async (importOriginal) => ({
|
|
47
|
+
...(await importOriginal<Record<string, unknown>>()),
|
|
48
|
+
getRoutingSchemaService: () => ({
|
|
49
|
+
searchRoutingSchema,
|
|
50
|
+
readRoutingSchema,
|
|
51
|
+
createRoutingSchema,
|
|
52
|
+
updateRoutingSchema,
|
|
53
|
+
}),
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
const { FlowsAPI } = await import('../flow');
|
|
57
|
+
|
|
58
|
+
const stringifiedSchema = JSON.stringify(wireFlow.schema, null, 4);
|
|
59
|
+
|
|
60
|
+
describe('FlowsAPI', () => {
|
|
61
|
+
beforeEach(() => vi.clearAllMocks());
|
|
62
|
+
|
|
63
|
+
it('getList maps the flowType filter to type, always with "default"', async () => {
|
|
64
|
+
await FlowsAPI.getList({
|
|
65
|
+
flowType: [
|
|
66
|
+
'chat',
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(searchRoutingSchema).toHaveBeenCalledWith(
|
|
71
|
+
expect.objectContaining({
|
|
72
|
+
type: [
|
|
73
|
+
'chat',
|
|
74
|
+
'default',
|
|
75
|
+
],
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('getList fills type and editor defaults on items', async () => {
|
|
81
|
+
const { items } = await FlowsAPI.getList({});
|
|
82
|
+
|
|
83
|
+
expect(items[0]).toMatchObject({
|
|
84
|
+
type: 'default',
|
|
85
|
+
editor: false,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('get stringifies schema and keeps payload keys as they are', async () => {
|
|
90
|
+
const flow = await FlowsAPI.get({
|
|
91
|
+
itemId: '1',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(flow).toMatchObject({
|
|
95
|
+
createdAt: '10',
|
|
96
|
+
schema: stringifiedSchema,
|
|
97
|
+
payload: {
|
|
98
|
+
some_key: 1,
|
|
99
|
+
},
|
|
100
|
+
tags: [],
|
|
101
|
+
editor: false,
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('add sends parsed schema, untouched payload, and only body fields', async () => {
|
|
106
|
+
const flow = await FlowsAPI.add({
|
|
107
|
+
itemInstance: {
|
|
108
|
+
id: '1',
|
|
109
|
+
name: 'IVR',
|
|
110
|
+
schema: '[{"set_var":"x"}]',
|
|
111
|
+
payload: {
|
|
112
|
+
someKey: 1,
|
|
113
|
+
},
|
|
114
|
+
createdAt: '10',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(createRoutingSchema).toHaveBeenCalledWith({
|
|
119
|
+
name: 'IVR',
|
|
120
|
+
schema: [
|
|
121
|
+
{
|
|
122
|
+
set_var: 'x',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
payload: {
|
|
126
|
+
someKey: 1,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
expect(flow.schema).toBe(stringifiedSchema);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('update sends the same body shape to the item id', async () => {
|
|
133
|
+
await FlowsAPI.update({
|
|
134
|
+
itemId: '1',
|
|
135
|
+
itemInstance: {
|
|
136
|
+
name: 'IVR',
|
|
137
|
+
schema: '[]',
|
|
138
|
+
editor: true,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
expect(updateRoutingSchema).toHaveBeenCalledWith('1', {
|
|
143
|
+
name: 'IVR',
|
|
144
|
+
schema: [],
|
|
145
|
+
editor: true,
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|