Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3d8490e9
authored
May 09, 2019
by
source_reader
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
refactored tests to meet new API requirements
parent
1d8ab2ba
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
13 deletions
app/services/nilm/add_nilm_by_key.rb
spec/controllers/nilms_controller_spec.rb
spec/services/nilm/add_nilm_by_key_spec.rb
spec/services/nilm/add_nilm_by_user_spec.rb
app/services/nilm/add_nilm_by_key.rb
View file @
3d8490e9
...
@@ -38,7 +38,6 @@ class AddNilmByKey
...
@@ -38,7 +38,6 @@ class AddNilmByKey
url
.
host
=
host
url
.
host
=
host
url
.
port
=
joule_params
[
:port
]
url
.
port
=
joule_params
[
:port
]
url
.
scheme
=
joule_params
[
:scheme
]
url
.
scheme
=
joule_params
[
:scheme
]
puts
"using url
#{
url
}
"
#3 Create the Nilm
#3 Create the Nilm
adapter
=
Joule
::
Adapter
.
new
(
url
,
joule_params
[
:api_key
])
adapter
=
Joule
::
Adapter
.
new
(
url
,
joule_params
[
:api_key
])
service
=
CreateNilm
.
new
(
adapter
)
service
=
CreateNilm
.
new
(
adapter
)
...
...
spec/controllers/nilms_controller_spec.rb
View file @
3d8490e9
...
@@ -175,8 +175,6 @@ RSpec.describe NilmsController, type: :request do
...
@@ -175,8 +175,6 @@ RSpec.describe NilmsController, type: :request do
post
"/nilms.json"
,
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
).
to
have_http_status
(
:ok
)
#should have a warning that NILM cannot see database
expect
(
response
).
to
have_warning_message
# make sure the NILM was built
# make sure the NILM was built
nilm
=
Nilm
.
find_by_name
(
'Test Node'
)
nilm
=
Nilm
.
find_by_name
(
'Test Node'
)
expect
(
nilm
).
to_not
be
nil
expect
(
nilm
).
to_not
be
nil
...
@@ -193,7 +191,8 @@ RSpec.describe NilmsController, type: :request do
...
@@ -193,7 +191,8 @@ RSpec.describe NilmsController, type: :request do
post
"/nilms.json"
,
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_error_message
# has an error message
expect
(
response
.
body
).
to
match
(
"last_name"
)
# make sure the NILM was not built
# make sure the NILM was not built
expect
(
Nilm
.
count
).
to
eq
0
expect
(
Nilm
.
count
).
to
eq
0
expect
(
User
.
count
).
to
eq
0
expect
(
User
.
count
).
to
eq
0
...
@@ -208,8 +207,6 @@ RSpec.describe NilmsController, type: :request do
...
@@ -208,8 +207,6 @@ RSpec.describe NilmsController, type: :request do
post
"/nilms.json"
,
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
).
to
have_http_status
(
:ok
)
#should have a warning that NILM cannot see database
expect
(
response
).
to
have_warning_message
# make sure the NILM was built
# make sure the NILM was built
nilm
=
Nilm
.
find_by_name
(
'Test Node'
)
nilm
=
Nilm
.
find_by_name
(
'Test Node'
)
expect
(
nilm
).
to_not
be
nil
expect
(
nilm
).
to_not
be
nil
...
@@ -226,7 +223,7 @@ RSpec.describe NilmsController, type: :request do
...
@@ -226,7 +223,7 @@ RSpec.describe NilmsController, type: :request do
post
"/nilms.json"
,
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_error_message
/auth_key/
expect
(
response
.
body
).
to
match
(
"auth_key"
)
# make sure the NILM was not built
# make sure the NILM was not built
expect
(
Nilm
.
count
).
to
eq
0
expect
(
Nilm
.
count
).
to
eq
0
expect
(
User
.
count
).
to
eq
1
expect
(
User
.
count
).
to
eq
1
...
@@ -239,7 +236,7 @@ RSpec.describe NilmsController, type: :request do
...
@@ -239,7 +236,7 @@ RSpec.describe NilmsController, type: :request do
post
"/nilms.json"
,
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_error_message
/authorization/
expect
(
response
.
body
).
to
match
(
"invalid"
)
# make sure the NILM was not built
# make sure the NILM was not built
expect
(
Nilm
.
count
).
to
eq
0
expect
(
Nilm
.
count
).
to
eq
0
expect
(
User
.
count
).
to
eq
1
expect
(
User
.
count
).
to
eq
1
...
@@ -252,7 +249,7 @@ RSpec.describe NilmsController, type: :request do
...
@@ -252,7 +249,7 @@ RSpec.describe NilmsController, type: :request do
post
"/nilms.json"
,
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
expect
(
response
).
to
have_error_message
expect
(
response
.
body
).
to
match
(
"port"
)
# make sure the NILM was not built
# make sure the NILM was not built
expect
(
Nilm
.
count
).
to
eq
0
expect
(
Nilm
.
count
).
to
eq
0
# user still exists and has an auth key
# user still exists and has an auth key
...
...
spec/services/nilm/add_nilm_by_key_spec.rb
View file @
3d8490e9
...
@@ -17,7 +17,7 @@ RSpec.describe 'AddNilmByKey' do
...
@@ -17,7 +17,7 @@ RSpec.describe 'AddNilmByKey' do
expect
(
service
.
success?
).
to
be
true
expect
(
service
.
success?
).
to
be
true
# creates the nilm
# creates the nilm
nilm
=
service
.
nilm
nilm
=
service
.
nilm
expect
(
nilm
.
url
).
to
eq
"http://
localhost
:8088"
expect
(
nilm
.
url
).
to
eq
"http://
127.0.0.1
:8088"
expect
(
nilm
.
name
).
to
eq
"Test Node"
expect
(
nilm
.
name
).
to
eq
"Test Node"
expect
(
nilm
.
key
).
to
eq
"api_key"
expect
(
nilm
.
key
).
to
eq
"api_key"
# owner is an admin for the nilm
# owner is an admin for the nilm
...
@@ -43,7 +43,7 @@ RSpec.describe 'AddNilmByKey' do
...
@@ -43,7 +43,7 @@ RSpec.describe 'AddNilmByKey' do
it
'forwards nilm errors'
do
it
'forwards nilm errors'
do
nilm
=
create
(
:nilm
)
nilm
=
create
(
:nilm
)
nilm
.
url
=
"http://
localhost
:8088"
nilm
.
url
=
"http://
127.0.0.1
:8088"
nilm
.
save!
nilm
.
save!
owner
=
create
(
:user
)
owner
=
create
(
:user
)
key
=
NilmAuthKey
.
new
(
key:
"random_key"
,
user:
owner
)
key
=
NilmAuthKey
.
new
(
key:
"random_key"
,
user:
owner
)
...
...
spec/services/nilm/add_nilm_by_user_spec.rb
View file @
3d8490e9
...
@@ -14,7 +14,7 @@ RSpec.describe 'AddNilmByUser' do
...
@@ -14,7 +14,7 @@ RSpec.describe 'AddNilmByUser' do
expect
(
service
.
success?
).
to
be
true
expect
(
service
.
success?
).
to
be
true
# creates the nilm
# creates the nilm
nilm
=
service
.
nilm
nilm
=
service
.
nilm
expect
(
nilm
.
url
).
to
eq
"http://
localhost
:8088"
expect
(
nilm
.
url
).
to
eq
"http://
127.0.0.1
:8088"
expect
(
nilm
.
name
).
to
eq
"Test Node"
expect
(
nilm
.
name
).
to
eq
"Test Node"
expect
(
nilm
.
key
).
to
eq
"api_key"
expect
(
nilm
.
key
).
to
eq
"api_key"
# creates the user associated with the nilm
# creates the user associated with the nilm
...
@@ -56,7 +56,7 @@ RSpec.describe 'AddNilmByUser' do
...
@@ -56,7 +56,7 @@ RSpec.describe 'AddNilmByUser' do
it
'forwards nilm errors'
do
it
'forwards nilm errors'
do
nilm
=
create
(
:nilm
)
nilm
=
create
(
:nilm
)
nilm
.
url
=
"http://
localhost
:8088"
nilm
.
url
=
"http://
127.0.0.1
:8088"
nilm
.
save!
nilm
.
save!
service
=
AddNilmByUser
.
new
service
=
AddNilmByUser
.
new
...
...
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