Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Commit

Permalink
#30 Adicionando novo teste
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Leal <vitinho2201@gmail.com>
Signed-off-by: Gabriela Barrozo Guedes <gabrielabguedes@gmail.com>

Co-authored-by: Gabriela Barrozo Guedes <gabrielabguedes@gmail.com>
Co-authored-by: Vitor Leal <vitinho2201@gmail.com>
  • Loading branch information
2 people authored and EzequielDeOliveira committed May 12, 2018
1 parent 52cd506 commit df170a4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 89 deletions.
62 changes: 0 additions & 62 deletions Schedule/Client/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< d0b1dd7abd1a09726eb130cd13fab5ad33619934
module.exports = function api(options) {
currentWeekNumber = require('current-week-number');

Expand Down Expand Up @@ -259,65 +258,4 @@ module.exports = function api(options) {



=======
module.exports = function api(options){

this.add('role:api,path:create', function(msg,respond){

var date = msg.args.body.date
var start_time = msg.args.body.start_time
var end_time = msg.args.body.end_time
var sector = msg.args.body.sector
var employee = msg.args.body.employee
var specialty = msg.args.body.specialty
var id = msg.args.query.id

// The diference between times is given in milliseconds. We are expecting hours,
//so wu divide by 3600000.0 that is the number of milliseconds in 1 hour
var amount_of_hours = (Date.parse(end_time) - Date.parse(start_time))/3600000.0

if(Date.parse(start_time) > Date.parse(end_time)){
this.act('role:schedule,cmd:create',{
}, respond(null, {success:false, message: 'Horários de Inicio e Fim estão em comflito'}))
}else if(sector == null || (sector.length < 1)){
this.act('role:schedule,cmd:create',{
}, respond(null, {success:false, message: 'Setor não pode ser vazio'}))
}else if(employee == null || (employee.length < 1)){
this.act('role:schedule,cmd:create',{
}, respond(null, {success:false, message: 'Plantonista não pode ser vazio'}))

}else{
this.act('role:schedule,cmd:create',{
date:date,
start_time:start_time,
end_time:end_time,
sector:sector,
employee:employee,
specialty:specialty,
amount_of_hours:amount_of_hours,
id:id
}, respond)
}
})

this.add('role:api,path:error', function(msg, respond){
this.act('role:schedule, cmd:error',{}, respond)
});


this.add('init:api', function (msg,respond){
this.act('role:web',{routes: {
prefix: '/api/schedule',
pin: 'role:api,path:*',
map: {
create: { POST:true,
auth: {
strategy: 'jwt',
fail: '/api/schedule/error',
}},
error: {GET:true}
}
}}, respond)
});
>>>>>>> #30 Criando estrutura basica para criar escala com requisição de token. Ainda falta colocar os atributos certos
}
13 changes: 5 additions & 8 deletions Schedule/Client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "node-app",
"version": "1.0.0",
"description": "",
"main": "client_sector.js",
"main": "client_schedule.js",
"scripts": {
"start": "nodemon client_sector.js",
"test": "mocha"
"start": "nodemon client_schedule.js",
"test": "./node_modules/.bin/mocha --reporter spec"
},
"author": "",
"license": "MIT",
Expand All @@ -18,18 +18,15 @@
"mongoose": "^4.6.1",
"morgan": "^1.9.0",
"nodemon": "^1.10.2",
"seneca": "^3.4.3",
"seneca-amqp-transport": "^2.2.0",
"seneca-entity": "^2.0.2",
"seneca-mongo-store": "^1.1.0",
"seneca-web": "^2.2.0",
"seneca-web-adapter-express": "^1.1.1"
"seneca-mongo-store": "^1.1.0"
},
"devDependencies": {
"assert": "^1.4.1",
"express": "^4.16.3",
"express-session": "^1.15.6",
"istanbul": "^0.4.5",
"jest": "^22.4.3",
"jsonwebtoken": "^8.2.1",
"mocha": "^5.0.5",
"passport": "^0.4.0",
Expand Down
88 changes: 69 additions & 19 deletions Schedule/Client/test/schedule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ var should = require('should');
describe('Routing', function() {
const url = 'http://localhost:8091';

describe('should test the token validation', () => {
describe('should test the token validation', () => {
it('should return an error message: access denied', () => {
request(url)
.post('/api/sector/create')
.post('/api/schedule/create')
.send()
.end((err,res) => {
if (err) {
throw err;
}
if (err) {
throw err;
}
res.should.be.json;
res.body.message.should.equal('acesso negado');
res.body.success.should.equal(false);
Expand Down Expand Up @@ -52,21 +52,71 @@ describe('Routing', function() {
expect(res.body.state).to.be.true;

request('http://localhost:8086/')
.post('/userManager/login')
.send(login_details)
.post('/userManager/login')
.send(login_details)
.end((err, res) => {
let token = res.body.token;
request(url)
.post('/schedule/create')
.send(new_schedule)
.set('x-access-token', token)
.end((err, res) => {
let token = res.body.token;
request(url)
.post('/schedule/create')
.send(new_schedule)
.set('x-access-token', token)
.end((err, res) => {
res.status.should.equal(200);
expect(res.body.state).to.be.true;
res.body.data.should.be.an('array');
})
res.status.should.equal(200);
expect(res.body.state).to.be.true;
res.body.data.should.be.an('array');
})
})
})
})
});
});
});
describe('should test the validations for creating a schedule', () => {
it('should return conflicting times', () => {
let register_details = {
'name': 'new user',
'registration': '54321',
'hospital': 'new user\'s hospital',
'sector' : 'new usser\'s sector',
'password': '1234',
'manager': true
}
let login_details = {
'registration': '54321',
'password': '1234'
}
let wrong_schedule = {
'date':'03/05/2018',
'start_time':'03/05/2018 16:00:00',
'end_time':'03/05/2018 14:00:00',
'sector':'employee\'s sector',
'employee':'employee user',
'specialty':'employee\'s specialty',
};

request('http://localhost:8083/')
.post('/userManager/create')
.send(register_details)
.end((err, res) => {
res.should.have.status(201);
expect(res.body.state).to.be.true;

request('http://localhost:8086/')
.post('/userManager/login')
.send(login_details)
.end((err, res) => {
let token = res.body.token;
request(url)
.post('/schedule/create')
.send(wrong_schedule)
.set('x-access-token', token)
.end((err, res) => {
res.should.be.json;
res.body.message.should.equal('Horários de Inicio e Fim estão em comflito');
res.body.success.should.equal(false);
res.status.should.equal(403);
})
})
})
});
});

});

0 comments on commit df170a4

Please sign in to comment.