Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
simcaq-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simcaq
simcaq-node
Commits
4753e07e
There was a problem fetching the pipeline summary.
Commit
4753e07e
authored
8 years ago
by
Lucas Gabriel Lima
Browse files
Options
Downloads
Patches
Plain Diff
add some tests for user (wip)
parent
a0bebadd
No related branches found
No related tags found
2 merge requests
!116
Release v1.0.0
,
!25
Auth
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/libs/routes/user.js
+1
-1
1 addition, 1 deletion
src/libs/routes/user.js
src/test/test.js
+268
-0
268 additions, 0 deletions
src/test/test.js
with
269 additions
and
1 deletion
src/libs/routes/user.js
+
1
−
1
View file @
4753e07e
...
@@ -36,7 +36,7 @@ userApp.post('/', (req, res, next) => {
...
@@ -36,7 +36,7 @@ userApp.post('/', (req, res, next) => {
},
(
req
,
res
,
next
)
=>
{
},
(
req
,
res
,
next
)
=>
{
if
(
!
emailSyntax
(
req
.
body
.
email
)){
if
(
!
emailSyntax
(
req
.
body
.
email
)){
res
.
json
({
success
:
false
,
msg
:
'
O email
I
nformado é inválido.
'
});
res
.
json
({
success
:
false
,
msg
:
'
O email
i
nformado é inválido.
'
});
}
else
{
}
else
{
next
();
next
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/test/test.js
+
268
−
0
View file @
4753e07e
...
@@ -24,6 +24,7 @@ const server = require(`${libs}/app`);
...
@@ -24,6 +24,7 @@ const server = require(`${libs}/app`);
const
mongoose
=
require
(
'
../libs/db/mongoose
'
);
const
mongoose
=
require
(
'
../libs/db/mongoose
'
);
const
Simulation
=
require
(
'
../libs/models/simulation
'
);
const
Simulation
=
require
(
'
../libs/models/simulation
'
);
const
User
=
require
(
'
../libs/models/user
'
);
chai
.
use
(
chaiHttp
);
chai
.
use
(
chaiHttp
);
...
@@ -778,3 +779,270 @@ describe('Requires a simulation', () => {
...
@@ -778,3 +779,270 @@ describe('Requires a simulation', () => {
});
});
});
});
});
});
describe
(
'
Saves a user
'
,
()
=>
{
beforeEach
(()
=>
{
User
.
remove
({},
(
err
)
=>
{
console
.
log
(
'
Test collection purged
'
);
});
});
it
(
'
should create a new user
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
post
(
'
/api/v1/user
'
)
.
set
(
'
content-type
'
,
'
application/x-www-form-urlencoded
'
)
.
set
(
'
x-apicache-bypass
'
,
'
true
'
)
.
send
({
email
:
'
lorem@ipsum.com
'
,
password
:
'
123mudar
'
,
name
:
'
Tequila Baby
'
,
cpf
:
'
48303270737
'
,
schooling
:
'
Doutorado
'
,
course
:
'
Ciência da Computação
'
,
segment
:
'
Comunidade acadêmica
'
,
role
:
'
Pesquisador
'
,
institution_name
:
'
UFPR
'
,
state
:
'
PR
'
,
city
:
'
Cutiriba
'
})
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
success
'
);
res
.
body
.
success
.
should
.
equal
(
true
);
User
.
findOne
({
'
email
'
:
'
lorem@ipsum.com
'
},
(
err
,
user
)
=>
{
if
(
err
){
console
.
log
(
'
MongoDB error:
'
+
err
);
}
user
.
should
.
have
.
property
(
'
email
'
);
done
();
});
});
});
it
(
'
should not create a user with an email that is already in use
'
,
(
done
)
=>
{
let
newUser
=
new
User
();
newUser
.
email
=
'
lorem@ipsum.com
'
;
newUser
.
password
=
'
123mudar
'
;
newUser
.
name
=
'
Gute
'
;
newUser
.
cpf
=
'
08236017907
'
;
newUser
.
schooling
=
'
Doutorado
'
;
newUser
.
course
=
'
Ciência da Computação
'
;
newUser
.
segment
=
'
Comunidade acadêmica
'
;
newUser
.
role
=
'
Pesquisador
'
;
newUser
.
institution_name
=
'
UFPR
'
;
newUser
.
state
=
'
PR
'
;
newUser
.
city
=
'
Curitiba
'
;
newUser
.
save
((
err
)
=>
{
if
(
err
)
{
console
.
log
(
'
MongoDB error:
'
+
err
);
}
}).
then
(
function
(
newuser
){
chai
.
request
(
server
)
.
post
(
'
/api/v1/user
'
)
.
set
(
'
content-type
'
,
'
application/x-www-form-urlencoded
'
)
.
set
(
'
x-apicache-bypass
'
,
'
true
'
)
.
send
({
email
:
'
lorem@ipsum.com
'
,
password
:
'
123mudar
'
,
name
:
'
Tequila Baby
'
,
cpf
:
'
48303270737
'
,
schooling
:
'
Doutorado
'
,
course
:
'
Ciência da Computação
'
,
segment
:
'
Comunidade acadêmica
'
,
role
:
'
Pesquisador
'
,
institution_name
:
'
UFPR
'
,
state
:
'
PR
'
,
city
:
'
Cutiriba
'
})
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
success
'
);
res
.
body
.
success
.
should
.
equal
(
false
);
res
.
body
.
should
.
have
.
property
(
'
msg
'
);
res
.
body
.
msg
.
should
.
equal
(
'
O email informado já está cadastrado.
'
);
User
.
findOne
({
'
cpf
'
:
'
48303270737
'
},
(
err
,
user
)
=>
{
expect
(
user
).
to
.
not
.
exist
;
done
();
});
});
});
});
it
(
'
should not save an user without email
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
post
(
'
/api/v1/user
'
)
.
set
(
'
content-type
'
,
'
application/x-www-form-urlencoded
'
)
.
set
(
'
x-apicache-bypass
'
,
'
true
'
)
.
send
({
password
:
'
123mudar
'
,
name
:
'
Tequila Baby
'
,
cpf
:
'
48303270737
'
,
schooling
:
'
Doutorado
'
,
course
:
'
Ciência da Computação
'
,
segment
:
'
Comunidade acadêmica
'
,
role
:
'
Pesquisador
'
,
institution_name
:
'
UFPR
'
,
state
:
'
PR
'
,
city
:
'
Cutiriba
'
})
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
success
'
);
res
.
body
.
success
.
should
.
equal
(
false
);
res
.
body
.
should
.
have
.
property
(
'
msg
'
);
res
.
body
.
msg
.
should
.
equal
(
'
O campo Email é obrigatório.
'
);
User
.
findOne
({
'
cpf
'
:
'
48303270737
'
},
(
err
,
user
)
=>
{
expect
(
user
).
to
.
not
.
exist
;
done
();
});
});
});
it
(
'
should not save an user without password
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
post
(
'
/api/v1/user
'
)
.
set
(
'
content-type
'
,
'
application/x-www-form-urlencoded
'
)
.
set
(
'
x-apicache-bypass
'
,
'
true
'
)
.
send
({
email
:
'
lorem@ipsum.com
'
,
name
:
'
Tequila Baby
'
,
cpf
:
'
48303270737
'
,
schooling
:
'
Doutorado
'
,
course
:
'
Ciência da Computação
'
,
segment
:
'
Comunidade acadêmica
'
,
role
:
'
Pesquisador
'
,
institution_name
:
'
UFPR
'
,
state
:
'
PR
'
,
city
:
'
Cutiriba
'
})
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
success
'
);
res
.
body
.
success
.
should
.
equal
(
false
);
res
.
body
.
should
.
have
.
property
(
'
msg
'
);
res
.
body
.
msg
.
should
.
equal
(
'
O campo Senha é obrigatório.
'
);
User
.
findOne
({
'
cpf
'
:
'
48303270737
'
},
(
err
,
user
)
=>
{
expect
(
user
).
to
.
not
.
exist
;
done
();
});
});
});
it
(
'
should not save an user with invalid email
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
post
(
'
/api/v1/user
'
)
.
set
(
'
content-type
'
,
'
application/x-www-form-urlencoded
'
)
.
set
(
'
x-apicache-bypass
'
,
'
true
'
)
.
send
({
email
:
'
notavalidemail
'
,
password
:
'
123mudar
'
,
name
:
'
Tequila Baby
'
,
cpf
:
'
48303270737
'
,
schooling
:
'
Doutorado
'
,
course
:
'
Ciência da Computação
'
,
segment
:
'
Comunidade acadêmica
'
,
role
:
'
Pesquisador
'
,
institution_name
:
'
UFPR
'
,
state
:
'
PR
'
,
city
:
'
Cutiriba
'
})
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
success
'
);
res
.
body
.
success
.
should
.
equal
(
false
);
res
.
body
.
should
.
have
.
property
(
'
msg
'
);
res
.
body
.
msg
.
should
.
equal
(
'
O email informado é inválido.
'
);
User
.
findOne
({
'
cpf
'
:
'
48303270737
'
},
(
err
,
user
)
=>
{
expect
(
user
).
to
.
not
.
exist
;
done
();
});
});
});
it
(
'
should not save an user without name
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
post
(
'
/api/v1/user
'
)
.
set
(
'
content-type
'
,
'
application/x-www-form-urlencoded
'
)
.
set
(
'
x-apicache-bypass
'
,
'
true
'
)
.
send
({
email
:
'
lorem@ipsum.com
'
,
password
:
'
123mudar
'
,
cpf
:
'
48303270737
'
,
schooling
:
'
Doutorado
'
,
course
:
'
Ciência da Computação
'
,
segment
:
'
Comunidade acadêmica
'
,
role
:
'
Pesquisador
'
,
institution_name
:
'
UFPR
'
,
state
:
'
PR
'
,
city
:
'
Cutiriba
'
})
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
success
'
);
res
.
body
.
success
.
should
.
equal
(
false
);
res
.
body
.
should
.
have
.
property
(
'
msg
'
);
res
.
body
.
msg
.
should
.
equal
(
'
O campo Nome é obrigatório.
'
);
User
.
findOne
({
'
cpf
'
:
'
48303270737
'
},
(
err
,
user
)
=>
{
expect
(
user
).
to
.
not
.
exist
;
done
();
});
});
});
it
(
'
should not save an user without CPF
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
post
(
'
/api/v1/user
'
)
.
set
(
'
content-type
'
,
'
application/x-www-form-urlencoded
'
)
.
set
(
'
x-apicache-bypass
'
,
'
true
'
)
.
send
({
email
:
'
lorem@ipsum.com
'
,
password
:
'
123mudar
'
,
name
:
'
Tequila baby
'
,
schooling
:
'
Doutorado
'
,
course
:
'
Ciência da Computação
'
,
segment
:
'
Comunidade acadêmica
'
,
role
:
'
Pesquisador
'
,
institution_name
:
'
UFPR
'
,
state
:
'
PR
'
,
city
:
'
Cutiriba
'
})
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
success
'
);
res
.
body
.
success
.
should
.
equal
(
false
);
res
.
body
.
should
.
have
.
property
(
'
msg
'
);
res
.
body
.
msg
.
should
.
equal
(
'
O campo CPF é obrigatório.
'
);
User
.
findOne
({
'
email
'
:
'
lorem@ipsum.com
'
},
(
err
,
user
)
=>
{
expect
(
user
).
to
.
not
.
exist
;
done
();
});
});
});
it
(
'
should not save an user without CPF
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
post
(
'
/api/v1/user
'
)
.
set
(
'
content-type
'
,
'
application/x-www-form-urlencoded
'
)
.
set
(
'
x-apicache-bypass
'
,
'
true
'
)
.
send
({
email
:
'
lorem@ipsum.com
'
,
password
:
'
123mudar
'
,
name
:
'
Tequila baby
'
,
cpf
:
'
48303270737
'
,
course
:
'
Ciência da Computação
'
,
segment
:
'
Comunidade acadêmica
'
,
role
:
'
Pesquisador
'
,
institution_name
:
'
UFPR
'
,
state
:
'
PR
'
,
city
:
'
Cutiriba
'
})
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
success
'
);
res
.
body
.
success
.
should
.
equal
(
false
);
res
.
body
.
should
.
have
.
property
(
'
msg
'
);
res
.
body
.
msg
.
should
.
equal
(
'
O campo Escolaridade é obrigatório.
'
);
User
.
findOne
({
'
email
'
:
'
lorem@ipsum.com
'
},
(
err
,
user
)
=>
{
expect
(
user
).
to
.
not
.
exist
;
done
();
});
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment