-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.test.js
More file actions
45 lines (45 loc) · 1.6 KB
/
sample.test.js
File metadata and controls
45 lines (45 loc) · 1.6 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
const request = require('supertest')
const app = require('./server')
describe('Post Upload Endpoint', () => {
it('try to upload without file', async () => {
const res = await request(app)
.post('/api/csv/upload')
expect(res.statusCode).toEqual(400)
expect(res.body).toHaveProperty('message')
const {message} =res.body;
expect(message).toBe('Please upload a CSV file!');
})
it('upload wrong file', async () => {
const res = await request(app)
.post('/api/csv/upload')
.attach('file', './testing_files/invalid_file.jpeg')
expect(res.statusCode).toEqual(500)
})
it('upload file test 1', async () => {
const res = await request(app)
.post('/api/csv/upload')
.attach('file', './documentation/file_samples/TEST1.csv')
expect(res.statusCode).toEqual(200)
expect(res.body).toHaveProperty('recordsUpload')
})
it('upload file length records test 2', async () => {
const res = await request(app)
.post('/api/csv/upload')
.attach('file', './documentation/file_samples/TEST2.csv')
expect(res.statusCode).toEqual(200)
const {recordsUpload} =res.body;
expect(recordsUpload).toBe(3);
})
})
describe('Get AllRecords Endpoint', () => {
it('should get data object', async () => {
const res = await request(app)
.get('/api/csv/getall')
expect(res.statusCode).toEqual(200)
expect(res.body).toHaveProperty('data')
})
});
afterAll(done => {
app.close();
done();
});