Skip to content

Commit

Permalink
Tests (#59)
Browse files Browse the repository at this point in the history
* registration and rake tests

* rubocop changes

Co-authored-by: Jesus Federico <jesus@123it.ca>
  • Loading branch information
Billzzhang and jfederico committed Jun 4, 2021
1 parent cd0c1c8 commit 5ce3f0a
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ process.yml
localhost.crt
localhost.key

/public/assets
/public/assets

# ignore rspec coverage
coverage/*
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'dotenv-rails'
gem 'rails-controller-testing'
gem 'rspec'
gem 'rspec-rails'
end
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ GEM
bundler (>= 1.3.0)
railties (= 6.0.3.7)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
Expand Down Expand Up @@ -383,6 +387,7 @@ DEPENDENCIES
pg (>= 0.4.4)
puma (>= 4.3.5)
rails (>= 6.0.3.3)
rails-controller-testing
rails_lti2_provider!
react-rails
redis (~> 4.2)
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/db_tenants.rake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace :db do
exit(1)
end
puts("Deleting keys for tenant '#{tenant.uid}'")
RailsLti2Provider::Tool.delete_all(tenant: tenant)
RailsLti2Provider::Tool.delete_by(tenant: tenant)
puts("Deleting tenant '#{tenant.uid}'")
tenant.delete
rescue StandardError => e
Expand All @@ -60,7 +60,7 @@ namespace :db do
next if tenant.uid.empty?

puts("Deleting keys for tenant '#{tenant.uid}'")
RailsLti2Provider::Tool.delete_all(tenant: tenant)
RailsLti2Provider::Tool.delete_by(tenant: tenant)
puts("Deleting tenant '#{tenant.uid}'")
tenant.delete
end
Expand Down
93 changes: 93 additions & 0 deletions spec/controllers/registration_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# frozen_string_literal: true

# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

require 'rails_helper'

RSpec.describe(RegistrationController, type: :controller) do
before do
ENV['DEVELOPER_MODE_ENABLED'] = 'true'
tenant = RailsLti2Provider::Tenant.create!(uid: '')
reg = {
issuer: 'issuer',
client_id: 'client_id',
key_set_url: 'key_set_url',
auth_token_url: 'auth_token_url',
auth_login_url: 'auth_login_url',
}
@app = RailsLti2Provider::Tool.create!(
uuid: 'issuer',
shared_secret: 'client_id',
tool_settings: reg.to_json,
lti_version: '1.3.0',
tenant: tenant
)
end

describe 'GET registration/new' do
it 'gives a successful response' do
get :new
expect(response).to(be_successful)
end
end

describe 'POST registration/submit' do
it 'adds another tool' do
post :submit, params: {
iss: 'test.com',
client_id: 'test_secret',
key_set_url: 'key.test.com',
auth_token_url: 'auth-token.test.com',
auth_login_url: 'auth-login.test.com',
}
expect(response).to(redirect_to(:registration_list))
end
end

describe 'GET registration/list' do
it 'gives a successful response' do
get :list
expect(response).to(be_successful)
end

it 'gives a proper list of all items' do
get :list
current_tools = RailsLti2Provider::Tool.where(lti_version: '1.3.0').pluck(:tool_settings)
current_tools.map! do |reg|
JSON.parse(reg)
end
expect(assigns(:registrations)).to(eq(current_tools))
end
end

describe 'GET registration/edit' do
it 'gives a successful response' do
get :edit, params: { client_id: @app.shared_secret, reg_id: @app.uuid }
expect(response).to(be_successful)
end
it 'edits an existing tool' do
post :submit, params: {
iss: 'test.com',
client_id: 'test_secret',
key_set_url: 'edit-key.test.com',
auth_token_url: 'edit-auth-token.test.com',
auth_login_url: 'edit-auth-login.test.com',
}
expect(response).to(redirect_to(:registration_list))
end
end
end
47 changes: 47 additions & 0 deletions spec/rake_tasks/rake_apps_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

require 'rails_helper'
require 'rake'

RSpec.describe('rake tasks involving apps') do
before do
Rake.application.rake_require('tasks/db_apps')
Rake::Task.define_task(:environment)

@app = Doorkeeper::Application.create!(name: 'test-app', uid: 'key', secret: 'secret', \
redirect_uri: 'https://test.example.com', scopes: 'api')
end
describe 'calling db:app' do
it 'displays the existing app' do
appinfo ||= @app.attributes.select { |key, _value| %w[name uid secret redirect_uri].include?(key) }
expect do
Rake.application.invoke_task('db:apps:showall')
end.to(output(appinfo.to_json + "\n").to_stdout)
end
it 'and adding an app' do
Rake.application.invoke_task('db:apps:add[test-add-app,https://test.example.com,key-add,secret-add]')
end
it 'and updating an app' do
Rake.application.invoke_task('db:apps:update[test-app,https://test.example.com,key-updated,secret-updated]')
end
it 'and deleting an app' do
Rake.application.invoke_task('db:apps:delete[test-app]')
end
end
end
57 changes: 57 additions & 0 deletions spec/rake_tasks/rake_keys_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

require 'rails_helper'
require 'rake'

RSpec.describe('rake tasks involving keys') do
before do
Rake.application.rake_require('tasks/db_keys')
Rake::Task.define_task(:environment)

@tenant = RailsLti2Provider::Tenant.create!(uid: 'tenant')
@other_tenant = RailsLti2Provider::Tenant.create!(uid: 'other-tenant')
@single_tenant_key = RailsLti2Provider::Tool.create!(uuid: 'single-key', shared_secret: 'secret', lti_version: 'LTI-1p0',
tool_settings: 'none', tenant: RailsLti2Provider::Tenant.create!(uid: ''))
@multi_tenant_key = RailsLti2Provider::Tool.create!(uuid: 'multi-key', shared_secret: 'secret', lti_version: 'LTI-1p0',
tool_settings: 'none', tenant: @tenant)
end
describe 'calling db:keys' do
it 'displays the existing keys' do
expected_keys_text = "'single-key'='secret'\n'multi-key'='secret' for tenant 'tenant'\n"
expect do
Rake.application.invoke_task('db:keys:showall')
end.to(output(expected_keys_text).to_stdout)
end
it 'and adding an key in single tenant' do
Rake.application.invoke_task('db:keys:add[single-test-key, secret]')
end
it 'and adding an key in multi tenant' do
Rake.application.invoke_task('db:keys:add[single-test-key, secret, tenant]')
end
it 'and updating an key in single tenant' do
Rake.application.invoke_task('db:keys:update[single-key,secret-updated]')
end
it 'and updating an key in multi tenant' do
Rake.application.invoke_task('db:keys:update[multi-key,secret-updated, other-tenant]')
end
it 'and deleting an key' do
Rake.application.invoke_task('db:keys:delete[single-key]')
end
end
end
46 changes: 46 additions & 0 deletions spec/rake_tasks/rake_tenant_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

require 'rails_helper'
require 'rake'

RSpec.describe('rake tasks involving tenants') do
before do
Rake.application.rake_require('tasks/db_tenants')
Rake::Task.define_task(:environment)
@tenant = RailsLti2Provider::Tenant.create!(uid: 'tenant')
end

describe 'calling db:tenants' do
it 'and displays the tenant' do
tenant_text = /Tenant with uid 'tenant'/
expect do
Rake.application.invoke_task('db:tenants:showall')
end.to(output(tenant_text).to_stdout)
end
it 'and adds a tenant' do
Rake.application.invoke_task('db:tenants:add[test-tenant]')
end
it 'and deletes a tenant' do
Rake.application.invoke_task('db:tenants:delete[tenant]')
end
it 'and deletes all tenants' do
Rake.application.invoke_task('db:tenants:deleteall')
end
end
end

0 comments on commit 5ce3f0a

Please sign in to comment.