testing bettervideo api
This commit is contained in:
parent
01af9115a0
commit
90e7238554
@ -17,7 +17,6 @@ class BetterVideo
|
||||
response = http.request(request)
|
||||
|
||||
resp = JSON.parse(response.body)
|
||||
puts resp
|
||||
|
||||
if resp["errorcode"].to_i == 0
|
||||
resp[:success] = true
|
||||
@ -30,15 +29,4 @@ class BetterVideo
|
||||
end
|
||||
resp
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
def valid_json? json_
|
||||
JSON.parse(json_)
|
||||
return true
|
||||
rescue JSON::ParserError
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -8,4 +8,6 @@ feature 'External request' do
|
||||
response = JSON.parse(Net::HTTP.get(uri))
|
||||
expect(response['success']).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -40,4 +40,44 @@ describe Campaign, 'associations' do
|
||||
expect(camp.video_completion_percent).to eq(100)
|
||||
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
|
@ -6,6 +6,16 @@ class FakeBetterVideo < Sinatra::Base
|
||||
json_response 200, 'bettervideo_0.json'
|
||||
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
|
||||
|
||||
def json_response(response_code, file_name)
|
||||
|
7
spec/support/fixtures/bettervideo_1.json
Normal file
7
spec/support/fixtures/bettervideo_1.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"errorcode": "1",
|
||||
"errormessage": "Unknown Error",
|
||||
"listingcode": "242000",
|
||||
"success": false,
|
||||
"videocode": "242001"
|
||||
}
|
7
spec/support/fixtures/bettervideo_102.json
Normal file
7
spec/support/fixtures/bettervideo_102.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"errorcode": "102",
|
||||
"errormessage": "Required field [voiceoverselection] missing.",
|
||||
"listingcode": "242000",
|
||||
"success": false,
|
||||
"videocode": "242001"
|
||||
}
|
Loading…
Reference in New Issue
Block a user