describe OpenMarket do context 'Client' do let(:id) { '123' } let(:password) { '456' } let(:text) { 'Hello OpenMarket World!' } let(:from) { 'streetbees' } let(:to) { '918000001' } let(:client) { ::OpenMarket::SMS::Client.new( account_id: id, account_password: password ) } context 'sending a text message' do let(:response) { client.send_message( from: from, to: to, text: text ) } context 'with success' do it 'should return success == true' do VCR.use_cassette('open_market/message_success') do expect(response.success?).to eq(true) expect(response.status).to eq(202) expect(response.message_id).to eq('2618Z-03021-1603K-03FDL') end end end context 'invalid auth' do it 'should return success == false' do VCR.use_cassette('open_market/message_unauthorized') do expect(response.success?).to eq(false) expect(response.status).to eq(401) expect(response.error_code).to eq(420) expect(response.error_message).not_to be(nil) end end end end context 'requesting a delivery status' do let(:ticket_id) { '2218Z-0318E-2225A-4999C' } let(:response) { client.message_status(ticket_id: ticket_id) } context 'with success' do let(:expected_delivery_date) { DateTime.parse('2018-03-19T14:56:05Z') } let(:expected_message_status) { 'Message successfully delivered.' } it 'should return success == true' do VCR.use_cassette('open_market/message_status_success') do expect(response.success?).to eq(true) expect(response.status).to eq(200) expect(response.destination).to eq('447736067864') expect(response.delivery_date).to eq(expected_delivery_date) expect(response.message_status_code).to eq(4) expect(response.message_status).to eq('Message successfully delivered.') end end end context 'invalid auth' do it 'should return success == false' do VCR.use_cassette('open_market/message_status_unauthorized') do expect(response.success?).to eq(false) expect(response.status).to eq(401) expect(response.error_code).to eq(420) expect(response.error_message).not_to be(nil) end end end context 'not found' do let(:ticket_id) { 'fake' } it 'should return success == false' do VCR.use_cassette('open_market/message_status_not_found') do expect(response.success?).to eq(false) expect(response.status).to eq(404) expect(response.error_code).to eq(711) expect(response.error_message).not_to be(nil) end end end end end end