Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Back-end_Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Agendador
Back-end_Server
Commits
bf3f803b
Commit
bf3f803b
authored
Aug 17, 2016
by
Mateus Ravedutti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Professionals test draft
parent
f4b04b61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
25 deletions
+85
-25
test/controllers/professionals_controller_test.rb
test/controllers/professionals_controller_test.rb
+85
-25
No files found.
test/controllers/professionals_controller_test.rb
View file @
bf3f803b
require
'test_helper'
class
ProfessionalsControllerTest
<
ActionDispatch
::
IntegrationTest
def
professional
@professional
||=
professionals
:one
end
class
Api::V1::ProfessionalsControllerTest
<
ActionDispatch
::
IntegrationTest
describe
"Token access"
do
before
do
@citizen
=
Citizen
.
new
(
cpf:
"123.456.789-04"
,
birth_date:
"18/04/1997"
,
cep:
"1234567"
,
email:
"test@example.com"
,
name:
"Test Example"
,
phone1:
"(12)1212-1212"
,
rg:
"1234567"
)
@account
=
Account
.
new
(
uid:
@citizen
.
cpf
,
password:
"123mudar"
,
password_confirmation:
"123mudar"
)
@professional
=
Professional
.
new
(
active:
true
,
registration:
"123"
)
@account
.
save!
@professional
.
account_id
=
@account
.
id
@professional
.
save!
@professional
.
account_id
=
@account
.
id
@professional
.
save!
def
test_index
get
professionals_url
assert_response
:success
end
@auth_headers
=
@account
.
create_new_auth_token
def
test_create
assert_difference
(
'Professional.count'
)
do
post
professionals_url
,
params:
{
professional:
{
}
}
@token
=
@auth_headers
[
'access-token'
]
@client_id
=
@auth_headers
[
'client'
]
@expiry
=
@auth_headers
[
'expiry'
]
end
assert_response
201
end
describe
"Successful request to show professional"
do
before
do
get
'/v1/professionals/'
+
@professional
.
id
.
to_s
,
params:
{},
headers:
@auth_headers
def
test_show
get
professional_url
(
professional
)
assert_response
:success
end
@body
=
JSON
.
parse
(
response
.
body
)
@resp_token
=
response
.
headers
[
'access-token'
]
@resp_client_id
=
response
.
headers
[
'client'
]
@resp_expiry
=
response
.
headers
[
'expiry'
]
@resp_uid
=
response
.
headers
[
'uid'
]
end
def
test_update
patch
professional_url
(
professional
),
params:
{
professional:
{
}
}
assert_response
200
end
it
"should be successful"
do
assert_equal
200
,
response
.
status
end
it
"should correspond to the current account"
do
assert_equal
@body
[
"id"
],
@controller
.
current_account
.
professional
.
id
end
it
"should correspond to the professional in the database"
do
assert_equal
@body
[
"cpf"
],
Professional
.
find
(
@professional
.
id
).
account
.
citizen
.
cpf
end
end
describe
"Successful request to delete professional"
do
before
do
delete
'/v1/professionals/'
+
@professional
.
id
.
to_s
,
params:
{},
headers:
@auth_headers
def
test_destroy
assert_difference
(
'Professional.count'
,
-
1
)
do
delete
professional_url
(
professional
)
@resp_token
=
response
.
headers
[
'access-token'
]
@resp_client_id
=
response
.
headers
[
'client'
]
@resp_expiry
=
response
.
headers
[
'expiry'
]
@resp_uid
=
response
.
headers
[
'uid'
]
end
it
"should be successful"
do
assert_equal
204
,
response
.
status
end
it
"should have been deleted"
do
assert_nil
Professional
.
where
(
id:
@professional
.
id
).
first
end
end
assert_response
204
describe
"Successful request to update professional"
do
before
do
put
'/v1/professionals/'
+
@professional
.
id
.
to_s
,
params:
{
professional:
{
cep:
"7654321"
}},
headers:
@auth_headers
@resp_token
=
response
.
headers
[
'access-token'
]
@resp_client_id
=
response
.
headers
[
'client'
]
@resp_expiry
=
response
.
headers
[
'expiry'
]
@resp_uid
=
response
.
headers
[
'uid'
]
end
it
"should be successful"
do
assert_equal
200
,
response
.
status
end
test
"cpf should have been changed"
do
@professional
=
Citizen
.
where
(
cpf:
@professional
.
cpf
).
first
.
account
.
professional
assert_equal
"7654321"
,
@professional
.
account
.
citizen
.
cep
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment