Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Add wishlist serializer specs to API Storefront.

Matthew Kennedy538d584e8d80
diff --git a/api/app/serializers/spree/v2/storefront/wished_variant_serializer.rb b/api/app/serializers/spree/v2/storefront/wished_variant_serializer.rb
index 26c2348b0b..fc00bd4bc9 100644
--- a/api/app/serializers/spree/v2/storefront/wished_variant_serializer.rb
+++ b/api/app/serializers/spree/v2/storefront/wished_variant_serializer.rb
@@ -15,11 +15,11 @@ module Spree
end
attribute :display_price do |wished_variant, params|
- wished_variant.display_price(currency: params[:currency])
+ wished_variant.display_price(currency: params[:currency]).to_s
end
attribute :display_total do |wished_variant, params|
- wished_variant.display_total(currency: params[:currency])
+ wished_variant.display_total(currency: params[:currency]).to_s
end
belongs_to :variant
diff --git a/api/spec/serializers/spree/api/v2/storefront/wished_variant_serializer_spec.rb b/api/spec/serializers/spree/api/v2/storefront/wished_variant_serializer_spec.rb
new file mode 100644
index 0000000000..c0de10fd25
--- /dev/null
+++ b/api/spec/serializers/spree/api/v2/storefront/wished_variant_serializer_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+describe Spree::V2::Storefront::WishedVariantSerializer do
+ subject { described_class.new(wished_variant, params: { currency: 'USD' }) }
+
+ let!(:wishlist) { create(:wishlist) }
+ let!(:wished_variant) { create(:wished_variant, wishlist: wishlist, variant: create(:variant), quantity: 5 ) }
+
+ it { expect(subject.serializable_hash).to be_kind_of(Hash) }
+
+ it do
+ expect(subject.serializable_hash).to eq(
+ {
+ data: {
+ id: wished_variant.id.to_s,
+ type: :wished_variant,
+ attributes: {
+ display_price: '$19.99',
+ display_total: '$99.95',
+ price: wished_variant.variant.price,
+ total: (wished_variant.variant.price * 5),
+ quantity: 5,
+ },
+ relationships: {
+ variant: {
+ data: {
+ id: wished_variant.variant.id.to_s,
+ type: :variant
+ }
+ },
+ wishlist: {
+ data: {
+ id: wishlist.id.to_s,
+ type: :wishlist
+ }
+ }
+ }
+ }
+ }
+ )
+ end
+end
diff --git a/api/spec/serializers/spree/api/v2/storefront/wishlist_serializer_spec.rb b/api/spec/serializers/spree/api/v2/storefront/wishlist_serializer_spec.rb
new file mode 100644
index 0000000000..e340ce1bba
--- /dev/null
+++ b/api/spec/serializers/spree/api/v2/storefront/wishlist_serializer_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+describe Spree::V2::Storefront::WishlistSerializer do
+ subject { described_class.new(wishlist) }
+
+ let!(:wishlist) { create(:wishlist) }
+ let!(:wished_variant) { create(:wished_variant, wishlist: wishlist, variant: create(:variant), quantity: 1 ) }
+
+ it { expect(subject.serializable_hash).to be_kind_of(Hash) }
+
+ it do
+ expect(subject.serializable_hash).to eq(
+ {
+ data: {
+ id: wishlist.id.to_s,
+ type: :wishlist,
+ attributes: {
+ name: wishlist.name,
+ token: wishlist.token,
+ is_private: wishlist.is_private,
+ is_default: wishlist.is_default
+ },
+ relationships: {
+ user: {
+ data:{
+ id: wishlist.user.id.to_s,
+ type: :user
+ }
+ },
+ wished_variants: {
+ data: [
+ {
+ id: wishlist.wished_variants.first.id.to_s,
+ type: :wished_variant
+ }
+ ]
+ }
+ }
+ }
+ }
+ )
+ end
+end