-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c11d0b4
commit eb2ff76
Showing
11 changed files
with
253 additions
and
8 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
api/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Spree | ||
module Api | ||
module V2 | ||
module Platform | ||
class ReimbursementCreditSerializer < BaseSerializer | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
26 changes: 26 additions & 0 deletions
26
api/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::Api::V2::Platform::RefundReasonSerializer do | ||
include_context 'API v2 serializers params' | ||
|
||
subject { described_class.new(resource, params: serializer_params).serializable_hash } | ||
|
||
let(:type) { :refund_reason } | ||
let(:resource) { create(type) } | ||
|
||
it do | ||
expect(subject).to eq( | ||
data: { | ||
id: resource.id.to_s, | ||
attributes: { | ||
name: resource.name, | ||
active: resource.active, | ||
mutable: resource.mutable, | ||
created_at: resource.created_at, | ||
updated_at: resource.updated_at | ||
}, | ||
type: type | ||
} | ||
) | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
api/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::Api::V2::Platform::ReimbursementCreditSerializer do | ||
include_context 'API v2 serializers params' | ||
|
||
subject { described_class.new(resource, params: serializer_params).serializable_hash } | ||
|
||
let(:type) { :reimbursement_credit } | ||
let(:resource) { create(type, creditable: create(:store_credit)) } | ||
|
||
it do | ||
expect(subject).to eq( | ||
data: { | ||
id: resource.id.to_s, | ||
type: type | ||
} | ||
) | ||
end | ||
end |
62 changes: 62 additions & 0 deletions
62
api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::Api::V2::Platform::ReimbursementSerializer do | ||
include_context 'API v2 serializers params' | ||
|
||
subject { described_class.new(resource, params: serializer_params).serializable_hash } | ||
|
||
let(:reimbursement_credit) { create(:reimbursement_credit, creditable: create(:store_credit)) } | ||
let(:payment) { create(:payment, state: 'completed') } | ||
let(:type) { :reimbursement } | ||
let(:refund) { create(:refund, amount: payment.credit_allowed - 1) } | ||
let(:resource) { create(type, refunds: [refund], credits: [reimbursement_credit]) } | ||
|
||
it do | ||
expect(subject).to eq( | ||
data: { | ||
id: resource.id.to_s, | ||
attributes: { | ||
number: resource.number, | ||
reimbursement_status: resource.reimbursement_status, | ||
total: resource.total, | ||
created_at: resource.created_at, | ||
updated_at: resource.updated_at, | ||
display_total: resource.display_total, | ||
}, | ||
relationships: { | ||
order: { | ||
data: { | ||
id: resource.order.id.to_s, | ||
type: :order | ||
} | ||
}, | ||
customer_return: { | ||
data: { | ||
id: resource.customer_return.id.to_s, | ||
type: :customer_return | ||
} | ||
}, | ||
refunds: { | ||
data: [{ | ||
id: refund.id.to_s, | ||
type: :refund | ||
}] | ||
}, | ||
reimbursement_credits: { | ||
data: [{ | ||
id: reimbursement_credit.id.to_s, | ||
type: :reimbursement_credit | ||
}] | ||
}, | ||
return_items: { | ||
data: [{ | ||
id: resource.return_items.first.id.to_s, | ||
type: :return_item | ||
}] | ||
} | ||
}, | ||
type: type | ||
} | ||
) | ||
end | ||
end |
42 changes: 42 additions & 0 deletions
42
api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::Api::V2::Platform::StockItemSerializer do | ||
include_context 'API v2 serializers params' | ||
|
||
subject { described_class.new(resource, params: serializer_params).serializable_hash } | ||
|
||
let(:resource) { stock_location.stock_items.order(:id).first } | ||
let(:stock_location) { create(:stock_location_with_items) } | ||
let(:type) { :stock_item } | ||
|
||
it do | ||
expect(subject).to eq( | ||
data: { | ||
id: resource.id.to_s, | ||
attributes: { | ||
backorderable: resource.backorderable, | ||
count_on_hand: resource.count_on_hand, | ||
created_at: resource.created_at, | ||
deleted_at: resource.deleted_at, | ||
is_available: resource.available?, | ||
updated_at: resource.updated_at | ||
}, | ||
relationships: { | ||
stock_location: { | ||
data: { | ||
id: stock_location.id.to_s, | ||
type: :stock_location | ||
} | ||
}, | ||
variant: { | ||
data: { | ||
id: resource.variant.id.to_s, | ||
type: :variant | ||
} | ||
} | ||
}, | ||
type: type | ||
} | ||
) | ||
end | ||
end |
53 changes: 53 additions & 0 deletions
53
api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::Api::V2::Platform::StockLocationSerializer do | ||
include_context 'API v2 serializers params' | ||
|
||
subject { described_class.new(resource, params: serializer_params).serializable_hash } | ||
|
||
let(:resource) { create(:stock_location_with_items, shipments: [shipment]) } | ||
let(:type) { :stock_location } | ||
let(:shipment) { create(:shipment) } | ||
|
||
it do | ||
expect(subject).to eq( | ||
data: { | ||
id: resource.id.to_s, | ||
type: type, | ||
attributes: { | ||
active: resource.active, | ||
address1: resource.address1, | ||
address2: resource.address2, | ||
admin_name: resource.admin_name, | ||
backorderable_default: resource.backorderable_default, | ||
city: resource.city, | ||
created_at: resource.created_at, | ||
default: resource.default, | ||
name: resource.name, | ||
phone: resource.phone, | ||
propagate_all_variants: resource.propagate_all_variants, | ||
state_name: resource.state_name, | ||
updated_at: resource.updated_at, | ||
zipcode: resource.zipcode | ||
}, | ||
relationships: { | ||
shipments: { | ||
data: [{ | ||
id: shipment.id.to_s, | ||
type: :shipment | ||
}] | ||
}, | ||
stock_items: { | ||
data: [{ | ||
id: resource.stock_items[0].id.to_s, | ||
type: :stock_item | ||
}, { | ||
id: resource.stock_items[1].id.to_s, | ||
type: :stock_item | ||
}] | ||
} | ||
} | ||
} | ||
) | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::Api::V2::Platform::StockMovementSerializer do | ||
include_context 'API v2 serializers params' | ||
|
||
subject { described_class.new(resource, params: serializer_params).serializable_hash } | ||
|
||
let(:type) { :stock_movement } | ||
let(:stock_location) { create(:stock_location_with_items) } | ||
let(:stock_item) { stock_location.stock_items.order(:id).first } | ||
let(:resource) { create(type, stock_item: stock_item) } | ||
|
||
it do | ||
expect(subject).to eq( | ||
data: { | ||
id: resource.id.to_s, | ||
attributes: { | ||
quantity: resource.quantity, | ||
action: resource.action, | ||
originator_type: resource.originator_type, | ||
created_at: resource.created_at, | ||
updated_at: resource.updated_at | ||
}, | ||
type: type | ||
} | ||
) | ||
end | ||
end |
This file contains 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
7 changes: 7 additions & 0 deletions
7
core/lib/spree/testing_support/factories/reimbursement_credit_factory.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :reimbursement_credit, class: Spree::Reimbursement::Credit do | ||
reimbursement | ||
|
||
amount { 100.00 } | ||
end | ||
end |