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
Added Event Serializers
Damian Legawiecd436c5278bc8
diff --git a/core/app/models/concerns/spree/publishable.rb b/core/app/models/concerns/spree/publishable.rbindex fdef886e62..334667981b 100644--- a/core/app/models/concerns/spree/publishable.rb+++ b/core/app/models/concerns/spree/publishable.rb@@ -4,7 +4,8 @@ module Spree# Concern for models that publish events.## This concern is included in Spree::Base, so all Spree models- # automatically emit lifecycle events (create, update, destroy).+ # can emit events. Event payloads are generated using dedicated+ # serializers from the Spree::Events namespace.## @example Disabling events for a specific model# class Spree::LogEntry < Spree.base_class@@ -19,23 +20,49 @@ module Spree# end# end#- # @example With custom serialization- # class Spree::Order < Spree.base_class- # def event_payload- # serializable_hash(- # only: [:id, :number, :state, :total],- # include: { line_items: { only: [:id, :quantity] } }- # )+ # @example Creating an event serializer (required for each model that publishes events)+ # # app/serializers/spree/events/order_serializer.rb+ # class Spree::Events::OrderSerializer < Spree::Events::BaseSerializer+ # protected+ #+ # def attributes+ # {+ # id: resource.id,+ # number: resource.number,+ # state: resource.state.to_s,+ # # ... other attributes+ # }# end# end#module Publishableextend ActiveSupport::Concern+ # Error raised when a model tries to publish an event but has no serializer defined+ class MissingSerializerError < StandardError+ def initialize(model_class)+ serializer_name = "Spree::Events::#{model_class.name.demodulize}Serializer"+ super(+ "Missing event serializer for #{model_class.name}. " \+ "Please create #{serializer_name} that inherits from Spree::Events::BaseSerializer. " \+ "Example:\n\n" \+ " class #{serializer_name} < Spree::Events::BaseSerializer\n" \+ " protected\n\n" \+ " def attributes\n" \+ " {\n" \+ " id: resource.id,\n" \+ " # add other attributes here\n" \+ " updated_at: timestamp(resource.updated_at)\n" \+ " }\n" \+ " end\n" \+ " end"+ )+ end+ end+included doclass_attribute :publish_events, default: trueclass_attribute :lifecycle_events_enabled, default: false- class_attribute :event_serialization_options, default: {}endclass_methods do@@ -44,18 +71,15 @@ module Spree# @param options [Hash] Options for lifecycle events# @option options [Array<Symbol>] :only Limit to specific events (:create, :update, :destroy)# @option options [Array<Symbol>] :except Exclude specific events- # @option options [Hash] :serialize Options passed to serializable_hash# @return [void]## @example# publishes_lifecycle_events# publishes_lifecycle_events only: [:create, :destroy]# publishes_lifecycle_events except: [:update]- # publishes_lifecycle_events serialize: { only: [:id, :name] }#def publishes_lifecycle_events(options = {})self.lifecycle_events_enabled = true- self.event_serialization_options = options.fetch(:serialize, {})events = [:create, :update, :destroy]events &= Array(options[:only]) if options[:only]@@ -116,19 +140,47 @@ module Spreedef publish_event(event_name, payload = nil, metadata = {})return unless Spree::Events.enabled?+ @_current_event_name = event_namepayload ||= event_payloadSpree::Events.publish(event_name, payload, metadata.merge(default_event_metadata))+ ensure+ @_current_event_name = nilend# Get the payload for events#- # Override this method to customize the data sent with events.- # By default, uses ActiveModel::Serialization#serializable_hash.+ # Uses dedicated event serializer (Spree::Events::ModelSerializer).+ # Raises MissingSerializerError if no serializer is defined.## @return [Hash]+ # @raise [MissingSerializerError] if no serializer is defined for this modeldef event_payload- options = self.class.event_serialization_options.presence || default_serialization_options- serializable_hash(options)+ serializer = event_serializer_class++ raise MissingSerializerError, self.class unless serializer++ serializer.serialize(self, event_context)+ end++ # Find the event serializer class for this model+ #+ # Looks for Spree::Events::ModelNameSerializer (e.g., Spree::Events::OrderSerializer)+ #+ # @return [Class, nil] The serializer class or nil if not found+ def event_serializer_class+ return nil unless self.class.name++ "Spree::Events::#{self.class.name.demodulize}Serializer".safe_constantize+ end++ # Context passed to the event serializer+ #+ # @return [Hash]+ def event_context+ {+ event_name: @_current_event_name,+ triggered_at: Time.current+ }end# Get the event prefix for this instance@@ -144,10 +196,6 @@ module Spreeself.class.publish_events && Spree::Events.enabled?end- def default_serialization_options- {}- end-def default_event_metadata{model_class: self.class.name,diff --git a/core/app/serializers/spree/events/asset_serializer.rb b/core/app/serializers/spree/events/asset_serializer.rbnew file mode 100644index 0000000000..1e898b2401--- /dev/null+++ b/core/app/serializers/spree/events/asset_serializer.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Spree+ module Events+ class AssetSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ type: resource.type,+ viewable_type: resource.viewable_type,+ viewable_id: resource.viewable_id,+ position: resource.position,+ alt: resource.alt,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/base_serializer.rb b/core/app/serializers/spree/events/base_serializer.rbnew file mode 100644index 0000000000..a39d302f1c--- /dev/null+++ b/core/app/serializers/spree/events/base_serializer.rb@@ -0,0 +1,61 @@+# frozen_string_literal: true++module Spree+ module Events+ class BaseSerializer+ attr_reader :resource, :context++ def initialize(resource, context = {})+ @resource = resource+ @context = context+ end++ # Main serialization method+ def as_json+ attributes+ end++ # Class method for convenience+ def self.serialize(resource, context = {})+ new(resource, context).as_json+ end++ protected++ # Override in subclasses to define attributes+ def attributes+ {+ id: resource.id+ }+ end++ # Context helpers+ def event_name+ context[:event_name]+ end++ def triggered_at+ context[:triggered_at] || Time.current+ end++ # Attribute helpers++ # Safely get attribute, returns nil if not present+ def attribute(name)+ resource.public_send(name) if resource.respond_to?(name)+ end++ # Timestamp helper - ISO8601 format+ def timestamp(time)+ time&.iso8601+ end++ # Money helper - decimal value for events+ def money(amount)+ return nil if amount.nil?++ amount.respond_to?(:to_d) ? amount.to_d : amount+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/customer_return_serializer.rb b/core/app/serializers/spree/events/customer_return_serializer.rbnew file mode 100644index 0000000000..3a9a9bebfc--- /dev/null+++ b/core/app/serializers/spree/events/customer_return_serializer.rb@@ -0,0 +1,20 @@+# frozen_string_literal: true++module Spree+ module Events+ class CustomerReturnSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ number: resource.number,+ stock_location_id: resource.stock_location_id,+ store_id: resource.store_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/digital_link_serializer.rb b/core/app/serializers/spree/events/digital_link_serializer.rbnew file mode 100644index 0000000000..66a8d03cad--- /dev/null+++ b/core/app/serializers/spree/events/digital_link_serializer.rb@@ -0,0 +1,20 @@+# frozen_string_literal: true++module Spree+ module Events+ class DigitalLinkSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ digital_id: resource.digital_id,+ line_item_id: resource.line_item_id,+ access_counter: resource.access_counter,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/digital_serializer.rb b/core/app/serializers/spree/events/digital_serializer.rbnew file mode 100644index 0000000000..ddce35828e--- /dev/null+++ b/core/app/serializers/spree/events/digital_serializer.rb@@ -0,0 +1,18 @@+# frozen_string_literal: true++module Spree+ module Events+ class DigitalSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ variant_id: resource.variant_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/export_serializer.rb b/core/app/serializers/spree/events/export_serializer.rbnew file mode 100644index 0000000000..ea313de947--- /dev/null+++ b/core/app/serializers/spree/events/export_serializer.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Spree+ module Events+ class ExportSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ number: resource.number,+ type: resource.type,+ format: resource.format,+ user_id: resource.user_id,+ store_id: resource.store_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/gift_card_batch_serializer.rb b/core/app/serializers/spree/events/gift_card_batch_serializer.rbnew file mode 100644index 0000000000..767fe9a277--- /dev/null+++ b/core/app/serializers/spree/events/gift_card_batch_serializer.rb@@ -0,0 +1,24 @@+# frozen_string_literal: true++module Spree+ module Events+ class GiftCardBatchSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ codes_count: resource.codes_count,+ amount: money(resource.amount),+ currency: resource.currency,+ prefix: resource.prefix,+ expires_at: resource.expires_at&.to_s,+ store_id: resource.store_id,+ created_by_id: resource.created_by_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/gift_card_serializer.rb b/core/app/serializers/spree/events/gift_card_serializer.rbnew file mode 100644index 0000000000..37c32f3cf1--- /dev/null+++ b/core/app/serializers/spree/events/gift_card_serializer.rb@@ -0,0 +1,29 @@+# frozen_string_literal: true++module Spree+ module Events+ class GiftCardSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ code: resource.code,+ state: resource.state.to_s,+ amount: money(resource.amount),+ amount_used: money(resource.amount_used),+ amount_authorized: money(resource.amount_authorized),+ amount_remaining: money(resource.amount_remaining),+ currency: resource.currency,+ expires_at: resource.expires_at&.iso8601,+ redeemed_at: timestamp(resource.redeemed_at),+ user_id: resource.user_id,+ store_id: resource.store_id,+ gift_card_batch_id: resource.gift_card_batch_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/image_serializer.rb b/core/app/serializers/spree/events/image_serializer.rbnew file mode 100644index 0000000000..76e74653d5--- /dev/null+++ b/core/app/serializers/spree/events/image_serializer.rb@@ -0,0 +1,9 @@+# frozen_string_literal: true++module Spree+ module Events+ # Image serializer - uses the same attributes as AssetSerializer+ class ImageSerializer < AssetSerializer+ end+ end+enddiff --git a/core/app/serializers/spree/events/import_serializer.rb b/core/app/serializers/spree/events/import_serializer.rbnew file mode 100644index 0000000000..ee1798c7b5--- /dev/null+++ b/core/app/serializers/spree/events/import_serializer.rb@@ -0,0 +1,24 @@+# frozen_string_literal: true++module Spree+ module Events+ class ImportSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ number: resource.number,+ type: resource.type,+ status: resource.status.to_s,+ owner_type: resource.owner_type,+ owner_id: resource.owner_id,+ user_id: resource.user_id,+ rows_count: resource.rows_count,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/invitation_serializer.rb b/core/app/serializers/spree/events/invitation_serializer.rbnew file mode 100644index 0000000000..8f1c1f902a--- /dev/null+++ b/core/app/serializers/spree/events/invitation_serializer.rb@@ -0,0 +1,28 @@+# frozen_string_literal: true++module Spree+ module Events+ class InvitationSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ email: resource.email,+ status: resource.status.to_s,+ resource_type: resource.resource_type,+ resource_id: resource.resource_id,+ inviter_type: resource.inviter_type,+ inviter_id: resource.inviter_id,+ invitee_type: resource.invitee_type,+ invitee_id: resource.invitee_id,+ role_id: resource.role_id,+ expires_at: timestamp(resource.expires_at),+ accepted_at: timestamp(resource.accepted_at),+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/legacy_user_serializer.rb b/core/app/serializers/spree/events/legacy_user_serializer.rbnew file mode 100644index 0000000000..3fb4e4ef99--- /dev/null+++ b/core/app/serializers/spree/events/legacy_user_serializer.rb@@ -0,0 +1,9 @@+# frozen_string_literal: true++module Spree+ module Events+ # LegacyUser serializer - uses the same attributes as UserSerializer+ class LegacyUserSerializer < UserSerializer+ end+ end+enddiff --git a/core/app/serializers/spree/events/line_item_serializer.rb b/core/app/serializers/spree/events/line_item_serializer.rbnew file mode 100644index 0000000000..2fbea9d63b--- /dev/null+++ b/core/app/serializers/spree/events/line_item_serializer.rb@@ -0,0 +1,31 @@+# frozen_string_literal: true++module Spree+ module Events+ class LineItemSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ quantity: resource.quantity,+ price: money(resource.price),+ currency: resource.currency,+ cost_price: money(resource.cost_price),+ adjustment_total: money(resource.adjustment_total),+ additional_tax_total: money(resource.additional_tax_total),+ promo_total: money(resource.promo_total),+ included_tax_total: money(resource.included_tax_total),+ pre_tax_amount: money(resource.pre_tax_amount),+ taxable_adjustment_total: money(resource.taxable_adjustment_total),+ non_taxable_adjustment_total: money(resource.non_taxable_adjustment_total),+ variant_id: resource.variant_id,+ order_id: resource.order_id,+ tax_category_id: resource.tax_category_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/newsletter_subscriber_serializer.rb b/core/app/serializers/spree/events/newsletter_subscriber_serializer.rbnew file mode 100644index 0000000000..ca7d0d4369--- /dev/null+++ b/core/app/serializers/spree/events/newsletter_subscriber_serializer.rb@@ -0,0 +1,21 @@+# frozen_string_literal: true++module Spree+ module Events+ class NewsletterSubscriberSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ email: resource.email,+ verified: resource.verified?,+ verified_at: timestamp(resource.verified_at),+ user_id: resource.user_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/order_serializer.rb b/core/app/serializers/spree/events/order_serializer.rbnew file mode 100644index 0000000000..f4a5b6f0bd--- /dev/null+++ b/core/app/serializers/spree/events/order_serializer.rb@@ -0,0 +1,35 @@+# frozen_string_literal: true++module Spree+ module Events+ class OrderSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ number: resource.number,+ state: resource.state.to_s,+ payment_state: resource.payment_state.to_s,+ shipment_state: resource.shipment_state.to_s,+ total: money(resource.total),+ item_total: money(resource.item_total),+ shipment_total: money(resource.shipment_total),+ adjustment_total: money(resource.adjustment_total),+ promo_total: money(resource.promo_total),+ included_tax_total: money(resource.included_tax_total),+ additional_tax_total: money(resource.additional_tax_total),+ item_count: resource.item_count,+ currency: resource.currency,+ email: resource.email,+ user_id: resource.user_id,+ store_id: resource.store_id,+ completed_at: timestamp(resource.completed_at),+ canceled_at: timestamp(resource.canceled_at),+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/payment_serializer.rb b/core/app/serializers/spree/events/payment_serializer.rbnew file mode 100644index 0000000000..3480ab864f--- /dev/null+++ b/core/app/serializers/spree/events/payment_serializer.rb@@ -0,0 +1,24 @@+# frozen_string_literal: true++module Spree+ module Events+ class PaymentSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ number: resource.number,+ state: resource.state.to_s,+ amount: money(resource.amount),+ order_id: resource.order_id,+ payment_method_id: resource.payment_method_id,+ source_type: resource.source_type,+ source_id: resource.source_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/post_category_serializer.rb b/core/app/serializers/spree/events/post_category_serializer.rbnew file mode 100644index 0000000000..791c07a942--- /dev/null+++ b/core/app/serializers/spree/events/post_category_serializer.rb@@ -0,0 +1,20 @@+# frozen_string_literal: true++module Spree+ module Events+ class PostCategorySerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ title: resource.title,+ slug: resource.slug,+ store_id: resource.store_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/post_serializer.rb b/core/app/serializers/spree/events/post_serializer.rbnew file mode 100644index 0000000000..cd2c785eb5--- /dev/null+++ b/core/app/serializers/spree/events/post_serializer.rb@@ -0,0 +1,26 @@+# frozen_string_literal: true++module Spree+ module Events+ class PostSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ title: resource.title,+ slug: resource.slug,+ meta_title: resource.meta_title,+ meta_description: resource.meta_description,+ published_at: timestamp(resource.published_at),+ deleted_at: timestamp(resource.deleted_at),+ author_id: resource.author_id,+ post_category_id: resource.post_category_id,+ store_id: resource.store_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/price_serializer.rb b/core/app/serializers/spree/events/price_serializer.rbnew file mode 100644index 0000000000..4d39500c01--- /dev/null+++ b/core/app/serializers/spree/events/price_serializer.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Spree+ module Events+ class PriceSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ amount: money(resource.amount),+ compare_at_amount: money(resource.compare_at_amount),+ currency: resource.currency,+ variant_id: resource.variant_id,+ deleted_at: timestamp(resource.deleted_at),+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/product_serializer.rb b/core/app/serializers/spree/events/product_serializer.rbnew file mode 100644index 0000000000..2f786e6d31--- /dev/null+++ b/core/app/serializers/spree/events/product_serializer.rb@@ -0,0 +1,23 @@+# frozen_string_literal: true++module Spree+ module Events+ class ProductSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ name: resource.name,+ slug: resource.slug,+ status: resource.status.to_s,+ available_on: timestamp(resource.available_on),+ discontinue_on: timestamp(resource.discontinue_on),+ store_ids: resource.store_ids,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/promotion_serializer.rb b/core/app/serializers/spree/events/promotion_serializer.rbnew file mode 100644index 0000000000..5e0a77de69--- /dev/null+++ b/core/app/serializers/spree/events/promotion_serializer.rb@@ -0,0 +1,32 @@+# frozen_string_literal: true++module Spree+ module Events+ class PromotionSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ name: resource.name,+ description: resource.description,+ code: resource.code,+ type: resource.type,+ kind: resource.kind,+ path: resource.path,+ match_policy: resource.match_policy,+ usage_limit: resource.usage_limit,+ advertise: resource.advertise,+ multi_codes: resource.multi_codes,+ code_prefix: resource.code_prefix,+ number_of_codes: resource.number_of_codes,+ starts_at: timestamp(resource.starts_at),+ expires_at: timestamp(resource.expires_at),+ promotion_category_id: resource.promotion_category_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/refund_serializer.rb b/core/app/serializers/spree/events/refund_serializer.rbnew file mode 100644index 0000000000..ee1e2cedba--- /dev/null+++ b/core/app/serializers/spree/events/refund_serializer.rb@@ -0,0 +1,23 @@+# frozen_string_literal: true++module Spree+ module Events+ class RefundSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ amount: money(resource.amount),+ transaction_id: resource.transaction_id,+ payment_id: resource.payment_id,+ refund_reason_id: resource.refund_reason_id,+ reimbursement_id: resource.reimbursement_id,+ refunder_id: resource.refunder_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/reimbursement_serializer.rb b/core/app/serializers/spree/events/reimbursement_serializer.rbnew file mode 100644index 0000000000..040538fcda--- /dev/null+++ b/core/app/serializers/spree/events/reimbursement_serializer.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Spree+ module Events+ class ReimbursementSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ number: resource.number,+ reimbursement_status: resource.reimbursement_status,+ total: money(resource.total),+ order_id: resource.order_id,+ customer_return_id: resource.customer_return_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/return_authorization_serializer.rb b/core/app/serializers/spree/events/return_authorization_serializer.rbnew file mode 100644index 0000000000..dfb0975272--- /dev/null+++ b/core/app/serializers/spree/events/return_authorization_serializer.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Spree+ module Events+ class ReturnAuthorizationSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ number: resource.number,+ state: resource.state.to_s,+ order_id: resource.order_id,+ stock_location_id: resource.stock_location_id,+ return_authorization_reason_id: resource.return_authorization_reason_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/return_item_serializer.rb b/core/app/serializers/spree/events/return_item_serializer.rbnew file mode 100644index 0000000000..bb3f0d0792--- /dev/null+++ b/core/app/serializers/spree/events/return_item_serializer.rb@@ -0,0 +1,27 @@+# frozen_string_literal: true++module Spree+ module Events+ class ReturnItemSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ reception_status: resource.reception_status,+ acceptance_status: resource.acceptance_status,+ pre_tax_amount: money(resource.pre_tax_amount),+ included_tax_total: money(resource.included_tax_total),+ additional_tax_total: money(resource.additional_tax_total),+ inventory_unit_id: resource.inventory_unit_id,+ return_authorization_id: resource.return_authorization_id,+ customer_return_id: resource.customer_return_id,+ reimbursement_id: resource.reimbursement_id,+ exchange_variant_id: resource.exchange_variant_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/shipment_serializer.rb b/core/app/serializers/spree/events/shipment_serializer.rbnew file mode 100644index 0000000000..5e1a318c32--- /dev/null+++ b/core/app/serializers/spree/events/shipment_serializer.rb@@ -0,0 +1,24 @@+# frozen_string_literal: true++module Spree+ module Events+ class ShipmentSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ number: resource.number,+ state: resource.state.to_s,+ tracking: resource.tracking,+ cost: money(resource.cost),+ order_id: resource.order_id,+ stock_location_id: resource.stock_location_id,+ shipped_at: timestamp(resource.shipped_at),+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/stock_item_serializer.rb b/core/app/serializers/spree/events/stock_item_serializer.rbnew file mode 100644index 0000000000..513ed12a29--- /dev/null+++ b/core/app/serializers/spree/events/stock_item_serializer.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Spree+ module Events+ class StockItemSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ count_on_hand: resource.count_on_hand,+ backorderable: resource.backorderable,+ stock_location_id: resource.stock_location_id,+ variant_id: resource.variant_id,+ deleted_at: timestamp(resource.deleted_at),+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/stock_movement_serializer.rb b/core/app/serializers/spree/events/stock_movement_serializer.rbnew file mode 100644index 0000000000..e79a4f3cab--- /dev/null+++ b/core/app/serializers/spree/events/stock_movement_serializer.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Spree+ module Events+ class StockMovementSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ quantity: resource.quantity,+ action: resource.action,+ originator_type: resource.originator_type,+ originator_id: resource.originator_id,+ stock_item_id: resource.stock_item_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/stock_transfer_serializer.rb b/core/app/serializers/spree/events/stock_transfer_serializer.rbnew file mode 100644index 0000000000..db669e3c56--- /dev/null+++ b/core/app/serializers/spree/events/stock_transfer_serializer.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Spree+ module Events+ class StockTransferSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ number: resource.number,+ type: resource.type,+ reference: resource.reference,+ source_location_id: resource.source_location_id,+ destination_location_id: resource.destination_location_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/store_credit_serializer.rb b/core/app/serializers/spree/events/store_credit_serializer.rbnew file mode 100644index 0000000000..0feedea7af--- /dev/null+++ b/core/app/serializers/spree/events/store_credit_serializer.rb@@ -0,0 +1,30 @@+# frozen_string_literal: true++module Spree+ module Events+ class StoreCreditSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ amount: money(resource.amount),+ amount_used: money(resource.amount_used),+ amount_authorized: money(resource.amount_authorized),+ currency: resource.currency,+ memo: resource.memo,+ user_id: resource.user_id,+ category_id: resource.category_id,+ type_id: resource.type_id,+ store_id: resource.store_id,+ created_by_id: resource.created_by_id,+ originator_type: resource.originator_type,+ originator_id: resource.originator_id,+ deleted_at: timestamp(resource.deleted_at),+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/user_serializer.rb b/core/app/serializers/spree/events/user_serializer.rbnew file mode 100644index 0000000000..8df13e10c2--- /dev/null+++ b/core/app/serializers/spree/events/user_serializer.rb@@ -0,0 +1,18 @@+# frozen_string_literal: true++module Spree+ module Events+ class UserSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ email: resource.email,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/variant_serializer.rb b/core/app/serializers/spree/events/variant_serializer.rbnew file mode 100644index 0000000000..d72ab180f2--- /dev/null+++ b/core/app/serializers/spree/events/variant_serializer.rb@@ -0,0 +1,34 @@+# frozen_string_literal: true++module Spree+ module Events+ class VariantSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ sku: resource.sku,+ barcode: resource.barcode,+ is_master: resource.is_master,+ position: resource.position,+ weight: money(resource.weight),+ height: money(resource.height),+ width: money(resource.width),+ depth: money(resource.depth),+ weight_unit: resource.weight_unit,+ dimensions_unit: resource.dimensions_unit,+ cost_price: money(resource.cost_price),+ cost_currency: resource.cost_currency,+ track_inventory: resource.track_inventory,+ product_id: resource.product_id,+ tax_category_id: resource.tax_category_id,+ discontinue_on: timestamp(resource.discontinue_on),+ deleted_at: timestamp(resource.deleted_at),+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/wished_item_serializer.rb b/core/app/serializers/spree/events/wished_item_serializer.rbnew file mode 100644index 0000000000..811acfc73f--- /dev/null+++ b/core/app/serializers/spree/events/wished_item_serializer.rb@@ -0,0 +1,20 @@+# frozen_string_literal: true++module Spree+ module Events+ class WishedItemSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ quantity: resource.quantity,+ variant_id: resource.variant_id,+ wishlist_id: resource.wishlist_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/app/serializers/spree/events/wishlist_serializer.rb b/core/app/serializers/spree/events/wishlist_serializer.rbnew file mode 100644index 0000000000..694bf7341b--- /dev/null+++ b/core/app/serializers/spree/events/wishlist_serializer.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++module Spree+ module Events+ class WishlistSerializer < BaseSerializer+ protected++ def attributes+ {+ id: resource.id,+ name: resource.name,+ is_private: resource.is_private,+ is_default: resource.is_default,+ user_id: resource.user_id,+ store_id: resource.store_id,+ created_at: timestamp(resource.created_at),+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+enddiff --git a/core/spec/models/concerns/spree/publishable_spec.rb b/core/spec/models/concerns/spree/publishable_spec.rbindex cad1248deb..be52e97229 100644--- a/core/spec/models/concerns/spree/publishable_spec.rb+++ b/core/spec/models/concerns/spree/publishable_spec.rb@@ -11,62 +11,77 @@ RSpec.describe Spree::Publishable doSpree::Events.reset!end+ # Define a test serializer for the spec+ let(:test_serializer_class) do+ Class.new(Spree::Events::BaseSerializer) do+ protected++ def attributes+ {+ id: resource.id,+ name: resource.name,+ updated_at: timestamp(resource.updated_at)+ }+ end+ end+ end+let(:publishable_class) doClass.new(Spree::Base) doself.table_name = 'spree_products'include Spree::Publishable-- # Simulate ActiveModel::Serialization- def serializable_hash(options = {})- { 'id' => id, 'name' => name }.merge(options[:extra] || {})- endendend- let(:instance) { publishable_class.new(id: 1, name: 'Test Product') }+ let(:instance) { publishable_class.new(id: 1, name: 'Test Product', updated_at: Time.current) }describe '#publish_event' do+ before do+ stub_const('Spree::TestProduct', publishable_class)+ stub_const('Spree::Events::TestProductSerializer', test_serializer_class)+ end+it 'publishes an event with the model payload' doreceived_event = nil- Spree::Events.subscribe('product.custom', async: false) { |e| received_event = e }+ Spree::Events.subscribe('test_product.custom', async: false) { |e| received_event = e }Spree::Events.activate!- instance.publish_event('product.custom')+ instance.publish_event('test_product.custom')expect(received_event).to be_present- expect(received_event.name).to eq('product.custom')+ expect(received_event.name).to eq('test_product.custom')expect(received_event.payload['id']).to eq(1)expect(received_event.payload['name']).to eq('Test Product')endit 'allows custom payload' doreceived_event = nil- Spree::Events.subscribe('product.custom', async: false) { |e| received_event = e }+ Spree::Events.subscribe('test_product.custom', async: false) { |e| received_event = e }Spree::Events.activate!- instance.publish_event('product.custom', { custom: 'data' })+ instance.publish_event('test_product.custom', { custom: 'data' })expect(received_event.payload).to eq({ 'custom' => 'data' })endit 'includes model metadata with IDs as strings' doreceived_event = nil- Spree::Events.subscribe('product.custom', async: false) { |e| received_event = e }+ Spree::Events.subscribe('test_product.custom', async: false) { |e| received_event = e }Spree::Events.activate!- instance.publish_event('product.custom')+ instance.publish_event('test_product.custom')expect(received_event.metadata['model_id']).to eq('1')endit 'does not publish when events are disabled' doreceived = false- Spree::Events.subscribe('product.custom', async: false) { received = true }+ Spree::Events.subscribe('test_product.custom', async: false) { received = true }Spree::Events.activate!Spree::Events.disable do- instance.publish_event('product.custom')+ instance.publish_event('test_product.custom')endexpect(received).to be false@@ -74,34 +89,72 @@ RSpec.describe Spree::Publishable doenddescribe '#event_payload' do- it 'returns serializable_hash by default' do- expect(instance.event_payload).to eq({ 'id' => 1, 'name' => 'Test Product' })+ context 'with a serializer defined' do+ before do+ stub_const('Spree::TestProduct', publishable_class)+ stub_const('Spree::Events::TestProductSerializer', test_serializer_class)+ end++ it 'returns the serialized payload' do+ payload = instance.event_payload++ expect(payload[:id]).to eq(1)+ expect(payload[:name]).to eq('Test Product')+ expect(payload[:updated_at]).to be_present+ endend- context 'with custom serialization options' do- let(:custom_class) do+ context 'without a serializer defined' do+ let(:no_serializer_class) doClass.new(Spree::Base) doself.table_name = 'spree_products'-include Spree::Publishable- self.event_serialization_options = { extra: { 'custom' => 'field' } }-- def serializable_hash(options = {})- { 'id' => id }.merge(options[:extra] || {})- endendend- it 'uses the custom serialization options' do- instance = custom_class.new(id: 1)- expect(instance.event_payload).to eq({ 'id' => 1, 'custom' => 'field' })+ before do+ stub_const('Spree::NoSerializer', no_serializer_class)+ end++ it 'raises MissingSerializerError with helpful message' do+ instance = no_serializer_class.new(id: 1, name: 'Test')++ expect { instance.event_payload }.to raise_error(+ Spree::Publishable::MissingSerializerError,+ /Missing event serializer for Spree::NoSerializer/+ )+ end++ it 'includes example code in the error message' do+ instance = no_serializer_class.new(id: 1, name: 'Test')++ expect { instance.event_payload }.to raise_error(+ Spree::Publishable::MissingSerializerError,+ /class Spree::Events::NoSerializerSerializer < Spree::Events::BaseSerializer/+ )+ end+ end++ context 'with anonymous class' do+ it 'returns nil for event_serializer_class' do+ anon_class = Class.new(Spree::Base) do+ self.table_name = 'spree_products'+ include Spree::Publishable+ end++ instance = anon_class.new(id: 1)+ expect(instance.event_serializer_class).to be_nilendendenddescribe '#event_prefix' do- it 'returns the model name element' do+ before dostub_const('Spree::Product', publishable_class)+ stub_const('Spree::Events::ProductSerializer', test_serializer_class)+ end++ it 'returns the model name element' doinstance = Spree::Product.newexpect(instance.event_prefix).to eq('product')@@ -115,15 +168,12 @@ RSpec.describe Spree::Publishable doinclude Spree::Publishablepublishes_lifecycle_events-- def serializable_hash(_options = {})- { 'id' => id, 'name' => name }- endendendbefore dostub_const('Spree::TestProduct', lifecycle_class)+ stub_const('Spree::Events::TestProductSerializer', test_serializer_class)endit 'enables lifecycle events' do@@ -177,25 +227,6 @@ RSpec.describe Spree::Publishable doendend- context 'with serialize option' do- let(:serialize_class) do- Class.new(ApplicationRecord) do- self.table_name = 'spree_products'-- include Spree::Publishable- publishes_lifecycle_events serialize: { only: [:id] }-- def serializable_hash(options = {})- options[:only] ? { 'id' => id } : { 'id' => id, 'name' => name }- end- end- end-- it 'uses custom serialization options' do- expect(serialize_class.event_serialization_options).to eq({ only: [:id] })- end- end-context 'with skip_lifecycle_events' dolet(:skipped_class) doClass.new(Spree::Base) do@@ -211,13 +242,18 @@ RSpec.describe Spree::Publishable doenddescribe '.event_prefix' do- it 'derives from model name' do+ before dostub_const('Spree::OrderLineItem', publishable_class)+ stub_const('Spree::Events::OrderLineItemSerializer', test_serializer_class)+ end++ it 'derives from model name' doexpect(Spree::OrderLineItem.event_prefix).to eq('order_line_item')endit 'can be customized' dostub_const('Spree::CustomModel', publishable_class)+ stub_const('Spree::Events::CustomModelSerializer', test_serializer_class)Spree::CustomModel.event_prefix = 'custom'expect(Spree::CustomModel.event_prefix).to eq('custom')enddiff --git a/core/spec/serializers/spree/events/asset_serializer_spec.rb b/core/spec/serializers/spree/events/asset_serializer_spec.rbnew file mode 100644index 0000000000..3f11e786da--- /dev/null+++ b/core/spec/serializers/spree/events/asset_serializer_spec.rb@@ -0,0 +1,36 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::AssetSerializer do+ subject { described_class.serialize(asset) }++ let(:product) { create(:product) }+ let(:variant) { product.master }+ let(:asset) { create(:image, viewable: variant) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(asset.id)+ expect(subject[:type]).to eq(asset.type)+ end++ it 'includes viewable polymorphic reference' do+ expect(subject[:viewable_type]).to eq('Spree::Variant')+ expect(subject[:viewable_id]).to eq(variant.id)+ end++ it 'includes position' do+ expect(subject).to have_key(:position)+ end++ it 'includes alt text' do+ expect(subject).to have_key(:alt)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/base_serializer_spec.rb b/core/spec/serializers/spree/events/base_serializer_spec.rbnew file mode 100644index 0000000000..d655acc48f--- /dev/null+++ b/core/spec/serializers/spree/events/base_serializer_spec.rb@@ -0,0 +1,86 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::BaseSerializer do+ let(:test_class) do+ Class.new(described_class) do+ protected++ def attributes+ {+ id: resource.id,+ name: resource.name,+ created_at: timestamp(resource.created_at)+ }+ end+ end+ end++ let(:resource) { Spree::Product.new(id: 1, name: 'Test Product', created_at: Time.zone.parse('2024-01-15 10:30:00')) }+ let(:context) { { event_name: 'product.test' } }+ let(:serializer) { test_class.new(resource, context) }++ describe '#as_json' do+ subject { serializer.as_json }++ it 'returns a hash with attributes' do+ expect(subject).to be_a(Hash)+ expect(subject[:id]).to eq(1)+ expect(subject[:name]).to eq('Test Product')+ end++ it 'formats timestamps as ISO8601' do+ expect(subject[:created_at]).to eq('2024-01-15T10:30:00Z')+ end+ end++ describe '.serialize' do+ it 'creates an instance and calls as_json' do+ result = test_class.serialize(resource, context)+ expect(result).to be_a(Hash)+ expect(result[:id]).to eq(1)+ end+ end++ describe '#timestamp' do+ it 'returns nil for nil values' do+ expect(serializer.send(:timestamp, nil)).to be_nil+ end++ it 'returns ISO8601 formatted string' do+ time = Time.zone.parse('2024-06-15 14:30:00')+ expect(serializer.send(:timestamp, time)).to eq('2024-06-15T14:30:00Z')+ end+ end++ describe '#money' do+ it 'returns nil for nil values' do+ expect(serializer.send(:money, nil)).to be_nil+ end++ it 'returns decimal value for numbers' do+ expect(serializer.send(:money, 10.50)).to eq(10.50)+ end++ it 'returns decimal value for BigDecimal' do+ expect(serializer.send(:money, BigDecimal('99.99'))).to eq(BigDecimal('99.99'))+ end+ end++ describe '#event_name' do+ it 'returns the event name from context' do+ expect(serializer.send(:event_name)).to eq('product.test')+ end+ end++ describe '#attribute' do+ it 'returns the attribute value if it exists' do+ expect(serializer.send(:attribute, :name)).to eq('Test Product')+ end++ it 'returns nil if the attribute does not exist' do+ expect(serializer.send(:attribute, :nonexistent)).to be_nil+ end+ end+enddiff --git a/core/spec/serializers/spree/events/customer_return_serializer_spec.rb b/core/spec/serializers/spree/events/customer_return_serializer_spec.rbnew file mode 100644index 0000000000..839689e952--- /dev/null+++ b/core/spec/serializers/spree/events/customer_return_serializer_spec.rb@@ -0,0 +1,26 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::CustomerReturnSerializer do+ let(:customer_return) { create(:customer_return) }++ subject { described_class.serialize(customer_return) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(customer_return.id)+ expect(subject[:number]).to eq(customer_return.number)+ end++ it 'includes foreign keys' do+ expect(subject[:stock_location_id]).to eq(customer_return.stock_location_id)+ expect(subject).to have_key(:store_id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/digital_link_serializer_spec.rb b/core/spec/serializers/spree/events/digital_link_serializer_spec.rbnew file mode 100644index 0000000000..7d5c0eb1c4--- /dev/null+++ b/core/spec/serializers/spree/events/digital_link_serializer_spec.rb@@ -0,0 +1,29 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::DigitalLinkSerializer do+ let(:digital_link) { create(:digital_link) }++ subject { described_class.serialize(digital_link) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(digital_link.id)+ end++ it 'includes foreign keys' do+ expect(subject[:digital_id]).to eq(digital_link.digital_id)+ expect(subject[:line_item_id]).to eq(digital_link.line_item_id)+ end++ it 'includes access_counter' do+ expect(subject).to have_key(:access_counter)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/digital_serializer_spec.rb b/core/spec/serializers/spree/events/digital_serializer_spec.rbnew file mode 100644index 0000000000..c9f60907ab--- /dev/null+++ b/core/spec/serializers/spree/events/digital_serializer_spec.rb@@ -0,0 +1,25 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::DigitalSerializer do+ let(:variant) { create(:variant) }+ let(:digital) { create(:digital, variant: variant) }++ subject { described_class.serialize(digital) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(digital.id)+ end++ it 'includes variant_id' do+ expect(subject[:variant_id]).to eq(variant.id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/export_serializer_spec.rb b/core/spec/serializers/spree/events/export_serializer_spec.rbnew file mode 100644index 0000000000..462d2eab40--- /dev/null+++ b/core/spec/serializers/spree/events/export_serializer_spec.rb@@ -0,0 +1,36 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::ExportSerializer do+ let(:store) { create(:store) }+ let(:admin_user) { create(:admin_user) }+ let(:export) { create(:export, store: store, user: admin_user) }++ subject { described_class.serialize(export) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(export.id)+ expect(subject[:number]).to eq(export.number)+ end++ it 'includes type' do+ expect(subject[:type]).to be_present+ end++ it 'includes format' do+ expect(subject).to have_key(:format)+ end++ it 'includes foreign keys' do+ expect(subject[:user_id]).to eq(admin_user.id)+ expect(subject[:store_id]).to eq(store.id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/gift_card_batch_serializer_spec.rb b/core/spec/serializers/spree/events/gift_card_batch_serializer_spec.rbnew file mode 100644index 0000000000..e88acc64d4--- /dev/null+++ b/core/spec/serializers/spree/events/gift_card_batch_serializer_spec.rb@@ -0,0 +1,52 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::GiftCardBatchSerializer do+ let(:store) { create(:store) }+ let(:admin_user) { create(:admin_user) }+ let(:gift_card_batch) do+ create(:gift_card_batch,+ store: store,+ created_by: admin_user,+ amount: 50.00,+ currency: 'USD',+ codes_count: 10,+ prefix: 'GIFT')+ end++ subject { described_class.serialize(gift_card_batch) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(gift_card_batch.id)+ end++ it 'includes codes_count' do+ expect(subject[:codes_count]).to eq(10)+ end++ it 'includes amount fields' do+ expect(subject[:amount]).to eq(50.00)+ expect(subject[:currency]).to eq('USD')+ end++ it 'includes prefix' do+ expect(subject).to have_key(:prefix)+ end++ it 'includes expires_at' do+ expect(subject).to have_key(:expires_at)+ end++ it 'includes foreign keys' do+ expect(subject[:store_id]).to eq(store.id)+ expect(subject[:created_by_id]).to eq(admin_user.id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/gift_card_serializer_spec.rb b/core/spec/serializers/spree/events/gift_card_serializer_spec.rbnew file mode 100644index 0000000000..5984750c3a--- /dev/null+++ b/core/spec/serializers/spree/events/gift_card_serializer_spec.rb@@ -0,0 +1,55 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::GiftCardSerializer do+ let(:store) { create(:store) }+ let(:gift_card) do+ create(:gift_card,+ store: store,+ amount: 100.00,+ amount_used: 25.00,+ currency: 'USD',+ expires_at: Date.parse('2025-12-31'))+ end++ subject { described_class.serialize(gift_card) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(gift_card.id)+ expect(subject[:code]).to eq(gift_card.code)+ end++ it 'includes state as string' do+ expect(subject[:state]).to be_a(String)+ end++ it 'includes amount fields' do+ expect(subject[:amount]).to eq(100.00)+ expect(subject[:amount_used]).to eq(25.00)+ expect(subject[:amount_authorized]).to be_present+ expect(subject[:amount_remaining]).to eq(75.00)+ end++ it 'includes currency' do+ expect(subject[:currency]).to eq('USD')+ end++ it 'includes foreign keys' do+ expect(subject[:store_id]).to eq(store.id)+ expect(subject).to have_key(:user_id)+ expect(subject).to have_key(:gift_card_batch_id)+ end++ it 'includes dates' do+ expect(subject[:expires_at]).to eq('2025-12-31')+ expect(subject).to have_key(:redeemed_at)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/import_serializer_spec.rb b/core/spec/serializers/spree/events/import_serializer_spec.rbnew file mode 100644index 0000000000..e5f3b69bd1--- /dev/null+++ b/core/spec/serializers/spree/events/import_serializer_spec.rb@@ -0,0 +1,44 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::ImportSerializer do+ let(:store) { create(:store) }+ let(:admin_user) { create(:admin_user) }+ let(:import) { create(:import, owner: store, user: admin_user) }++ subject { described_class.serialize(import) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(import.id)+ expect(subject[:number]).to eq(import.number)+ end++ it 'includes type' do+ expect(subject[:type]).to be_present+ end++ it 'includes status as string' do+ expect(subject[:status]).to be_a(String)+ end++ it 'includes owner polymorphic reference' do+ expect(subject[:owner_type]).to eq('Spree::Store')+ expect(subject[:owner_id]).to eq(store.id)+ end++ it 'includes user_id' do+ expect(subject[:user_id]).to eq(admin_user.id)+ end++ it 'includes rows_count' do+ expect(subject).to have_key(:rows_count)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/invitation_serializer_spec.rb b/core/spec/serializers/spree/events/invitation_serializer_spec.rbnew file mode 100644index 0000000000..9004e42c04--- /dev/null+++ b/core/spec/serializers/spree/events/invitation_serializer_spec.rb@@ -0,0 +1,49 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::InvitationSerializer do+ let(:invitation) { create(:invitation) }++ subject { described_class.serialize(invitation) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(invitation.id)+ expect(subject[:email]).to eq(invitation.email)+ end++ it 'includes status as string' do+ expect(subject[:status]).to be_a(String)+ end++ it 'includes resource polymorphic reference' do+ expect(subject[:resource_type]).to eq(invitation.resource_type)+ expect(subject[:resource_id]).to eq(invitation.resource_id)+ end++ it 'includes inviter polymorphic reference' do+ expect(subject[:inviter_type]).to eq(invitation.inviter_type)+ expect(subject[:inviter_id]).to eq(invitation.inviter_id)+ end++ it 'includes invitee polymorphic reference' do+ expect(subject).to have_key(:invitee_type)+ expect(subject).to have_key(:invitee_id)+ end++ it 'includes role_id' do+ expect(subject[:role_id]).to eq(invitation.role_id)+ end++ it 'includes dates' do+ expect(subject).to have_key(:expires_at)+ expect(subject).to have_key(:accepted_at)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/legacy_user_serializer_spec.rb b/core/spec/serializers/spree/events/legacy_user_serializer_spec.rbnew file mode 100644index 0000000000..4fe243583f--- /dev/null+++ b/core/spec/serializers/spree/events/legacy_user_serializer_spec.rb@@ -0,0 +1,31 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::LegacyUserSerializer do+ let(:user) { create(:user) }++ subject { described_class.serialize(user) }++ describe '#as_json' do+ it 'inherits from UserSerializer' do+ expect(described_class.superclass).to eq(Spree::Events::UserSerializer)+ end++ it 'includes identity attributes' do+ expect(subject[:id]).to eq(user.id)+ expect(subject[:email]).to eq(user.email)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end++ it 'does not include sensitive data' do+ expect(subject).not_to have_key(:encrypted_password)+ expect(subject).not_to have_key(:password)+ expect(subject).not_to have_key(:spree_api_key)+ end+ end+enddiff --git a/core/spec/serializers/spree/events/line_item_serializer_spec.rb b/core/spec/serializers/spree/events/line_item_serializer_spec.rbnew file mode 100644index 0000000000..cf785da085--- /dev/null+++ b/core/spec/serializers/spree/events/line_item_serializer_spec.rb@@ -0,0 +1,47 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::LineItemSerializer do+ let(:order) { create(:order_with_line_items, line_items_count: 1) }+ let(:line_item) { order.line_items.first }++ subject { described_class.serialize(line_item) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(line_item.id)+ end++ it 'includes quantity' do+ expect(subject[:quantity]).to eq(line_item.quantity)+ end++ it 'includes price fields' do+ expect(subject[:price]).to be_present+ expect(subject[:currency]).to eq(line_item.currency)+ expect(subject).to have_key(:cost_price)+ end++ it 'includes adjustment totals' do+ expect(subject).to have_key(:adjustment_total)+ expect(subject).to have_key(:additional_tax_total)+ expect(subject).to have_key(:promo_total)+ expect(subject).to have_key(:included_tax_total)+ expect(subject).to have_key(:pre_tax_amount)+ expect(subject).to have_key(:taxable_adjustment_total)+ expect(subject).to have_key(:non_taxable_adjustment_total)+ end++ it 'includes foreign keys' do+ expect(subject[:variant_id]).to eq(line_item.variant_id)+ expect(subject[:order_id]).to eq(order.id)+ expect(subject).to have_key(:tax_category_id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/newsletter_subscriber_serializer_spec.rb b/core/spec/serializers/spree/events/newsletter_subscriber_serializer_spec.rbnew file mode 100644index 0000000000..c359885b34--- /dev/null+++ b/core/spec/serializers/spree/events/newsletter_subscriber_serializer_spec.rb@@ -0,0 +1,43 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::NewsletterSubscriberSerializer do+ let(:subscriber) do+ create(:newsletter_subscriber,+ email: '[email protected]',+ verified_at: Time.zone.parse('2024-01-15 10:30:00'))+ end++ subject { described_class.serialize(subscriber) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(subscriber.id)+ expect(subject[:email]).to eq('[email protected]')+ end++ it 'includes verified status' do+ expect(subject[:verified]).to be true+ expect(subject[:verified_at]).to eq('2024-01-15T10:30:00Z')+ end++ it 'includes user_id' do+ expect(subject).to have_key(:user_id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end++ context 'when not verified' do+ let(:subscriber) { create(:newsletter_subscriber, verified_at: nil) }++ it 'returns verified as false' do+ expect(subject[:verified]).to be false+ expect(subject[:verified_at]).to be_nil+ end+ end+ end+enddiff --git a/core/spec/serializers/spree/events/order_serializer_spec.rb b/core/spec/serializers/spree/events/order_serializer_spec.rbnew file mode 100644index 0000000000..2521676c34--- /dev/null+++ b/core/spec/serializers/spree/events/order_serializer_spec.rb@@ -0,0 +1,67 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::OrderSerializer do+ let(:store) { create(:store) }+ let(:user) { create(:user) }+ let(:order) do+ create(:completed_order_with_totals,+ store: store,+ user: user)+ end++ subject { described_class.serialize(order) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(order.id)+ expect(subject[:number]).to eq(order.number)+ end++ it 'includes state attributes as strings' do+ expect(subject[:state]).to be_a(String)+ expect(subject[:payment_state]).to be_a(String)+ expect(subject[:shipment_state]).to be_a(String)+ end++ it 'includes totals' do+ expect(subject[:total]).to be_present+ expect(subject[:item_total]).to be_present+ expect(subject[:shipment_total]).to be_present+ expect(subject[:adjustment_total]).to be_present+ expect(subject[:promo_total]).to be_present+ end++ it 'includes tax totals' do+ expect(subject).to have_key(:included_tax_total)+ expect(subject).to have_key(:additional_tax_total)+ end++ it 'includes item count and currency' do+ expect(subject[:item_count]).to eq(order.item_count)+ expect(subject[:currency]).to eq(order.currency)+ end++ it 'includes email' do+ expect(subject[:email]).to eq(order.email)+ end++ it 'includes foreign keys' do+ expect(subject[:user_id]).to eq(user.id)+ expect(subject[:store_id]).to eq(store.id)+ end++ it 'includes timestamps' do+ expect(subject[:completed_at]).to be_present+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end++ it 'does not include associations' do+ expect(subject).not_to have_key(:line_items)+ expect(subject).not_to have_key(:shipments)+ expect(subject).not_to have_key(:payments)+ end+ end+enddiff --git a/core/spec/serializers/spree/events/payment_serializer_spec.rb b/core/spec/serializers/spree/events/payment_serializer_spec.rbnew file mode 100644index 0000000000..55468864e0--- /dev/null+++ b/core/spec/serializers/spree/events/payment_serializer_spec.rb@@ -0,0 +1,52 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::PaymentSerializer do+ let(:order) { create(:order_with_line_items) }+ let(:payment_method) { create(:credit_card_payment_method) }+ let(:payment) do+ create(:payment,+ order: order,+ payment_method: payment_method,+ amount: 100.00,+ state: 'completed')+ end++ subject { described_class.serialize(payment) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(payment.id)+ expect(subject[:number]).to eq(payment.number)+ end++ it 'includes state as string' do+ expect(subject[:state]).to eq('completed')+ end++ it 'includes amount' do+ expect(subject[:amount]).to eq(100.00)+ end++ it 'includes foreign keys' do+ expect(subject[:order_id]).to eq(order.id)+ expect(subject[:payment_method_id]).to eq(payment_method.id)+ end++ it 'includes source polymorphic reference' do+ expect(subject).to have_key(:source_type)+ expect(subject).to have_key(:source_id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end++ it 'does not include associations' do+ expect(subject).not_to have_key(:refunds)+ expect(subject).not_to have_key(:log_entries)+ end+ end+enddiff --git a/core/spec/serializers/spree/events/post_category_serializer_spec.rb b/core/spec/serializers/spree/events/post_category_serializer_spec.rbnew file mode 100644index 0000000000..7a398543b3--- /dev/null+++ b/core/spec/serializers/spree/events/post_category_serializer_spec.rb@@ -0,0 +1,27 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::PostCategorySerializer do+ let(:store) { create(:store) }+ let(:post_category) { create(:post_category, store: store, title: 'News') }++ subject { described_class.serialize(post_category) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(post_category.id)+ expect(subject[:title]).to eq('News')+ expect(subject[:slug]).to eq(post_category.slug)+ end++ it 'includes store_id' do+ expect(subject[:store_id]).to eq(store.id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/post_serializer_spec.rb b/core/spec/serializers/spree/events/post_serializer_spec.rbnew file mode 100644index 0000000000..2d24a8d722--- /dev/null+++ b/core/spec/serializers/spree/events/post_serializer_spec.rb@@ -0,0 +1,51 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::PostSerializer do+ let(:store) { create(:store) }+ let(:post_category) { create(:post_category, store: store) }+ let(:author) { create(:admin_user) }+ let(:post) do+ create(:post,+ store: store,+ post_category: post_category,+ author: author,+ title: 'Test Post',+ published_at: Time.current)+ end++ subject { described_class.serialize(post) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(post.id)+ expect(subject[:title]).to eq('Test Post')+ expect(subject[:slug]).to eq(post.slug)+ end++ it 'includes meta fields' do+ expect(subject).to have_key(:meta_title)+ expect(subject).to have_key(:meta_description)+ end++ it 'includes published_at' do+ expect(subject[:published_at]).to be_present+ end++ it 'includes deleted_at' do+ expect(subject).to have_key(:deleted_at)+ end++ it 'includes foreign keys' do+ expect(subject[:author_id]).to eq(author.id)+ expect(subject[:post_category_id]).to eq(post_category.id)+ expect(subject[:store_id]).to eq(store.id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/price_serializer_spec.rb b/core/spec/serializers/spree/events/price_serializer_spec.rbnew file mode 100644index 0000000000..13e24a03ae--- /dev/null+++ b/core/spec/serializers/spree/events/price_serializer_spec.rb@@ -0,0 +1,35 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::PriceSerializer do+ let(:variant) { create(:variant) }+ let(:price) { variant.prices.first }++ subject { described_class.serialize(price) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(price.id)+ end++ it 'includes amount fields' do+ expect(subject[:amount]).to be_present+ expect(subject).to have_key(:compare_at_amount)+ expect(subject[:currency]).to eq(price.currency)+ end++ it 'includes variant_id' do+ expect(subject[:variant_id]).to eq(variant.id)+ end++ it 'includes deleted_at' do+ expect(subject).to have_key(:deleted_at)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/product_serializer_spec.rb b/core/spec/serializers/spree/events/product_serializer_spec.rbnew file mode 100644index 0000000000..bbe9d87a28--- /dev/null+++ b/core/spec/serializers/spree/events/product_serializer_spec.rb@@ -0,0 +1,48 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::ProductSerializer do+ let(:store) { create(:store) }+ let(:product) do+ create(:product,+ name: 'Test Product',+ status: 'active',+ available_on: Time.zone.parse('2024-01-01 00:00:00'),+ stores: [store])+ end++ subject { described_class.serialize(product) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(product.id)+ expect(subject[:name]).to eq('Test Product')+ expect(subject[:slug]).to eq(product.slug)+ end++ it 'includes status as string' do+ expect(subject[:status]).to eq('active')+ end++ it 'includes availability timestamps' do+ expect(subject[:available_on]).to eq('2024-01-01T00:00:00Z')+ expect(subject).to have_key(:discontinue_on)+ end++ it 'includes store_ids' do+ expect(subject[:store_ids]).to eq([store.id])+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end++ it 'does not include associations' do+ expect(subject).not_to have_key(:variants)+ expect(subject).not_to have_key(:images)+ expect(subject).not_to have_key(:taxons)+ end+ end+enddiff --git a/core/spec/serializers/spree/events/promotion_serializer_spec.rb b/core/spec/serializers/spree/events/promotion_serializer_spec.rbnew file mode 100644index 0000000000..2a088e71a9--- /dev/null+++ b/core/spec/serializers/spree/events/promotion_serializer_spec.rb@@ -0,0 +1,62 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::PromotionSerializer do+ let(:promotion) do+ create(:promotion,+ name: 'Test Promotion',+ code: 'SAVE10',+ starts_at: 1.day.ago,+ expires_at: 1.month.from_now)+ end++ subject { described_class.serialize(promotion) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(promotion.id)+ expect(subject[:name]).to eq('Test Promotion')+ end++ it 'includes code' do+ expect(subject).to have_key(:code)+ end++ it 'includes description' do+ expect(subject).to have_key(:description)+ end++ it 'includes type and kind' do+ expect(subject).to have_key(:type)+ expect(subject).to have_key(:kind)+ end++ it 'includes policy settings' do+ expect(subject).to have_key(:match_policy)+ expect(subject).to have_key(:usage_limit)+ expect(subject).to have_key(:advertise)+ expect(subject).to have_key(:path)+ end++ it 'includes multi-code settings' do+ expect(subject).to have_key(:multi_codes)+ expect(subject).to have_key(:code_prefix)+ expect(subject).to have_key(:number_of_codes)+ end++ it 'includes date range' do+ expect(subject[:starts_at]).to be_present+ expect(subject[:expires_at]).to be_present+ end++ it 'includes promotion_category_id' do+ expect(subject).to have_key(:promotion_category_id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/refund_serializer_spec.rb b/core/spec/serializers/spree/events/refund_serializer_spec.rbnew file mode 100644index 0000000000..d6a14733c4--- /dev/null+++ b/core/spec/serializers/spree/events/refund_serializer_spec.rb@@ -0,0 +1,36 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::RefundSerializer do+ let(:payment) { create(:payment, state: 'completed', amount: 100) }+ let(:refund) { create(:refund, payment: payment, amount: 10) }++ subject { described_class.serialize(refund) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(refund.id)+ end++ it 'includes amount' do+ expect(subject[:amount]).to be_present+ end++ it 'includes transaction_id' do+ expect(subject).to have_key(:transaction_id)+ end++ it 'includes foreign keys' do+ expect(subject[:payment_id]).to eq(refund.payment_id)+ expect(subject).to have_key(:refund_reason_id)+ expect(subject).to have_key(:reimbursement_id)+ expect(subject).to have_key(:refunder_id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/reimbursement_serializer_spec.rb b/core/spec/serializers/spree/events/reimbursement_serializer_spec.rbnew file mode 100644index 0000000000..1a4028a2af--- /dev/null+++ b/core/spec/serializers/spree/events/reimbursement_serializer_spec.rb@@ -0,0 +1,34 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::ReimbursementSerializer do+ let(:reimbursement) { create(:reimbursement) }++ subject { described_class.serialize(reimbursement) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(reimbursement.id)+ expect(subject[:number]).to eq(reimbursement.number)+ end++ it 'includes reimbursement_status' do+ expect(subject[:reimbursement_status]).to be_present+ end++ it 'includes total' do+ expect(subject).to have_key(:total)+ end++ it 'includes foreign keys' do+ expect(subject[:order_id]).to eq(reimbursement.order_id)+ expect(subject[:customer_return_id]).to eq(reimbursement.customer_return_id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/return_authorization_serializer_spec.rb b/core/spec/serializers/spree/events/return_authorization_serializer_spec.rbnew file mode 100644index 0000000000..95329f5368--- /dev/null+++ b/core/spec/serializers/spree/events/return_authorization_serializer_spec.rb@@ -0,0 +1,35 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::ReturnAuthorizationSerializer do+ let(:return_authorization) { create(:return_authorization) }++ subject { described_class.serialize(return_authorization) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(return_authorization.id)+ expect(subject[:number]).to eq(return_authorization.number)+ end++ it 'includes state as string' do+ expect(subject[:state]).to be_a(String)+ end++ it 'includes foreign keys' do+ expect(subject[:order_id]).to eq(return_authorization.order_id)+ expect(subject[:stock_location_id]).to eq(return_authorization.stock_location_id)+ expect(subject).to have_key(:return_authorization_reason_id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end++ it 'does not include associations' do+ expect(subject).not_to have_key(:return_items)+ end+ end+enddiff --git a/core/spec/serializers/spree/events/return_item_serializer_spec.rb b/core/spec/serializers/spree/events/return_item_serializer_spec.rbnew file mode 100644index 0000000000..15467cb855--- /dev/null+++ b/core/spec/serializers/spree/events/return_item_serializer_spec.rb@@ -0,0 +1,39 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::ReturnItemSerializer do+ let(:return_item) { create(:return_item) }++ subject { described_class.serialize(return_item) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(return_item.id)+ end++ it 'includes status fields' do+ expect(subject[:reception_status]).to be_present+ expect(subject[:acceptance_status]).to be_present+ end++ it 'includes amount fields' do+ expect(subject).to have_key(:pre_tax_amount)+ expect(subject).to have_key(:included_tax_total)+ expect(subject).to have_key(:additional_tax_total)+ end++ it 'includes foreign keys' do+ expect(subject[:inventory_unit_id]).to eq(return_item.inventory_unit_id)+ expect(subject[:return_authorization_id]).to eq(return_item.return_authorization_id)+ expect(subject).to have_key(:customer_return_id)+ expect(subject).to have_key(:reimbursement_id)+ expect(subject).to have_key(:exchange_variant_id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/shipment_serializer_spec.rb b/core/spec/serializers/spree/events/shipment_serializer_spec.rbnew file mode 100644index 0000000000..c730b2afd5--- /dev/null+++ b/core/spec/serializers/spree/events/shipment_serializer_spec.rb@@ -0,0 +1,44 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::ShipmentSerializer do+ let(:shipment) { create(:shipment) }++ subject { described_class.serialize(shipment) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(shipment.id)+ expect(subject[:number]).to eq(shipment.number)+ end++ it 'includes state as string' do+ expect(subject[:state]).to be_a(String)+ end++ it 'includes tracking' do+ expect(subject).to have_key(:tracking)+ end++ it 'includes cost' do+ expect(subject).to have_key(:cost)+ end++ it 'includes foreign keys' do+ expect(subject[:order_id]).to eq(shipment.order_id)+ expect(subject[:stock_location_id]).to eq(shipment.stock_location_id)+ end++ it 'includes timestamps' do+ expect(subject).to have_key(:shipped_at)+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end++ it 'does not include associations' do+ expect(subject).not_to have_key(:inventory_units)+ expect(subject).not_to have_key(:shipping_rates)+ end+ end+enddiff --git a/core/spec/serializers/spree/events/stock_item_serializer_spec.rb b/core/spec/serializers/spree/events/stock_item_serializer_spec.rbnew file mode 100644index 0000000000..4dc94fbb8d--- /dev/null+++ b/core/spec/serializers/spree/events/stock_item_serializer_spec.rb@@ -0,0 +1,39 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::StockItemSerializer do+ let(:stock_location) { create(:stock_location) }+ let(:variant) { create(:variant) }+ let(:stock_item) { variant.stock_items.first || create(:stock_item, variant: variant, stock_location: stock_location) }++ subject { described_class.serialize(stock_item) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(stock_item.id)+ end++ it 'includes count_on_hand' do+ expect(subject).to have_key(:count_on_hand)+ end++ it 'includes backorderable' do+ expect(subject).to have_key(:backorderable)+ end++ it 'includes foreign keys' do+ expect(subject[:stock_location_id]).to eq(stock_item.stock_location_id)+ expect(subject[:variant_id]).to eq(stock_item.variant_id)+ end++ it 'includes deleted_at' do+ expect(subject).to have_key(:deleted_at)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/stock_movement_serializer_spec.rb b/core/spec/serializers/spree/events/stock_movement_serializer_spec.rbnew file mode 100644index 0000000000..9d60e53fa5--- /dev/null+++ b/core/spec/serializers/spree/events/stock_movement_serializer_spec.rb@@ -0,0 +1,40 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::StockMovementSerializer do+ let(:stock_location) { create(:stock_location) }+ let(:variant) { create(:variant) }+ let(:stock_item) { variant.stock_items.first || create(:stock_item, variant: variant, stock_location: stock_location) }+ let(:stock_movement) { create(:stock_movement, stock_item: stock_item, quantity: 5) }++ subject { described_class.serialize(stock_movement) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(stock_movement.id)+ end++ it 'includes quantity' do+ expect(subject[:quantity]).to eq(5)+ end++ it 'includes action' do+ expect(subject).to have_key(:action)+ end++ it 'includes originator polymorphic reference' do+ expect(subject).to have_key(:originator_type)+ expect(subject).to have_key(:originator_id)+ end++ it 'includes stock_item_id' do+ expect(subject[:stock_item_id]).to eq(stock_item.id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/stock_transfer_serializer_spec.rb b/core/spec/serializers/spree/events/stock_transfer_serializer_spec.rbnew file mode 100644index 0000000000..5c2e2904b1--- /dev/null+++ b/core/spec/serializers/spree/events/stock_transfer_serializer_spec.rb@@ -0,0 +1,41 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::StockTransferSerializer do+ let(:source_location) { create(:stock_location, name: 'Source') }+ let(:destination_location) { create(:stock_location, name: 'Destination') }+ let(:stock_transfer) do+ create(:stock_transfer,+ source_location: source_location,+ destination_location: destination_location,+ reference: 'REF123')+ end++ subject { described_class.serialize(stock_transfer) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(stock_transfer.id)+ expect(subject[:number]).to eq(stock_transfer.number)+ end++ it 'includes type' do+ expect(subject).to have_key(:type)+ end++ it 'includes reference' do+ expect(subject[:reference]).to eq('REF123')+ end++ it 'includes location foreign keys' do+ expect(subject[:source_location_id]).to eq(source_location.id)+ expect(subject[:destination_location_id]).to eq(destination_location.id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/store_credit_serializer_spec.rb b/core/spec/serializers/spree/events/store_credit_serializer_spec.rbnew file mode 100644index 0000000000..baf3c6a6d5--- /dev/null+++ b/core/spec/serializers/spree/events/store_credit_serializer_spec.rb@@ -0,0 +1,64 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::StoreCreditSerializer do+ let(:store) { create(:store) }+ let(:user) { create(:user) }+ let(:admin_user) { create(:admin_user) }+ let(:store_credit) do+ create(:store_credit,+ user: user,+ created_by: admin_user,+ amount: 100.00,+ currency: 'USD',+ store: store)+ end++ subject { described_class.serialize(store_credit) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(store_credit.id)+ end++ it 'includes amount fields' do+ expect(subject[:amount]).to eq(100.00)+ expect(subject).to have_key(:amount_used)+ expect(subject).to have_key(:amount_authorized)+ expect(subject[:currency]).to eq('USD')+ end++ it 'includes memo' do+ expect(subject).to have_key(:memo)+ end++ it 'includes user foreign keys' do+ expect(subject[:user_id]).to eq(user.id)+ expect(subject[:created_by_id]).to eq(admin_user.id)+ end++ it 'includes category and type ids' do+ expect(subject).to have_key(:category_id)+ expect(subject).to have_key(:type_id)+ end++ it 'includes store_id' do+ expect(subject[:store_id]).to eq(store.id)+ end++ it 'includes originator polymorphic reference' do+ expect(subject).to have_key(:originator_type)+ expect(subject).to have_key(:originator_id)+ end++ it 'includes deleted_at' do+ expect(subject).to have_key(:deleted_at)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/user_serializer_spec.rb b/core/spec/serializers/spree/events/user_serializer_spec.rbnew file mode 100644index 0000000000..da0c5780b8--- /dev/null+++ b/core/spec/serializers/spree/events/user_serializer_spec.rb@@ -0,0 +1,27 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::UserSerializer do+ let(:user) { create(:user, email: '[email protected]') }++ subject { described_class.serialize(user) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(user.id)+ expect(subject[:email]).to eq('[email protected]')+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end++ it 'does not include sensitive data' do+ expect(subject).not_to have_key(:encrypted_password)+ expect(subject).not_to have_key(:password)+ expect(subject).not_to have_key(:spree_api_key)+ end+ end+enddiff --git a/core/spec/serializers/spree/events/variant_serializer_spec.rb b/core/spec/serializers/spree/events/variant_serializer_spec.rbnew file mode 100644index 0000000000..e6d26ab3ac--- /dev/null+++ b/core/spec/serializers/spree/events/variant_serializer_spec.rb@@ -0,0 +1,65 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::VariantSerializer do+ let(:product) { create(:product) }+ let(:variant) { create(:variant, product: product, sku: 'TEST-SKU-001') }++ subject { described_class.serialize(variant) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(variant.id)+ expect(subject[:sku]).to eq('TEST-SKU-001')+ end++ it 'includes barcode' do+ expect(subject).to have_key(:barcode)+ end++ it 'includes is_master' do+ expect(subject[:is_master]).to eq(variant.is_master)+ end++ it 'includes position' do+ expect(subject).to have_key(:position)+ end++ it 'includes dimensions' do+ expect(subject).to have_key(:weight)+ expect(subject).to have_key(:height)+ expect(subject).to have_key(:width)+ expect(subject).to have_key(:depth)+ expect(subject).to have_key(:weight_unit)+ expect(subject).to have_key(:dimensions_unit)+ end++ it 'includes cost fields' do+ expect(subject).to have_key(:cost_price)+ expect(subject).to have_key(:cost_currency)+ end++ it 'includes track_inventory' do+ expect(subject).to have_key(:track_inventory)+ end++ it 'includes foreign keys' do+ expect(subject[:product_id]).to eq(product.id)+ expect(subject).to have_key(:tax_category_id)+ end++ it 'includes discontinue_on' do+ expect(subject).to have_key(:discontinue_on)+ end++ it 'includes deleted_at' do+ expect(subject).to have_key(:deleted_at)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/wished_item_serializer_spec.rb b/core/spec/serializers/spree/events/wished_item_serializer_spec.rbnew file mode 100644index 0000000000..42f83b2c2c--- /dev/null+++ b/core/spec/serializers/spree/events/wished_item_serializer_spec.rb@@ -0,0 +1,32 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::WishedItemSerializer do+ let(:user) { create(:user) }+ let(:wishlist) { create(:wishlist, user: user) }+ let(:variant) { create(:variant) }+ let(:wished_item) { create(:wished_item, wishlist: wishlist, variant: variant, quantity: 2) }++ subject { described_class.serialize(wished_item) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(wished_item.id)+ end++ it 'includes quantity' do+ expect(subject[:quantity]).to eq(2)+ end++ it 'includes foreign keys' do+ expect(subject[:variant_id]).to eq(variant.id)+ expect(subject[:wishlist_id]).to eq(wishlist.id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end+ end+enddiff --git a/core/spec/serializers/spree/events/wishlist_serializer_spec.rb b/core/spec/serializers/spree/events/wishlist_serializer_spec.rbnew file mode 100644index 0000000000..dbd2c73d18--- /dev/null+++ b/core/spec/serializers/spree/events/wishlist_serializer_spec.rb@@ -0,0 +1,44 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::Events::WishlistSerializer do+ let(:store) { create(:store) }+ let(:user) { create(:user) }+ let(:wishlist) do+ create(:wishlist,+ user: user,+ store: store,+ name: 'My Wishlist',+ is_private: true,+ is_default: false)+ end++ subject { described_class.serialize(wishlist) }++ describe '#as_json' do+ it 'includes identity attributes' do+ expect(subject[:id]).to eq(wishlist.id)+ expect(subject[:name]).to eq('My Wishlist')+ end++ it 'includes privacy settings' do+ expect(subject[:is_private]).to eq(true)+ expect(subject[:is_default]).to eq(false)+ end++ it 'includes foreign keys' do+ expect(subject[:user_id]).to eq(user.id)+ expect(subject[:store_id]).to eq(store.id)+ end++ it 'includes timestamps' do+ expect(subject[:created_at]).to be_present+ expect(subject[:updated_at]).to be_present+ end++ it 'does not include token' do+ expect(subject).not_to have_key(:token)+ end+ end+end