-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
41 lines (35 loc) · 1.86 KB
/
index.test.js
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
const request = require('supertest');
const { fetchFormResponses, sendToTelex, app } = require('./index');
jest.mock('axios');
const axios = require('axios');
describe('Google Sheets and Telex Integration', () => {
test('fetchFormResponses should return an array', async () => {
axios.get = jest.fn().mockResolvedValue({ data: { values: [['Timestamp', 'Feedback'], ['2025-02-22', 'Great Service!']] } });
const responses = await fetchFormResponses();
expect(Array.isArray(responses)).toBe(true);
expect(responses.length).toBeGreaterThan(0);
});
test('sendToTelex should return success', async () => {
axios.post.mockResolvedValue({ data: { success: true } });
const result = await sendToTelex({ timestamp: '2025-02-22', feedback: 'Great service!' });
expect(result.success).toBe(true);
});
test('GET / should return a success message', async () => {
const res = await request(app).get('/');
expect(res.status).toBe(200);
expect(res.text).toBe('Telex Feedback Form Monitoring Integration Running!');
});
test('GET /api/telex/data should return form responses', async () => {
axios.get = jest.fn().mockResolvedValue({ data: { values: [['Timestamp', 'Feedback'], ['2025-02-22', 'Great service!']] } });
const res = await request(app).get('/api/telex/data');
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('data');
expect(Array.isArray(res.body.data)).toBe(true);
});
test('POST /api/telex/tick should trigger processing and return success', async () => {
axios.post.mockResolvedValue({ data: { success: true } });
const res = await request(app).post('/api/telex/tick');
expect(res.status).toBe(200);
expect(res.body).toHaveProperty('message', 'Tick received, feedback processed!');
});
});