-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
75 lines (68 loc) · 1.84 KB
/
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
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
import chai from 'chai';
import chaiHttp from 'chai-http';
import app from './app.js';
chai.use(chaiHttp);
const expect = chai.expect;
describe('Express App', () => {
// Test GET /project route
describe('GET /project', () => {
it('should return a random project as HTML', (done) => {
chai
.request(app)
.get('/project')
.end((err, res) => {
expect(res).to.have.status(200);
expect(res).to.be.html;
// You can add more assertions for the HTML content if needed
done();
});
});
});
// Test GET /projects route
describe('GET /projects', () => {
it('should return a list of projects as HTML', (done) => {
chai
.request(app)
.get('/projects')
.end((err, res) => {
expect(res).to.have.status(200);
expect(res).to.be.html;
// You can add more assertions for the HTML content if needed
done();
});
});
});
// Test POST /add-project route
describe('POST /add-project', () => {
it('should add a new project and return the redirection URL', (done) => {
const newProject = {
name: 'Test Project',
description: 'This is a test project',
difficulty: 'Easy',
tags: 'test, project',
};
chai
.request(app)
.post('/add-project')
.send(newProject)
.end((err, res) => {
expect(res).to.have.status(200);
expect(res.body).to.have.property('redirectUrl').that.equals('/project');
done();
});
});
it('should return 400 if required fields are missing', (done) => {
const invalidProject = {
// Missing fields
};
chai
.request(app)
.post('/add-project')
.send(invalidProject)
.end((err, res) => {
expect(res).to.have.status(400);
done();
});
});
})
});