forked from kirlz44/Bitrix24_mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.test.js
More file actions
152 lines (141 loc) · 4.45 KB
/
server.test.js
File metadata and controls
152 lines (141 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// server.test.js
const request = require('supertest');
const app = require('./server');
// Моки для ответов Битрикс24 API
jest.mock('axios', () => ({
post: jest.fn((url) => {
if (url.includes('tasks.task.list')) {
return Promise.resolve({
data: {
result: {
tasks: [
{
id: 1,
title: 'Тестовая задача',
responsibleName: 'Иван Иванов',
deadline: '2023-12-31',
status: 'новая',
createdDate: '2023-10-01'
}
],
total: 1
}
}
});
}
if (url.includes('crm.contact.list')) {
return Promise.resolve({
data: {
result: [
{
ID: 1,
NAME: 'Иван',
LAST_NAME: 'Петров',
EMAIL: [{ VALUE: 'ivan@example.com' }],
PHONE: [{ VALUE: '+7 999 123 45 67' }],
COMPANY_ID: '42'
}
],
total: 1
}
});
}
if (url.includes('crm.deal.list')) {
return Promise.resolve({
data: {
result: [
{
ID: 1,
TITLE: 'Тестовая сделка',
STAGE_ID: 'NEW',
OPPORTUNITY: '100000',
CURRENCY_ID: 'RUB',
CONTACT_ID: '1',
ASSIGNED_BY_ID: '42',
DATE_CREATE: '2023-10-01'
}
],
total: 1
}
});
}
if (url.includes('crm.deal.add')) {
return Promise.resolve({
data: {
result: 2
}
});
}
if (url.includes('crm.deal.update')) {
return Promise.resolve({
data: {
result: true
}
});
}
return Promise.reject(new Error('Неизвестный эндпоинт'));
})
}));
describe('Bitrix24 MCP Server API', () => {
afterAll(() => {
// Закрываем соединение после тестов
app.close();
});
describe('GET /api/tasks', () => {
it('должен возвращать список задач', async () => {
const response = await request(app).get('/api/tasks');
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('tasks');
expect(response.body.tasks).toBeInstanceOf(Array);
expect(response.body.tasks[0]).toHaveProperty('title', 'Тестовая задача');
});
});
describe('GET /api/contacts', () => {
it('должен возвращать список контактов', async () => {
const response = await request(app).get('/api/contacts');
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('contacts');
expect(response.body.contacts).toBeInstanceOf(Array);
expect(response.body.contacts[0]).toHaveProperty('name', 'Иван Петров');
});
});
describe('GET /api/deals', () => {
it('должен возвращать список сделок', async () => {
const response = await request(app).get('/api/deals');
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('deals');
expect(response.body.deals).toBeInstanceOf(Array);
expect(response.body.deals[0]).toHaveProperty('title', 'Тестовая сделка');
});
});
describe('POST /api/deals', () => {
it('должен создавать новую сделку', async () => {
const dealData = {
TITLE: 'Новая тестовая сделка',
STAGE_ID: 'NEW',
OPPORTUNITY: '150000',
CURRENCY_ID: 'RUB',
CONTACT_ID: '1'
};
const response = await request(app)
.post('/api/deals')
.send(dealData);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('success', true);
expect(response.body).toHaveProperty('id', 2);
});
});
describe('PUT /api/deals/:id', () => {
it('должен обновлять существующую сделку', async () => {
const dealData = {
TITLE: 'Обновленная тестовая сделка',
OPPORTUNITY: '200000'
};
const response = await request(app)
.put('/api/deals/1')
.send(dealData);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('success', true);
});
});
});