Skip to content

Commit

Permalink
Add tests for branches resource
Browse files Browse the repository at this point in the history
  • Loading branch information
simacektomas authored and jirutka committed Feb 14, 2018
1 parent 78cdc14 commit a305239
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/kosapi_client/entity/branch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'

describe KOSapiClient::Entity::Branch do
let(:attributes) {{
capacity: '60',
code: '3902R031',
division: { xlink_href: 'divisions/13136/', __content__: 'katedra počítačů' },
diploma_name: [
{ xml_lang: 'cs', __content__: 'Softwarové inženýrství' },
{ xml_lang: 'en', __content__: 'Software Engineering' },
],
guarantor: { xlink_href: 'people/jelinek/', __content__: 'doc. Ing. Ivan Jelínek CSc.' },
name: [
{ xml_lang: 'cs', __content__: 'Softwarové inženýrství' },
{ xml_lang: 'en', __content__: 'Software Engineering' },
],
open_for_admission: 'true',
}}

it 'parses branch attributes' do
branch = KOSapiClient::Entity::Branch.parse(attributes)
expect(branch.capacity).to eq 60
expect(branch.code).to eq '3902R031'
expect(branch.division).to be_an_instance_of KOSapiClient::Entity::Link
expect(branch.division.link_href).to eq 'divisions/13136/'
expect(branch.division.link_title).to eq 'katedra počítačů'
expect(branch.guarantor).to be_an_instance_of KOSapiClient::Entity::Link
expect(branch.guarantor.link_href).to eq 'people/jelinek/'
expect(branch.guarantor.link_title).to eq 'doc. Ing. Ivan Jelínek CSc.'
end
end
28 changes: 28 additions & 0 deletions spec/kosapi_client/resource/branches_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'spec_helper'

describe KOSapiClient::Resource::BranchesBuilder do

let(:url_builder) { instance_double(KOSapiClient::URLBuilder, url: 'http://example.com') }
let(:response) { double(foo: :bar) }
let(:http_client) { double(send_request: response) }
subject(:builder) { KOSapiClient::Resource::BranchesBuilder.new('http://example.com', http_client, url_builder)}

describe '#study_plans' do

before { allow(url_builder).to receive(:set_path) }

it 'throws error when branch id is not set' do
expect { builder.study_plans }.to raise_error(RuntimeError)
end

it 'returns self' do
builder.find(69)
expect(builder.study_plans).to eq builder
end

it 'adds studyPlans to URL' do
expect(url_builder).to receive(:set_path).with(69, 'studyPlans')
builder.find(69).study_plans
end
end
end

0 comments on commit a305239

Please sign in to comment.