This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EasyPost | |
module Carriers | |
class CancelSlot | |
attr_reader :ez_shipment | |
def self.call(courier_slot) | |
new.call(courier_slot) | |
end | |
def initialize(easy_post_api: EasyPost::Shipment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "#cancel_slot" do | |
let(:courier_slot) do | |
instance_double("CourierSlot", external_api_identifier: "api_identifier") | |
end | |
let(:cancel_slot) do | |
instance_double("EasyPost::Carriers::CancelSlot", ez_shipment: ez_shipment) | |
end | |
let(:ez_shipment) do | |
instance_double("EasyPost::Carriers::CancelSlot") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "easypost" | |
require_relative "../../../../app/services/easy_post/carriers/cancel_slot" | |
describe EasyPost::Carriers::CancelSlot do | |
subject(:cancel_slot) { described_class.new } | |
before do | |
EasyPost.api_key = "API_KEY" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CancelSlot | |
def self.call(courier) | |
ez_shipment = EasyPost::Shipment.retrieve(courier.external_api_identifier) | |
ez_shipment.refund | |
ez_shipment | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe '#cancel_slot', vcr: { record: :once, match_requests_on: [:method, :host, :path] } do | |
let(:external_api_identifier) { "API_IDENTIFIER" } | |
let(:courier_slot) { create(:courier_slot, external_api_identifier: external_api_identifier) } | |
it "cancels the slot via the api client" do | |
ez_shipment = described_class.new.cancel_slot(courier_slot) | |
expect(ez_shipment.refund_status).to eq "refunded" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Courier < ActiveRecord::Model | |
def cancel_slot(courier_slot) | |
ez_shipment = EasyPost::Shipment.retrieve(courier.external_api_identifier) | |
ez_shipment.refund | |
ez_shipment | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cancel_slot(courier_slot) | |
ez_shipment = EasyPost::Shipment.retrieve(courier.external_api_identifier) | |
ez_shipment.refund | |
ez_shipment | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def attachments_for(shipment_items) | |
shipment_items.map(&:case_pack).uniq.map do |case_pack| | |
{ | |
display_name: "Case Pack Label - SSCC:#{case_pack.shipping_serial_code}", | |
url: case_pack.case_pack_label.url.to_s, | |
} | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == Schema Information | |
# | |
# Table name: warehouses | |
# | |
# id :integer not null, primary key | |
# name :string(255) | |
# address_id :integer | |
# supplier_id :integer | |
# manages_label_purchases :boolean | |
# scanner_api_token :string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Rescuer interface { | |
WhenMessage(string, func()) func() | |
WhenPattern(Regexp, func()) func() | |
Exec(func()) func() | |
} |