Commit e1a35380 by source_reader

refactored test suite

parent eaf2a1d5
require 'rails_helper'
RSpec.describe JouleModulesController, type: :controller do
end
......@@ -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)
......
......@@ -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
......
......@@ -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")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment