Skip to content

Commit

Permalink
Merge pull request #15 from sampatbadhe/improve_specs
Browse files Browse the repository at this point in the history
Improve specs
  • Loading branch information
sampatbadhe authored Oct 26, 2019
2 parents 3bb1c55 + 02dd7dc commit 08a895b
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 183 deletions.
20 changes: 11 additions & 9 deletions spec/dotloop/authenticate_spec.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
# frozen_string_literal: true

require 'spec_helper'

describe Dotloop::Authenticate do
let(:app_id) { 'abc' }
let(:app_secret) { 'secret' }
let(:application) { 'blah' }
subject { Dotloop::Authenticate.new(app_id: app_id, app_secret: app_secret, application: application) }
subject(:dotloop_auth) { Dotloop::Authenticate.new(app_id: app_id, app_secret: app_secret, application: application) }

describe '#initialize' do
it 'take an app id' do
expect(subject).to be_a(Dotloop::Authenticate)
expect(subject.app_id).to eq('abc')
expect(dotloop_auth).to be_a(Dotloop::Authenticate)
expect(dotloop_auth.app_id).to eq('abc')
end

context 'without application' do
subject { Dotloop::Authenticate.new(app_id: app_id, app_secret: app_secret) }
subject(:dotloop_auth) { Dotloop::Authenticate.new(app_id: app_id, app_secret: app_secret) }

it 'default the application name to dotloop' do
expect(subject.application).to eq('dotloop')
expect(dotloop_auth.application).to eq('dotloop')
end
end

it 'take an application name' do
expect(subject.application).to eq('blah')
expect(dotloop_auth.application).to eq('blah')
end

it 'take an app secret' do
expect(subject.app_secret).to eq('secret')
expect(dotloop_auth.app_secret).to eq('secret')
end

context 'without an app id' do
let(:app_id) { nil }
it 'raise the error' do
expect { subject }.to raise_error RuntimeError
expect { dotloop_auth }.to raise_error RuntimeError
end
end

context 'without an app secret' do
let(:app_secret) { nil }
it 'raise the error' do
expect { subject }.to raise_error RuntimeError
expect { dotloop_auth }.to raise_error RuntimeError
end
end
end
Expand Down
48 changes: 41 additions & 7 deletions spec/dotloop/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# frozen_string_literal: true

require 'spec_helper'

describe Dotloop::Client do
let(:access_token) { 'blah' }
let(:application) { 'bloh' }
subject { Dotloop::Client.new(access_token: access_token, application: application) }
subject(:dotloop_client) { Dotloop::Client.new(access_token: access_token, application: application) }

describe '#initialize' do
it 'take an access token' do
expect(subject).to be_a(Dotloop::Client)
expect(subject.access_token).to eq('blah')
expect(dotloop_client).to be_a(Dotloop::Client)
expect(dotloop_client.access_token).to eq('blah')
end

context 'without application' do
subject { Dotloop::Client.new(access_token: access_token) }
subject(:dotloop_client) { Dotloop::Client.new(access_token: access_token) }

it 'default the application name to dotloop' do
expect(subject.application).to eq('dotloop')
expect(dotloop_client.application).to eq('dotloop')
end
end

it 'take an application name' do
expect(subject.application).to eq('bloh')
expect(dotloop_client.application).to eq('bloh')
end

context 'without an api key' do
let(:access_token) { nil }
it 'raise the error' do
expect { subject }.to raise_error RuntimeError
expect { dotloop_client }.to raise_error RuntimeError
end
end
end
Expand Down Expand Up @@ -57,6 +59,14 @@
end
end

context 'when there is a 400 error' do
let(:code) { 400 }
it 'raise an Unauthorized error' do
expect(subject.class).to receive(:get).with('foo', anything).and_return(response)
expect { subject.get('foo') }.to raise_error Dotloop::BadRequest
end
end

context 'when there is a 401 error' do
let(:code) { 401 }
it 'raise an Unauthorized error' do
Expand All @@ -73,6 +83,30 @@
end
end

context 'when there is a 404 error' do
let(:code) { 404 }
it 'raise an Forbidden error' do
expect(subject.class).to receive(:get).with('foo', anything).and_return(response)
expect { subject.get('foo') }.to raise_error Dotloop::NotFound
end
end

context 'when there is a 422 error' do
let(:code) { 422 }
it 'raise an Forbidden error' do
expect(subject.class).to receive(:get).with('foo', anything).and_return(response)
expect { subject.get('foo') }.to raise_error Dotloop::UnprocessableEntity
end
end

context 'when there is a 429 error' do
let(:code) { 429 }
it 'raise an Forbidden error' do
expect(subject.class).to receive(:get).with('foo', anything).and_return(response)
expect { subject.get('foo') }.to raise_error Dotloop::TooManyRequest
end
end

context 'when the response is a single object' do
it 'snake the camels' do
expect(subject.class).to receive(:get).and_return(response)
Expand Down
38 changes: 20 additions & 18 deletions spec/dotloop/contact_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# frozen_string_literal: true

require 'spec_helper'

describe Dotloop::Contact do
let(:client) { Dotloop::Client.new(access_token: SecureRandom.uuid) }
subject { Dotloop::Contact.new(client: client) }
subject(:dotloop_contact) { Dotloop::Contact.new(client: client) }

describe '#initialize' do
it 'exist' do
expect(subject).to_not be_nil
expect(dotloop_contact).to_not be_nil
end

it 'set the client' do
expect(subject.client).to eq(client)
expect(dotloop_contact.client).to eq(client)
end
end

describe '#all' do
it 'return all contacts' do
dotloop_mock_batch(:contacts)
contacts = subject.all()
contacts = dotloop_contact.all
expect(contacts.size).to eq(52)
expect(contacts).to all(be_a(Dotloop::Models::Contact))
end
Expand All @@ -26,7 +28,7 @@
describe '#find' do
it 'return a contact' do
dotloop_mock(:contact)
contact = subject.find(contact_id: 3_603_862)
contact = dotloop_contact.find(contact_id: 3_603_862)
expect(contact).to be_a(Dotloop::Models::Contact)
end
end
Expand All @@ -35,17 +37,17 @@
it 'return a contact' do
dotloop_mock(:contacts, :post, 201)
params = {
"firstName": "Brian",
"lastName": "Erwin",
"email": "[email protected]",
"home": "(415) 8936 332",
"office": "(415) 1213 656",
"fax": "(415) 8655 686",
"address": "2100 Waterview Dr",
"city": "San Francisco",
"zipCode": "94114",
"state": "CA",
"country": "US"
"firstName": 'Brian',
"lastName": 'Erwin',
"email": '[email protected]',
"home": '(415) 8936 332',
"office": '(415) 1213 656',
"fax": '(415) 8655 686',
"address": '2100 Waterview Dr',
"city": 'San Francisco',
"zipCode": '94114',
"state": 'CA',
"country": 'US'
}

contact = subject.create(params: params)
Expand All @@ -56,9 +58,9 @@
describe '#update' do
it 'return a contact' do
dotloop_mock(:contact, :patch)
contact = subject.update(contact_id: 3_603_862, params: { "home": "(415) 888 8888" })
contact = subject.update(contact_id: 3_603_862, params: { "home": '(415) 888 8888' })
expect(contact).to be_a(Dotloop::Models::Contact)
expect(contact).to have_attributes(home: "(415) 888 8888")
expect(contact).to have_attributes(home: '(415) 888 8888')
end
end

Expand Down
48 changes: 25 additions & 23 deletions spec/dotloop/document_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# frozen_string_literal: true

require 'spec_helper'

describe Dotloop::Document do
let(:client) { Dotloop::Client.new(access_token: SecureRandom.uuid) }
subject { Dotloop::Document.new(client: client) }
subject(:dotloop_document) { Dotloop::Document.new(client: client) }

describe '#initialize' do
it 'exist' do
expect(subject).to_not be_nil
expect(dotloop_document).to_not be_nil
end

it 'set the client' do
expect(subject.client).to eq(client)
expect(dotloop_document.client).to eq(client)
end
end

describe '#all' do
it 'return a list of documents' do
dotloop_mock(:documents)
documents = subject.all(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424)
documents = dotloop_document.all(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424)
expect(documents).not_to be_empty
expect(documents).to all(be_a(Dotloop::Models::Document))
expect(documents.first).to have_attributes(name: 'disclosures.pdf')
Expand All @@ -27,7 +29,7 @@
describe '#find' do
it 'return a document' do
dotloop_mock(:document)
document = subject.find(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, document_id: 561_621)
document = dotloop_document.find(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, document_id: 561_621)
expect(document).to be_a(Dotloop::Models::Document)
expect(document).to have_attributes(name: 'disclosures.pdf')
end
Expand All @@ -36,51 +38,51 @@
describe '#get' do
it 'should get pdf data' do
dotloop_pdf
document = subject.get(profile_id: 1_234,
loop_id: 76_046,
folder_id: 423_424,
document_id: 561_621)
document = dotloop_document.get(profile_id: 1_234,
loop_id: 76_046,
folder_id: 423_424,
document_id: 561_621)
expect(document.string).to eq(disclosure_file_data)
end
end

describe '#upload' do
it 'return a document' do
file = File.read("#{ROOT}/spec/stub_responses/get/profile/1234/loop/76046/folder/423424/document/561621/AgencyDisclosureStatementSeller.pdf")
file = File.read("#{ROOT}/spec/stub_responses/get/profile/1234/loop/76046/folder/423424/document/561621/AgencyDisclosureStatementSeller.pdf")
dotloop_mock(:document_upload, :post, 201)
document = subject.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { "file_name" => 'AgencyDisclosureStatementSeller.pdf', "file_content" => file })
document = dotloop_document.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { 'file_name' => 'AgencyDisclosureStatementSeller.pdf', 'file_content' => file })
expect(document).to be_a(Dotloop::Models::Document)
expect(document).to have_attributes(name: 'AgencyDisclosureStatementSeller.pdf')
end

it 'raise the error if file name is not provided' do
file = File.read("#{ROOT}/spec/stub_responses/get/profile/1234/loop/76046/folder/423424/document/561621/AgencyDisclosureStatementSeller.pdf")
dotloop_mock(:document_upload, :post, 201)
expect {
subject.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { "file_content" => file })
}.to raise_error RuntimeError
expect do
dotloop_document.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { 'file_content' => file })
end.to raise_error RuntimeError
end

it 'raise the error if file name is empty' do
file = File.read("#{ROOT}/spec/stub_responses/get/profile/1234/loop/76046/folder/423424/document/561621/AgencyDisclosureStatementSeller.pdf")
dotloop_mock(:document_upload, :post, 201)
expect {
subject.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { "file_name" => '', "file_content" => file })
}.to raise_error RuntimeError
expect do
dotloop_document.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { 'file_name' => '', 'file_content' => file })
end.to raise_error RuntimeError
end

it 'raise the error if file content is not provided' do
dotloop_mock(:document_upload, :post, 201)
expect {
subject.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { "file_name" => 'AgencyDisclosureStatementSeller.pdf' })
}.to raise_error RuntimeError
expect do
dotloop_document.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { 'file_name' => 'AgencyDisclosureStatementSeller.pdf' })
end.to raise_error RuntimeError
end

it 'raise the error if file content is empty' do
dotloop_mock(:document_upload, :post, 201)
expect {
subject.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { "file_name" => 'AgencyDisclosureStatementSeller.pdf', "file_content" => '' })
}.to raise_error RuntimeError
expect do
dotloop_document.upload(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { 'file_name' => 'AgencyDisclosureStatementSeller.pdf', 'file_content' => '' })
end.to raise_error RuntimeError
end
end
end
16 changes: 9 additions & 7 deletions spec/dotloop/folder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# frozen_string_literal: true

require 'spec_helper'

describe Dotloop::Folder do
let(:client) { Dotloop::Client.new(access_token: SecureRandom.uuid) }
subject { Dotloop::Folder.new(client: client) }
subject(:dotloop_folder) { Dotloop::Folder.new(client: client) }

describe '#initialize' do
it 'exist' do
expect(subject).to_not be_nil
expect(dotloop_folder).to_not be_nil
end

it 'set the client' do
expect(subject.client).to eq(client)
expect(dotloop_folder.client).to eq(client)
end
end

describe '#all' do
it 'return a list of folders' do
dotloop_mock(:folders)
folders = subject.all(profile_id: 1_234, loop_id: 76_046)
folders = dotloop_folder.all(profile_id: 1_234, loop_id: 76_046)
expect(folders).not_to be_empty
expect(folders).to all(be_a(Dotloop::Models::Folder))
expect(folders.first).to have_attributes(name: 'Disclosures')
Expand All @@ -27,7 +29,7 @@
describe '#find' do
it 'return a folder' do
dotloop_mock(:folder)
folder = subject.find(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424)
folder = dotloop_folder.find(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424)
expect(folder).to be_a(Dotloop::Models::Folder)
expect(folder).to have_attributes(name: 'Disclosures')
end
Expand All @@ -36,7 +38,7 @@
describe '#create' do
it 'return a folder' do
dotloop_mock(:folders, :post, 201)
folder = subject.create(profile_id: 1_234, loop_id: 76_046, params: { name: 'Disclosures' })
folder = dotloop_folder.create(profile_id: 1_234, loop_id: 76_046, params: { name: 'Disclosures' })
expect(folder).to be_a(Dotloop::Models::Folder)
expect(folder).to have_attributes(name: 'Disclosures')
end
Expand All @@ -45,7 +47,7 @@
describe '#update' do
it 'return a folder' do
dotloop_mock(:folder, :patch)
folder = subject.update(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { name: 'Disclosures' })
folder = dotloop_folder.update(profile_id: 1_234, loop_id: 76_046, folder_id: 423_424, params: { name: 'Disclosures' })
expect(folder).to be_a(Dotloop::Models::Folder)
expect(folder).to have_attributes(name: 'Disclosures')
end
Expand Down
Loading

0 comments on commit 08a895b

Please sign in to comment.