Created
February 23, 2016 19:28
-
-
Save adam-phillipps/5027f4f76a36d6de4e40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe 'User Registration class' do | |
let(:name) { SecureRandom.hex } | |
let(:required_params) do | |
{ | |
name: name, | |
email: "#{name}[email protected]", | |
catalog_id: ENV['CATALOG_ACCOUNT_ID'] | |
} | |
end | |
let(:correct_response_keys) do | |
['canvas_user_id', 'name', 'email', 'custom_fields', 'created_at', 'updated_at', { 'catalog' => ['id', 'name'] }] | |
end | |
it 'should be able to create a basic registration' do | |
registration = CatalogFactory::UserRegistration.create! required_params | |
expect(registration.canvas_user_id).not_to be nil | |
end | |
it 'should be able to create a registration in a child catalog' do | |
child_catalog_params = required_params | |
child_catalog_params[:catalog_id] = 2 | |
registration = CatalogFactory::UserRegistration.create! child_catalog_params | |
expect(registration.catalog_id).to eq(2) | |
end | |
it 'should get back a full, valid response from the api call' do | |
registration = CatalogFactory::UserRegistration.create! required_params | |
validate_response(registration, required_params) | |
end | |
it 'should throw an error if the given catalog doesn\'t exist' do | |
child_catalog_params = required_params | |
child_catalog_params[:catalog_id] = 0 | |
byebug | |
registration = CatalogFactory::UserRegistration.create! child_catalog_params | |
byebug | |
end | |
def validate_response(response, desired_outcome) | |
desired_outcome.each do |attr, value| | |
if response.catalog_response.include?(attr.to_s) | |
expect(response.catalog_response[attr.to_s]).to eq(value) | |
else | |
response.catalog_response.select { |key| key[1].kind_of?(Hash) }.each do |k,v| | |
expect(response.catalog_response[k]).to eq(value) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment