mirror of https://github.com/xfarrow/blink
add tests
This commit is contained in:
parent
71caaf6886
commit
d043869050
|
@ -51,14 +51,14 @@ app.use(rateLimiter); // Apply the rate limiter middleware to all routes
|
||||||
===== BEGIN ROUTE HANDLING =====
|
===== BEGIN ROUTE HANDLING =====
|
||||||
*/
|
*/
|
||||||
app.use('/api/server', serverRoutes.routes);
|
app.use('/api/server', serverRoutes.routes);
|
||||||
app.use('/api/persons', personRoutes.publicRoutes);
|
app.use('/api/persons', personRoutes.publicRoutes); // TODO: Change in "/people". Idk why I chose "persons"
|
||||||
app.use('/api/persons', personRoutes.protectedRoutes);
|
app.use('/api/persons', personRoutes.protectedRoutes); // TODO: Change in "/people". Idk why I chose "persons"
|
||||||
app.use('/api/organizations', organizationRoutes.routes);
|
app.use('/api/organizations', organizationRoutes.routes);
|
||||||
app.use('/api/organizations', jobOffersRoutes.routes);
|
app.use('/api/organizations', jobOffersRoutes.routes);
|
||||||
app.use('/api/organizations', organizationAdminRoutes.routes);
|
app.use('/api/organizations', organizationAdminRoutes.routes);
|
||||||
app.use('/api/resetpassword', resetPasswordRoutes.routes);
|
app.use('/api/resetpassword', resetPasswordRoutes.routes);
|
||||||
app.use('/api/organizations', applicationRoutes.routes);
|
app.use('/api/organizations', applicationRoutes.routes);
|
||||||
app.use('/api/persons', personContactInfosRoutes.routes);
|
app.use('/api/persons', personContactInfosRoutes.routes); // TODO: Change in "/people". Idk why I chose "persons"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
===== END ROUTE HANDLING =====
|
===== END ROUTE HANDLING =====
|
||||||
|
@ -78,6 +78,3 @@ app.listen(port, () => {
|
||||||
/*
|
/*
|
||||||
===== END STARTING THE SERVER =====
|
===== END STARTING THE SERVER =====
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Export the app for testing purposes
|
|
||||||
module.exports = app;
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
// To execute tests, call: npx jest
|
||||||
|
// Note: The API should already be running
|
||||||
|
// Note: These tests will pollute the database. Run only in test environments
|
||||||
|
|
||||||
|
const request = require('supertest');
|
||||||
|
const apiEndpoint = 'http://localhost:3000/api';
|
||||||
|
|
||||||
|
function randomString() {
|
||||||
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
const length = Math.floor(Math.random() * 10) + 1;
|
||||||
|
let result = '';
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const userEmail = randomString() + "_test@mail.org";
|
||||||
|
|
||||||
|
describe('Person tests', () => {
|
||||||
|
it('should return a 201 status code for POST /persons', async () => {
|
||||||
|
const userData = {
|
||||||
|
"email": userEmail,
|
||||||
|
"password": "password",
|
||||||
|
"displayName": "Test1",
|
||||||
|
};
|
||||||
|
const response = await request(apiEndpoint)
|
||||||
|
.post('/persons')
|
||||||
|
.send(userData);
|
||||||
|
expect(response.status).toBe(201);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a 400 status code for POST /persons', async () => {
|
||||||
|
const userData = {
|
||||||
|
"password": "password",
|
||||||
|
"displayName": "Test1",
|
||||||
|
};
|
||||||
|
const response = await request(apiEndpoint)
|
||||||
|
.post('/persons')
|
||||||
|
.send(userData);
|
||||||
|
expect(response.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a 400 status code for POST /persons', async () => {
|
||||||
|
const userData = {
|
||||||
|
"email": "test1@mail.org",
|
||||||
|
"displayName": "Test1",
|
||||||
|
};
|
||||||
|
const response = await request(apiEndpoint)
|
||||||
|
.post('/persons')
|
||||||
|
.send(userData);
|
||||||
|
expect(response.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a 400 status code for POST /persons', async () => {
|
||||||
|
const userData = {
|
||||||
|
"email": "test1@mail.org",
|
||||||
|
"password": "password"
|
||||||
|
};
|
||||||
|
const response = await request(apiEndpoint)
|
||||||
|
.post('/persons')
|
||||||
|
.send(userData);
|
||||||
|
expect(response.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a 400 status code for POST /persons', async () => {
|
||||||
|
const userData = {
|
||||||
|
"email": randomString() + "_test_not_an_email",
|
||||||
|
"password": "password",
|
||||||
|
"displayName": "Test1",
|
||||||
|
};
|
||||||
|
const response = await request(apiEndpoint)
|
||||||
|
.post('/persons')
|
||||||
|
.send(userData);
|
||||||
|
expect(response.status).toBe(400);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue