Skip to content

Commit

Permalink
Merge pull request #22 from fga-eps-mds/252-professional-homepage
Browse files Browse the repository at this point in the history
Criar página home
  • Loading branch information
JPedroCh authored May 16, 2021
2 parents dc1e0fa + b17b3a5 commit d5a253e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Controllers/SectorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ const sectorDelete = async (req, res) => {
}
};

const newestFourSectorsGet = async (req, res) => {
const sectors = await Sector.find().limit(4).sort({ createdAt: -1 });

return res.status(200).json(sectors);
};

module.exports = {
sectorGet, sectorId, sectorCreate, sectorUpdate, sectorDelete,
sectorGet, sectorId, sectorCreate, sectorUpdate, sectorDelete, newestFourSectorsGet,
};
1 change: 1 addition & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const SectorController = require('./Controllers/SectorController');
const { verifyJWT } = require('./Utils/validateJWT');

routes.get('/sector', verifyJWT, SectorController.sectorGet);
routes.get('/sector/newest-four', verifyJWT, SectorController.newestFourSectorsGet);
routes.get('/sector/:id', verifyJWT, SectorController.sectorId);
routes.post('/sector/create', verifyJWT, SectorController.sectorCreate);
routes.put('/sector/update/:id', verifyJWT, SectorController.sectorUpdate);
Expand Down
43 changes: 43 additions & 0 deletions tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,58 @@ describe('Sample Test', () => {
description: 'setor teste',
};

const sector1 = {
name: 'setor um',
description: 'setor número um',
};

const sector2 = {
name: 'setor dois',
description: 'setor número dois',
};

const sector3 = {
name: 'setor três',
description: 'setor número três',
};

const sector4 = {
name: 'setor quatro',
description: 'setor número quatro',
};

const sector5 = {
name: 'setor cinco',
description: 'setor número cinco',
};

const token = jwt.sign({ name: "Teste", description: "Teste" }, process.env.SECRET, {
expiresIn: 240,
});


beforeAll(async () => {
await request(app).post('/sector/create').set('x-access-token', token).send(sector1);
await request(app).post('/sector/create').set('x-access-token', token).send(sector2);
await request(app).post('/sector/create').set('x-access-token', token).send(sector3);
await request(app).post('/sector/create').set('x-access-token', token).send(sector4);
await request(app).post('/sector/create').set('x-access-token', token).send(sector5);
})


it('App is defined', (done) => {
expect(app).toBeDefined();
done();
});

it('Get newest four sectors', async (done) => {
const res = await request(app).get('/sector/newest-four').set('x-access-token', token);
expect(res.statusCode).toBe(200);
expect(res.body.length).toBe(4);
done();
});

// sector/create
it('Post sector', async (done) => {
const res = await request(app).post('/sector/create').set('x-access-token', token).send(sector);
expect(res.statusCode).toBe(200);
Expand Down

0 comments on commit d5a253e

Please sign in to comment.