testing bettervideo api

This commit is contained in:
Tyrel Souza 2014-05-06 12:20:19 -04:00
parent 01af9115a0
commit 90e7238554
6 changed files with 67 additions and 13 deletions

View File

@ -17,7 +17,6 @@ class BetterVideo
response = http.request(request) response = http.request(request)
resp = JSON.parse(response.body) resp = JSON.parse(response.body)
puts resp
if resp["errorcode"].to_i == 0 if resp["errorcode"].to_i == 0
resp[:success] = true resp[:success] = true
@ -30,15 +29,4 @@ class BetterVideo
end end
resp resp
end end
private
def valid_json? json_
JSON.parse(json_)
return true
rescue JSON::ParserError
return false
end
end end

View File

@ -8,4 +8,6 @@ feature 'External request' do
response = JSON.parse(Net::HTTP.get(uri)) response = JSON.parse(Net::HTTP.get(uri))
expect(response['success']).to eq(true) expect(response['success']).to eq(true)
end end
end end

View File

@ -40,4 +40,44 @@ describe Campaign, 'associations' do
expect(camp.video_completion_percent).to eq(100) expect(camp.video_completion_percent).to eq(100)
end end
it 'gets the proper better video format' do
campaign = FactoryGirl.build(:campaign)
campaign.save
bv_fmt = campaign.to_bettervideo_format
expect(JSON.parse(bv_fmt)['key']).to eq("PRO1234")
expect(JSON.parse(bv_fmt)['campaigns'][0]["clientid"]).to eq(720)
expect(JSON.parse(bv_fmt)['campaigns'][0]["videolistings"].length).to eq(1)
end
it 'sends to better video and returns success' do
campaign = FactoryGirl.build(:campaign)
campaign.save
client = BetterVideo.new
bv_response = client.addVideo(campaign: campaign.to_bettervideo_format)
expect(bv_response[:success]).to eq(true)
end
it 'sends to better video and returns missing field' do
campaign = FactoryGirl.build(:campaign)
campaign.listingcode = "videolistingmissing"
campaign.save
client = BetterVideo.new
bv_response = client.addVideo(campaign: campaign.to_bettervideo_format)
expect(bv_response["errormessage"]).to eq("Required field [voiceoverselection] missing.")
end
it 'sends to better video and returns error' do
campaign = FactoryGirl.build(:campaign)
campaign.listingcode = "contactdev"
campaign.save
client = BetterVideo.new
bv_response = client.addVideo(campaign: campaign.to_bettervideo_format)
expect(bv_response[:message]).to include("Please Contact Dev")
end
end end

View File

@ -6,6 +6,16 @@ class FakeBetterVideo < Sinatra::Base
json_response 200, 'bettervideo_0.json' json_response 200, 'bettervideo_0.json'
end end
post '/orders/MDS.OrdersWS.svc/addVideo' do
if params.to_s.include? "videolistingmissing"
json_response 200, 'bettervideo_102.json'
elsif params.to_s.include? "contactdev"
json_response 200, 'bettervideo_1.json'
else
json_response 200, 'bettervideo_0.json'
end
end
private private
def json_response(response_code, file_name) def json_response(response_code, file_name)

View File

@ -0,0 +1,7 @@
{
"errorcode": "1",
"errormessage": "Unknown Error",
"listingcode": "242000",
"success": false,
"videocode": "242001"
}

View File

@ -0,0 +1,7 @@
{
"errorcode": "102",
"errormessage": "Required field [voiceoverselection] missing.",
"listingcode": "242000",
"success": false,
"videocode": "242001"
}