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
e1a35380
authored
Sep 16, 2019
by
source_reader
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
refactored test suite
parent
eaf2a1d5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
22 deletions
spec/controllers/joule_modules_controller_spec.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
spec/controllers/joule_modules_controller_spec.rb
deleted
100644 → 0
View file @
eaf2a1d5
require
'rails_helper'
RSpec
.
describe
JouleModulesController
,
type: :controller
do
end
spec/controllers/nilms_controller_spec.rb
View file @
e1a35380
...
...
@@ -171,7 +171,8 @@ RSpec.describe NilmsController, type: :request do
it
'creates a NILM'
do
user_params
=
{
email:
"bob@email.com"
,
password:
"password"
,
first_name:
"Bob"
,
last_name:
"Test"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:ok
)
...
...
@@ -187,7 +188,8 @@ RSpec.describe NilmsController, type: :request do
# all user parameters must be present
user_params
=
{
email:
"bob@email.com"
,
password:
"password"
,
first_name:
"Bob"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
...
...
@@ -203,7 +205,8 @@ RSpec.describe NilmsController, type: :request do
owner
=
create
(
:user
)
NilmAuthKey
.
create
(
user:
owner
,
key:
"valid_key"
)
user_params
=
{
auth_key:
"valid_key"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:ok
)
...
...
@@ -219,7 +222,8 @@ RSpec.describe NilmsController, type: :request do
create
(
:user
)
user_params
=
{
email:
"bob@email.com"
,
password:
"password"
,
first_name:
"Bob"
,
last_name:
"Test"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
...
...
@@ -232,7 +236,8 @@ RSpec.describe NilmsController, type: :request do
it
'requires valid auth key'
do
create
(
:user
)
user_params
=
{
auth_key:
"invalid"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
...
...
@@ -245,7 +250,8 @@ RSpec.describe NilmsController, type: :request do
owner
=
create
(
:user
)
NilmAuthKey
.
create
(
user:
owner
,
key:
"valid_key"
)
user_params
=
{
auth_key:
"valid_key"
}
nilm_params
=
{
name:
"Missing port param"
,
api_key:
"api_key"
,
scheme:
"http"
}
nilm_params
=
{
name:
"Missing port param"
,
api_key:
"api_key"
,
scheme:
"http"
,
base_uri:
"/joule"
}
post
"/nilms.json"
,
params:
user_params
.
merge
(
nilm_params
)
expect
(
response
).
to
have_http_status
(
:unprocessable_entity
)
...
...
spec/services/nilm/add_nilm_by_key_spec.rb
View file @
e1a35380
...
...
@@ -9,7 +9,8 @@ RSpec.describe 'AddNilmByKey' do
key
.
save!
user_params
=
{
auth_key:
"random_key"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
request_params
=
ActionController
::
Parameters
.
new
(
user_params
.
merge
(
nilm_params
))
service
=
AddNilmByKey
.
new
...
...
@@ -17,7 +18,7 @@ RSpec.describe 'AddNilmByKey' do
expect
(
service
.
success?
).
to
be
true
# creates the nilm
nilm
=
service
.
nilm
expect
(
nilm
.
url
).
to
eq
"http://127.0.0.1:8088"
expect
(
nilm
.
url
).
to
eq
"http://127.0.0.1:8088
/joule
"
expect
(
nilm
.
name
).
to
eq
"Test Node"
expect
(
nilm
.
key
).
to
eq
"api_key"
# owner is an admin for the nilm
...
...
@@ -31,7 +32,8 @@ RSpec.describe 'AddNilmByKey' do
it
'requires valid auth key'
do
service
=
AddNilmByKey
.
new
user_params
=
{
auth_key:
"invalid"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
request_params
=
ActionController
::
Parameters
.
new
(
user_params
.
merge
(
nilm_params
))
service
.
run
(
request_params
,
"127.0.0.1"
)
expect
(
service
.
success?
).
to
be
false
...
...
@@ -43,14 +45,15 @@ RSpec.describe 'AddNilmByKey' do
it
'forwards nilm errors'
do
nilm
=
create
(
:nilm
)
nilm
.
url
=
"http://127.0.0.1:8088"
nilm
.
url
=
"http://127.0.0.1:8088
/joule
"
nilm
.
save!
owner
=
create
(
:user
)
key
=
NilmAuthKey
.
new
(
key:
"random_key"
,
user:
owner
)
key
.
save!
user_params
=
{
auth_key:
"random_key"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
request_params
=
ActionController
::
Parameters
.
new
(
user_params
.
merge
(
nilm_params
))
service
=
AddNilmByKey
.
new
...
...
spec/services/nilm/add_nilm_by_user_spec.rb
View file @
e1a35380
...
...
@@ -7,14 +7,15 @@ RSpec.describe 'AddNilmByUser' do
service
=
AddNilmByUser
.
new
user_params
=
{
email:
"bob@email.com"
,
password:
"password"
,
first_name:
"Bob"
,
last_name:
"Test"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
request_params
=
ActionController
::
Parameters
.
new
(
user_params
.
merge
(
nilm_params
))
service
.
run
(
request_params
,
"127.0.0.1"
)
expect
(
service
.
success?
).
to
be
true
# creates the nilm
nilm
=
service
.
nilm
expect
(
nilm
.
url
).
to
eq
"http://127.0.0.1:8088"
expect
(
nilm
.
url
).
to
eq
"http://127.0.0.1:8088
/joule
"
expect
(
nilm
.
name
).
to
eq
"Test Node"
expect
(
nilm
.
key
).
to
eq
"api_key"
# creates the user associated with the nilm
...
...
@@ -27,7 +28,8 @@ RSpec.describe 'AddNilmByUser' do
service
=
AddNilmByUser
.
new
user_params
=
{
password:
"missing_email"
,
first_name:
"Bob"
,
last_name:
"Test"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
request_params
=
ActionController
::
Parameters
.
new
(
user_params
.
merge
(
nilm_params
))
service
.
run
(
request_params
,
"127.0.0.1"
)
expect
(
service
.
success?
).
to
be
false
...
...
@@ -42,7 +44,8 @@ RSpec.describe 'AddNilmByUser' do
service
=
AddNilmByUser
.
new
user_params
=
{
email:
"bob@email.com"
,
password:
"short"
,
first_name:
"Bob"
,
last_name:
"Test"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
request_params
=
ActionController
::
Parameters
.
new
(
user_params
.
merge
(
nilm_params
))
service
.
run
(
request_params
,
"127.0.0.1"
)
expect
(
service
.
success?
).
to
be
false
...
...
@@ -56,13 +59,14 @@ RSpec.describe 'AddNilmByUser' do
it
'forwards nilm errors'
do
nilm
=
create
(
:nilm
)
nilm
.
url
=
"http://127.0.0.1:8088"
nilm
.
url
=
"http://127.0.0.1:8088
/joule
"
nilm
.
save!
service
=
AddNilmByUser
.
new
user_params
=
{
email:
"bob@email.com"
,
password:
"password"
,
first_name:
"Bob"
,
last_name:
"Test"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
}
nilm_params
=
{
name:
"Test Node"
,
api_key:
"api_key"
,
port:
8088
,
scheme:
"http"
,
base_uri:
"/joule"
}
request_params
=
ActionController
::
Parameters
.
new
(
user_params
.
merge
(
nilm_params
))
service
.
run
(
request_params
,
"127.0.0.1"
)
...
...
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