require File.dirname(__FILE__) + '/../../../../spec_helper'
include OpenEHR::RM::Demographic
include OpenEHR::RM::DataTypes::Text
include OpenEHR::RM::DataTypes::Quantity::DateTime
include OpenEHR::RM::Support::Identification
include OpenEHR::RM::DataStructures::ItemStructure

describe Capability do
  before(:each) do
    name = DvText.new(:value => 'party relation')
    credentials = double(ItemStructure, :archetype_node_id => 'at0001')
    lower = DvDate.new(:value => '2009-11-21')
    time_validity = double(DvInterval, :lower => lower)
    @capability = Capability.new(:archetype_node_id => 'at0000',
                                 :name => name,
                                 :credentials => credentials,
                                 :time_validity => time_validity)
  end

  it 'should be an instance of Capability' do
    expect(@capability).to be_an_instance_of Capability
  end

  it 'credential should be assigned properly' do
    expect(@capability.credentials.archetype_node_id).to eq('at0001')
  end

  it 'should raise ArgumentError when nil assigned to credentials' do
    expect {
      @capability.credentials = nil
    }.to raise_error ArgumentError
  end

  it 'time_validity should be assigned properly' do
    expect(@capability.time_validity.lower.value).to eq('2009-11-21')
  end
end
