Skip to content

Instantly share code, notes, and snippets.

@cored
Created September 10, 2018 15:53
Show Gist options
  • Save cored/d3b2760fe4660568956ca17100ebe24d to your computer and use it in GitHub Desktop.
Save cored/d3b2760fe4660568956ca17100ebe24d to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "timecop"
require "active_support/all"
require_relative "../../../../app/services/flexe/notification_handlers/retail_fulfillment_order_info"
describe Flexe::NotificationHandlers::RetailFulfillmentOrderInfo do
subject(:retail_fulfillment_order_info) do
described_class.for(attrs)
end
context "when retail attributes are defined with symbolize keys" do
let(:attrs) do
{
reservation_id: 12345,
purchase_orders: [
{
retail_fulfillment_order_id: "Some FLEXE internal id",
bill_of_lading_number: "Some BOL number",
purchase_order_uuid: purchase_order_uuid,
tags: tags,
},
],
master_bill_of_lading_number: "Some master BOL number",
scac: "Some code",
pro_number: "Some number",
lading_quantity: {
num_pallets: 2,
},
}
end
let(:tags) { ["consolidator_bound"] }
describe "#purchase_order_uuids" do
context "when the purchase order number uuids contains dashes" do
let(:purchase_order_uuid) { "TEST123-HELLO-TEST#SHIPMENT_NUMBER" }
it "returns the list of order uuids" do
expect(
retail_fulfillment_order_info.purchase_order_uuids
).to match_array(%w[TEST123-HELLO-TEST])
end
end
context "when the purchase order number uuids does not contains dashes" do
let(:purchase_order_uuid) { "ORDERNUMBER#SHIPMENT_NUMBER" }
it "returns the list of order uuids" do
expect(
retail_fulfillment_order_info.purchase_order_uuids
).to match_array(%w[ORDERNUMBER])
end
it "returns proper order uuids" do
expect(
retail_fulfillment_order_info.purchase_order_uuids.first.size
).not_to be 1
end
end
end
describe "#purchase_orders_from_store" do
let(:attrs) do
{
reservation_id: 12345,
purchase_orders: [
{
retail_fulfillment_order_id: "Some FLEXE internal id",
bill_of_lading_number: "Some BOL number",
purchase_order_uuid: "UUID",
tags: ["consolidator_bound"],
},
{
retail_fulfillment_order_id: "Some FLEXE internal id",
bill_of_lading_number: "Some BOL number",
purchase_order_uuid: "UUID ST",
tags: ["consolidator_bound"],
},
{
retail_fulfillment_order_id: "Some FLEXE internal id",
bill_of_lading_number: "Some BOL number",
purchase_order_uuid: "SF UUID",
tags: ["consolidator_bound"],
},
],
master_bill_of_lading_number: "Some master BOL number",
scac: "Some code",
pro_number: "Some number",
lading_quantity: {
num_pallets: 2,
},
}
end
it "returns purchase orders with uuids ending in ST or SF" do
expect(
retail_fulfillment_order_info.purchase_orders_from_store.map(&:to_h)
).to match([
{
:purchase_order_uuid=>"UUID ST",
:bill_of_lading_number=>"Some BOL number",
:retail_fulfillment_order_id=>"Some FLEXE internal id",
:tags=>["consolidator_bound"],
},
{
:purchase_order_uuid=>"SF UUID",
:bill_of_lading_number=>"Some BOL number",
:retail_fulfillment_order_id=>"Some FLEXE internal id",
:tags=>["consolidator_bound"],
},
])
end
end
describe "#tracking_info" do
let(:purchase_order_uuid) { "purchase_order_uuid" }
it "shipped at contains current time" do
Timecop.freeze(Time.now.utc.iso8601) do
expect(
retail_fulfillment_order_info.tracking_info[:shipped_at].to_i
).to eql 2018
end
end
context "when retail fulfillment info is a consolidator bound" do
it "returns tracking information" do
expect(
retail_fulfillment_order_info.tracking_info.except(:shipped_at)
).to match({
carrier_pro_number: "Some number",
carrier_alpha_code: "Some code",
lading_quantity: 2,
master_bill_of_lading_number: "Some master BOL number",
})
end
end
context "when retail fulfillment info is not a consolidator bound" do
let(:tags) { [] }
it "returns tracking information" do
expect(
retail_fulfillment_order_info.tracking_info.except(:shipped_at)
).to match({
carrier_pro_number: "Some number",
carrier_alpha_code: "Some code",
lading_quantity: 2,
})
end
end
end
end
context "when retail attributes are defined with string keys" do
let(:attrs) do
{
"reservation_id" => 12345,
"purchase_orders" => [
{
"retail_fulfillment_order_id" => "Some FLEXE internal id",
"bill_of_lading_number" => "Some BOL number",
"purchase_order_uuid" => purchase_order_uuid,
"tags" => tags,
},
],
"master_bill_of_lading_number" => "Some master BOL number",
"scac" => "Some code",
"pro_number" => "Some number",
"lading_quantity" => {
"num_pallets" => 2,
},
}
end
let(:tags) { ["consolidator_bound"] }
describe "#purchase_order_uuids" do
context "when the purchase order number uuids contains dashes" do
let(:purchase_order_uuid) { "TEST123-HELLO-TEST#SHIPMENT_NUMBER" }
it "returns the list of order uuids" do
expect(
retail_fulfillment_order_info.purchase_order_uuids
).to match_array(%w[TEST123-HELLO-TEST])
end
end
context "when the purchase order number uuids does not contains dashes" do
let(:purchase_order_uuid) { "ORDERNUMBER#SHIPMENT_NUMBER" }
it "returns the list of order uuids" do
expect(
retail_fulfillment_order_info.purchase_order_uuids
).to match_array(%w[ORDERNUMBER])
end
it "returns proper order uuids" do
expect(
retail_fulfillment_order_info.purchase_order_uuids.first.size
).not_to be 1
end
end
end
describe "#purchase_orders_from_store" do
let(:attrs) do
{
reservation_id: 12345,
purchase_orders: [
{
retail_fulfillment_order_id: "Some FLEXE internal id",
bill_of_lading_number: "Some BOL number",
purchase_order_uuid: "UUID",
tags: ["consolidator_bound"],
},
{
retail_fulfillment_order_id: "Some FLEXE internal id",
bill_of_lading_number: "Some BOL number",
purchase_order_uuid: "UUID ST",
tags: ["consolidator_bound"],
},
{
retail_fulfillment_order_id: "Some FLEXE internal id",
bill_of_lading_number: "Some BOL number",
purchase_order_uuid: "UUID SF",
tags: ["consolidator_bound"],
},
],
master_bill_of_lading_number: "Some master BOL number",
scac: "Some code",
pro_number: "Some number",
lading_quantity: {
num_pallets: 2,
},
}
end
it "returns purchase orders with uuids ending in ST or SF" do
expect(
retail_fulfillment_order_info.purchase_orders_from_store.map(&:to_h)
).to match([
{
:purchase_order_uuid=>"UUID ST",
:bill_of_lading_number=>"Some BOL number",
:retail_fulfillment_order_id=>"Some FLEXE internal id",
:tags=>["consolidator_bound"],
},
{
:purchase_order_uuid=>"UUID SF",
:bill_of_lading_number=>"Some BOL number",
:retail_fulfillment_order_id=>"Some FLEXE internal id",
:tags=>["consolidator_bound"],
},
])
end
end
describe "#tracking_info" do
let(:purchase_order_uuid) { "purchase_order_uuid" }
it "shipped at contains current time" do
Timecop.freeze(Time.now.utc.iso8601) do
expect(
retail_fulfillment_order_info.tracking_info[:shipped_at].to_i
).to eql 2018
end
end
context "when retail fulfillment info is a consolidator bound" do
it "returns tracking information" do
expect(
retail_fulfillment_order_info.tracking_info.except(:shipped_at)
).to match({
carrier_pro_number: "Some number",
carrier_alpha_code: "Some code",
lading_quantity: 2,
master_bill_of_lading_number: "Some master BOL number",
})
end
end
context "when retail fulfillment info is not a consolidator bound" do
let(:tags) { [] }
it "returns tracking information" do
expect(
retail_fulfillment_order_info.tracking_info.except(:shipped_at)
).to match({
carrier_pro_number: "Some number",
carrier_alpha_code: "Some code",
lading_quantity: 2,
})
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment