Add spec for new PDU classes

develop
Guillaume DOTT 2013-09-09 17:29:35 +02:00
parent 2de794042d
commit d1103a0772
5 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,29 @@
require 'spec_helper'
require 'biju/pdu'
describe Biju::PDU::DataCodingScheme do
describe '::autodetect' do
it "autodetects gsm7bit encoding" do
[
"Test",
"Ç$",
"[teßt}",
].each do |string|
expect(Biju::PDU::DataCodingScheme.autodetect(string)).to eq(:gsm7bit)
end
end
it "autodetects ucs2 encoding" do
[
"ç",
"âmazing",
].each do |string|
expect(Biju::PDU::DataCodingScheme.autodetect(string)).to eq(:ucs2)
end
end
end
subject { Biju::PDU::DataCodingScheme.new(:gsm7bit) }
its(:to_sym) { should eq(:gsm7bit) }
its(:hex) { should eq(0) }
end

View File

@ -0,0 +1,21 @@
require 'spec_helper'
require 'biju/pdu'
describe Biju::PDU::PhoneNumber do
describe '::encode' do
subject { Biju::PDU::PhoneNumber.encode('33123456789') }
its(:number) { should eq('3321436587F9') }
end
context "odd length" do
subject { Biju::PDU::PhoneNumber.new('3321436587F9') }
its(:decode) { should eq('33123456789') }
its(:length) { should eq(11) }
end
context "even length" do
subject { Biju::PDU::PhoneNumber.new('3321436587') }
its(:decode) { should eq('3312345678') }
its(:length) { should eq(10) }
end
end

View File

@ -0,0 +1,9 @@
require 'spec_helper'
require 'biju/pdu'
describe Biju::PDU::TypeOfAddress do
subject { Biju::PDU::TypeOfAddress.new(:international) }
its(:to_sym) { should eq(:international) }
its(:hex) { should eq(145) }
end

View File

@ -0,0 +1,12 @@
require 'spec_helper'
require 'biju/pdu'
describe Biju::PDU::UserData do
subject(:message) { 'Test' }
subject(:encoded) { Biju::PDU::Encoding::GSM7Bit.encode(message) }
subject { Biju::PDU::UserData.encode(message, encoding: :gsm7bit) }
its(:message) { should eq(encoded[0]) }
its(:length) { should eq(encoded[1][:length]) }
its(:decode) { should eq(message) }
end

View File

@ -23,5 +23,18 @@ describe Biju::Sms do
its(:datetime) { should eq(DateTime.new(2013, 9, 5, 9, 59, 29, '+08')) } its(:datetime) { should eq(DateTime.new(2013, 9, 5, 9, 59, 29, '+08')) }
its(:message) { should eq('Test') } its(:message) { should eq('Test') }
its(:phone_number) { should eq('33666666666') }
its(:type_of_address) { should eq(:international) }
end
describe '#to_pdu' do
subject do
Biju::Sms.new(
phone_number: '33666666666',
type_of_address: :international,
message: 'Test').to_pdu.upcase
end
it { should eq('0001000B913366666666F6000004D4F29C0E') }
end end
end end