aboutsummaryrefslogtreecommitdiff
path: root/test/controllers/backends
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-04-03 07:52:00 +0100
committerChristopher Baines <mail@cbaines.net>2018-04-03 21:58:55 +0100
commit9e622112a80f493eab53420d7dafedb9dd10a612 (patch)
tree6a21d19f6ff7ae72db8510f8e0ae813bb8a49045 /test/controllers/backends
parenta29946a593988003cbd4637293c5b4cc1aee7eaa (diff)
downloadgovuk-mini-environment-admin-9e622112a80f493eab53420d7dafedb9dd10a612.tar
govuk-mini-environment-admin-9e622112a80f493eab53420d7dafedb9dd10a612.tar.gz
Improve the test suite
Add some tests, and setup the helpers. For some reason, directly running the test files requires the ugly `ENV['RAILS_ENV'] = 'test'` line at the top of the test_helper.rb file.
Diffstat (limited to 'test/controllers/backends')
-rw-r--r--test/controllers/backends/terraform_aws_controller_test.rb85
-rw-r--r--test/controllers/backends/terraform_libvirt_controller_test.rb77
2 files changed, 152 insertions, 10 deletions
diff --git a/test/controllers/backends/terraform_aws_controller_test.rb b/test/controllers/backends/terraform_aws_controller_test.rb
index 0c574fa..41373b8 100644
--- a/test/controllers/backends/terraform_aws_controller_test.rb
+++ b/test/controllers/backends/terraform_aws_controller_test.rb
@@ -1,14 +1,89 @@
-require 'test_helper'
+require 'integration_test_helper'
class Backends::TerraformAwsControllerTest < ActionDispatch::IntegrationTest
- test "should get new" do
- get backends_terraform_aws_new_url
+ setup do
+ login_as User.new(name: 'Test', email: 'test@example.com')
+ end
+
+ test 'new' do
+ get new_terraform_aws_backend_path
+ assert_response :success
+ end
+
+ test 'create' do
+ attributes = {
+ label: 'Test Backend',
+ aws_region: 'test-region',
+ aws_access_key_id: 'test-access-key-id',
+ aws_secret_access_key: 'test-secret-access-key'
+ }
+
+ post(
+ terraform_aws_backends_path,
+ params: {
+ backends_terraform_aws: attributes
+ }
+ )
+
+ assert_response :redirect
+ follow_redirect!
+ assert_response :success
+
+ backend = Backends::TerraformAws.last
+ attributes.each do |(key, value)|
+ assert_equal backend.send(key), value
+ end
+ end
+
+ test 'update' do
+ backend = Backends::TerraformAws.create(
+ label: 'Old label',
+ aws_region: 'old-test-region',
+ aws_access_key_id: 'old-test-access-key-id',
+ aws_secret_access_key: 'old-test-secret-access-key'
+ )
+
+ new_attributes = {
+ label: 'New label',
+ aws_access_key_id: 'new-test-access-key-id',
+ aws_secret_access_key: 'new-test-secret-access-key'
+ }
+
+ put(
+ terraform_aws_backend_path(backend),
+ params: {
+ backends_terraform_aws: new_attributes
+ }
+ )
+
assert_response :success
+
+ backend.reload
end
- test "should get show" do
- get backends_terraform_aws_show_url
+ test 'show' do
+ backend = Backends::TerraformAws.create(
+ label: 'Test Backend',
+ aws_region: 'old-test-region',
+ aws_access_key_id: 'old-test-access-key-id',
+ aws_secret_access_key: 'old-test-secret-access-key'
+ )
+
+ get terraform_aws_backend_path(backend)
+
assert_response :success
end
+ test 'destroy' do
+ backend = Backends::TerraformAws.create(
+ label: 'Test Backend',
+ aws_region: 'old-test-region',
+ aws_access_key_id: 'old-test-access-key-id',
+ aws_secret_access_key: 'old-test-secret-access-key'
+ )
+
+ delete terraform_aws_backend_path(backend)
+
+ assert_response :redirect
+ end
end
diff --git a/test/controllers/backends/terraform_libvirt_controller_test.rb b/test/controllers/backends/terraform_libvirt_controller_test.rb
index 376d753..b34a8ac 100644
--- a/test/controllers/backends/terraform_libvirt_controller_test.rb
+++ b/test/controllers/backends/terraform_libvirt_controller_test.rb
@@ -1,14 +1,81 @@
-require 'test_helper'
+require 'integration_test_helper'
class Backends::TerraformLibvirtControllerTest < ActionDispatch::IntegrationTest
- test "should get new" do
- get backends_terraform_libvirt_new_url
+ setup do
+ login_as User.new(name: 'Test', email: 'test@example.com')
+ end
+
+ test 'new' do
+ get new_terraform_aws_backend_path
assert_response :success
end
- test "should get show" do
- get backends_terraform_libvirt_show_url
+ test 'create' do
+ attributes = {
+ label: 'Test Backend',
+ domain: 'test.backend.example.com',
+ uri: 'test://uri'
+ }
+
+ post(
+ terraform_libvirt_backends_path,
+ params: {
+ backends_terraform_libvirt: attributes
+ }
+ )
+
+ assert_response :redirect
+ follow_redirect!
assert_response :success
+
+ backend = Backends::TerraformLibvirt.last
+ attributes.each do |(key, value)|
+ assert_equal backend.send(key), value
+ end
end
+ test 'update' do
+ backend = Backends::TerraformLibvirt.create(
+ label: 'Old label',
+ domain: 'old.domain.example.com',
+ uri: 'old://uri'
+ )
+
+ new_attributes = {
+ label: 'New label'
+ }
+
+ put(
+ terraform_libvirt_backend_path(backend),
+ params: {
+ backends_terraform_libvirt: new_attributes
+ }
+ )
+
+ assert_response :success
+ end
+
+ test 'show' do
+ backend = Backends::TerraformLibvirt.create(
+ label: 'Test Backend',
+ domain: 'test.backend.example.com',
+ uri: 'test://uri'
+ )
+
+ get terraform_libvirt_backend_path(backend)
+
+ assert_response :success
+ end
+
+ test 'destroy' do
+ backend = Backends::TerraformLibvirt.create(
+ label: 'Test Backend',
+ domain: 'test.backend.example.com',
+ uri: 'test://uri'
+ )
+
+ delete terraform_libvirt_backend_path(backend)
+
+ assert_response :redirect
+ end
end