require 'spec_helper'
describe Endicia::LabelResponse do
describe "initialize" do
let(:result) {
OpenStruct.new(
"LabelRequestResponse" => {
image_key => image_value,
"Status" => Faker::Lorem.sentence,
"TrackingNumber" => Faker::Lorem.sentence,
"FinalPostage" => Faker::Lorem.sentence,
"TransactionDateTime" => Faker::Lorem.sentence,
"TransactionId" => Faker::Lorem.sentence,
"PostmarkDate" => Faker::Lorem.sentence,
"PostageBalance" => Faker::Lorem.sentence,
"Pic" => Faker::Lorem.sentence,
"ErrorMessage" => Faker::Lorem.sentence,
"ReferenceId" => Faker::Lorem.sentence,
"ReferenceId2" => Faker::Lorem.sentence,
"ReferenceId3" => Faker::Lorem.sentence,
"ReferenceId4" => Faker::Lorem.sentence,
"RequesterId" => Faker::Lorem.sentence,
"CostCenter" => Faker::Lorem.sentence,
"RequestBody" => Faker::Lorem.sentence,
"RequestUrl" => Faker::Lorem.sentence,
"Ignored" => Faker::Lorem.sentence,
},
body: "ksadjhfalskjfhalsjfhaslfjhasdljkf"
)
}
let(:expected_image_value) { Faker::Lorem.sentence }
let(:image_key) { "Base64LabelImage" }
let(:image_value) { expected_image_value }
subject(:response) { described_class.new(result) }
it "turns the awful Enterprise keys into snake-case and sets 'em up appropriate" do
expect(response.status).to eq(result["LabelRequestResponse"]["Status"])
expect(response.tracking_number).to eq(result["LabelRequestResponse"]["TrackingNumber"])
expect(response.final_postage).to eq(result["LabelRequestResponse"]["FinalPostage"])
expect(response.transaction_date_time).to eq(result["LabelRequestResponse"]["TransactionDateTime"])
expect(response.transaction_id).to eq(result["LabelRequestResponse"]["TransactionId"])
expect(response.postmark_date).to eq(result["LabelRequestResponse"]["PostmarkDate"])
expect(response.postage_balance).to eq(result["LabelRequestResponse"]["PostageBalance"])
expect(response.pic).to eq(result["LabelRequestResponse"]["Pic"])
expect(response.error_message).to eq(result["LabelRequestResponse"]["ErrorMessage"])
expect(response.reference_id).to eq(result["LabelRequestResponse"]["ReferenceId"])
expect(response.reference_id2).to eq(result["LabelRequestResponse"]["ReferenceId2"])
expect(response.reference_id3).to eq(result["LabelRequestResponse"]["ReferenceId3"])
expect(response.reference_id4).to eq(result["LabelRequestResponse"]["ReferenceId4"])
expect(response.requester_id).to eq(result["LabelRequestResponse"]["RequesterId"])
expect(response.cost_center).to eq(result["LabelRequestResponse"]["CostCenter"])
expect(response.request_body).to eq(result["LabelRequestResponse"]["RequestBody"])
expect(response.request_url).to eq(result["LabelRequestResponse"]["RequestUrl"])
end
it "masks data in the body" do
expect(response.response_body).to eq("[data]")
end
context "for typical case" do
let(:image_key) { "Base64LabelImage" }
let(:image_value) { expected_image_value }
it "translates Base64LabelImage to 'image'" do
expect(response.image).to eq(expected_image_value)
end
end
context "for customs form case" do
let(:image_key) { "Label" }
let(:image_value) {
{
"Image" => {
"__content__" => expected_image_value
}
}
}
it "translates Base64LabelImage to 'image'" do
expect(response.image).to eq(expected_image_value)
end
end
end
end