Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add missing serializers examples.
Sebastian Palmaeb2ff76505ac
diff --git a/api/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb b/api/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rbnew file mode 100644index 0000000000..8665a34244--- /dev/null+++ b/api/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb@@ -0,0 +1,10 @@+module Spree+ module Api+ module V2+ module Platform+ class ReimbursementCreditSerializer < BaseSerializer+ end+ end+ end+ end+enddiff --git a/api/app/serializers/spree/api/v2/platform/stock_item_serializer.rb b/api/app/serializers/spree/api/v2/platform/stock_item_serializer.rbindex ff7fb00d1c..ded1fab01c 100644--- a/api/app/serializers/spree/api/v2/platform/stock_item_serializer.rb+++ b/api/app/serializers/spree/api/v2/platform/stock_item_serializer.rb@@ -5,8 +5,6 @@ module Spreeclass StockItemSerializer < BaseSerializerinclude ResourceSerializerConcern- set_type :stock_item-attribute :is_available do |stock_item|stock_item.available?enddiff --git a/api/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb b/api/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rbindex 9c2235edfb..c5049be4cb 100644--- a/api/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb+++ b/api/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb@@ -5,8 +5,8 @@ module Spreeclass StockTransferSerializer < BaseSerializerinclude ResourceSerializerConcern- belongs_to :destination_location, serializer: :stock_location, record_type: :destination_location- belongs_to :source_location, serializer: :stock_location, record_type: :source_location+ belongs_to :destination_location, serializer: :stock_location+ belongs_to :source_location, serializer: :stock_locationhas_many :stock_movementsendenddiff --git a/api/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rbnew file mode 100644index 0000000000..807a0f29c1--- /dev/null+++ b/api/spec/serializers/spree/api/v2/platform/refund_reason_serializer_spec.rb@@ -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+enddiff --git a/api/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rbnew file mode 100644index 0000000000..c9361e7397--- /dev/null+++ b/api/spec/serializers/spree/api/v2/platform/reimbursement_credit_serializer_spec.rb@@ -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+enddiff --git a/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rbnew file mode 100644index 0000000000..e17ef9d014--- /dev/null+++ b/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb@@ -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+enddiff --git a/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rbnew file mode 100644index 0000000000..b317caf0c1--- /dev/null+++ b/api/spec/serializers/spree/api/v2/platform/stock_item_serializer_spec.rb@@ -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+enddiff --git a/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rbnew file mode 100644index 0000000000..fad1e40eb7--- /dev/null+++ b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb@@ -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+enddiff --git a/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rbnew file mode 100644index 0000000000..33fd0066d6--- /dev/null+++ b/api/spec/serializers/spree/api/v2/platform/stock_movement_serializer_spec.rb@@ -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+enddiff --git a/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rbindex dd406851c7..745a88370e 100644--- a/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/stock_transfer_serializer_spec.rb@@ -1,10 +1,10 @@require 'spec_helper'describe Spree::Api::V2::Platform::StockTransferSerializer do- include_context 'API v2 serializers params'-subject { described_class.new(resource, params: serializer_params).serializable_hash }+ include_context 'API v2 serializers params'+let(:destination_location) { create(:stock_location) }let(:resource) { create(type, destination_location: destination_location, source_location: source_location) }let(:source_location) { create(:stock_location) }@@ -35,13 +35,13 @@ describe Spree::Api::V2::Platform::StockTransferSerializer dosource_location: {data: {id: source_location.id.to_s,- type: :source_location+ type: :stock_location}},destination_location: {data: {id: destination_location.id.to_s,- type: :destination_location+ type: :stock_location}}},diff --git a/core/lib/spree/testing_support/factories/reimbursement_credit_factory.rb b/core/lib/spree/testing_support/factories/reimbursement_credit_factory.rbnew file mode 100644index 0000000000..8a03944383--- /dev/null+++ b/core/lib/spree/testing_support/factories/reimbursement_credit_factory.rb@@ -0,0 +1,7 @@+FactoryBot.define do+ factory :reimbursement_credit, class: Spree::Reimbursement::Credit do+ reimbursement++ amount { 100.00 }+ end+end