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 specs for MenuItemSerializer and CmsSectionSerializer (#11278)

Virginia Nguyenb167bc76d14d
diff --git a/api/spec/fixtures/files/icon_256x256.jpg b/api/spec/fixtures/files/icon_256x256.jpg
new file mode 100644
index 0000000000..2edee4a6a3
Binary files /dev/null and b/api/spec/fixtures/files/icon_256x256.jpg differ
diff --git a/api/spec/serializers/spree/v2/storefront/cms_section_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/cms_section_serializer_spec.rb
new file mode 100644
index 0000000000..7e6d6aa491
--- /dev/null
+++ b/api/spec/serializers/spree/v2/storefront/cms_section_serializer_spec.rb
@@ -0,0 +1,109 @@
+require 'spec_helper'
+
+describe Spree::V2::Storefront::CmsSectionSerializer do
+ subject { described_class.new(cms_section) }
+
+ let(:cms_section) { create(:cms_section) }
+
+ shared_examples 'returns proper hash' do
+ it { expect(subject.serializable_hash).to be_kind_of(Hash) }
+
+ it do
+ expect(subject.serializable_hash).to eq(
+ {
+ data: {
+ id: cms_section.id.to_s,
+ type: :cms_section,
+ attributes: {
+ name: cms_section.name,
+ content: cms_section.content,
+ settings: cms_section.settings,
+ link: cms_section.link,
+ fit: cms_section.fit,
+ type: cms_section.type,
+ position: cms_section.position,
+ img_one_sm: cms_section.img_one_sm,
+ img_one_md: cms_section.img_one_md,
+ img_one_lg: cms_section.img_one_lg,
+ img_one_xl: cms_section.img_one_xl,
+ img_two_sm: cms_section.img_two_sm,
+ img_two_md: cms_section.img_two_md,
+ img_two_lg: cms_section.img_two_lg,
+ img_two_xl: cms_section.img_two_xl,
+ img_three_sm: cms_section.img_three_sm,
+ img_three_md: cms_section.img_three_md,
+ img_three_lg: cms_section.img_three_lg,
+ img_three_xl: cms_section.img_three_xl,
+ is_fullscreen: false
+ },
+ relationships: {
+ linked_resource: {
+ data: cms_section.linked_resource
+ }
+ }
+ }
+ }
+ )
+ end
+ end
+
+ context 'cms_hero_image_section' do
+ let!(:store) { create(:store) }
+ let!(:homepage) { create(:cms_homepage, store: store) }
+ let!(:cms_section) do
+ section = create(:cms_hero_image_section, cms_page: homepage)
+ section.image_one.attach(io: file, filename: 't-shirt.png')
+ section
+ end
+ let(:file) { File.open(file_fixture('icon_256x256.jpg')) }
+
+ it_behaves_like 'returns proper hash'
+ end
+
+ context 'cms_featured_article_section' do
+ let(:homepage) { create(:cms_homepage) }
+ let(:cms_section) { create(:cms_featured_article_section, name: 'Test', linked_resource_type: 'Spree::Taxon', cms_page: homepage) }
+
+ it_behaves_like 'returns proper hash'
+ end
+
+ context 'cms_side_by_side_images_section' do
+ let!(:store) { create(:store) }
+ let!(:homepage) { create(:cms_homepage, store: store) }
+ let!(:cms_section) do
+ section = create(:cms_side_by_side_images_section, cms_page: homepage)
+ section.image_one.attach(io: file, filename: 't-shirt.png')
+ section
+ end
+ let(:file) { File.open(file_fixture('icon_256x256.jpg')) }
+
+ it_behaves_like 'returns proper hash'
+ end
+
+ context 'cms_image_gallery_section' do
+ let!(:store) { create(:store) }
+ let!(:homepage) { create(:cms_homepage, store: store) }
+ let!(:cms_section) do
+ section = create(:cms_image_gallery_section, cms_page: homepage)
+ section.image_one.attach(io: file, filename: 't-shirt.png')
+ section
+ end
+ let(:file) { File.open(file_fixture('icon_256x256.jpg')) }
+
+ it_behaves_like 'returns proper hash'
+ end
+
+ context 'cms_product_carousel_section' do
+ let(:homepage) { create(:cms_homepage) }
+ let(:cms_section) { create(:cms_product_carousel_section, name: 'Test', linked_resource_type: 'Spree::Taxon', cms_page: homepage) }
+
+ it_behaves_like 'returns proper hash'
+ end
+
+ context 'cms_rich_text_content_section' do
+ let(:homepage) { create(:cms_homepage) }
+ let(:cms_section) { create(:cms_rich_text_content_section, cms_page: homepage) }
+
+ it_behaves_like 'returns proper hash'
+ end
+end
diff --git a/api/spec/serializers/spree/v2/storefront/menu_item_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/menu_item_serializer_spec.rb
new file mode 100644
index 0000000000..bf7b8087ba
--- /dev/null
+++ b/api/spec/serializers/spree/v2/storefront/menu_item_serializer_spec.rb
@@ -0,0 +1,72 @@
+require 'spec_helper'
+
+describe Spree::V2::Storefront::MenuItemSerializer do
+ subject { described_class.new(menu_item) }
+
+ let(:menu) { create(:menu) }
+ let(:menu_item) { create(:menu_item, menu: menu, linked_resource: create(:taxon)) }
+ let!(:children) { create(:menu_item, parent_id: menu_item.id, menu: menu) }
+
+ it { expect(subject.serializable_hash).to be_kind_of(Hash) }
+
+ it do
+ expect(subject.serializable_hash).to eq(
+ {
+ data: {
+ id: menu_item.id.to_s,
+ type: :menu_item,
+ attributes: {
+ code: menu_item.code,
+ name: menu_item.name,
+ subtitle: menu_item.subtitle,
+ link: menu_item.link,
+ new_window: menu_item.new_window,
+ lft: menu_item.lft,
+ rgt: menu_item.rgt,
+ depth: menu_item.depth,
+ is_container: false,
+ is_root: false,
+ is_child: true,
+ destination: menu_item.destination,
+ is_leaf: true,
+ item_type: menu_item.item_type
+ },
+ relationships: {
+ icon: {
+ data: {
+ id: menu_item.icon.id.to_s,
+ type: :icon
+ }
+ },
+ menu: {
+ data: {
+ id: menu_item.menu.id.to_s,
+ type: :menu
+ }
+ },
+ parent: {
+ data: {
+ id: menu_item.menu.root.id.to_s,
+ type: :menu_item
+ }
+ },
+ linked_resource: {
+ data: {
+ id: menu_item.linked_resource.id.to_s,
+ type: :taxon
+ }
+ },
+ children: {
+ data: [
+ {
+ id: menu_item.children.first.id.to_s,
+ type: :menu_item
+ }
+ ]
+ }
+ }
+ }
+ }
+ )
+ end
+end