Skip to content

Instantly share code, notes, and snippets.

View cored's full-sized avatar
🐽
Hacking Everything

Rafael George cored

🐽
Hacking Everything
View GitHub Profile
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)
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
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
class CancelSlot
def self.call(courier)
ez_shipment = EasyPost::Shipment.retrieve(courier.external_api_identifier)
ez_shipment.refund
ez_shipment
end
end
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
@cored
cored / courier.rb
Last active December 24, 2017 18:16
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
def cancel_slot(courier_slot)
ez_shipment = EasyPost::Shipment.retrieve(courier.external_api_identifier)
ez_shipment.refund
ez_shipment
end
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
# == 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
type Rescuer interface {
WhenMessage(string, func()) func()
WhenPattern(Regexp, func()) func()
Exec(func()) func()
}