mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add spec for CatalogItem serializer
This commit is contained in:
@@ -28,7 +28,7 @@ module DfcProvider
|
||||
def references
|
||||
{
|
||||
'@type' => '@id',
|
||||
'@id' => "/supplied_products/#{object.product_id}"
|
||||
'@id' => reference_id
|
||||
}
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@ module DfcProvider
|
||||
dfc_provider_routes.api_dfc_provider_enterprise_supplied_product_url(
|
||||
enterprise_id: object.product.supplier_id,
|
||||
id: object.product_id,
|
||||
host: root_url
|
||||
host: host
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe DfcProvider::CatalogItemSerializer do
|
||||
let!(:product) { create(:simple_product ) }
|
||||
let!(:variant) { product.variants.first }
|
||||
|
||||
subject { described_class.new(variant) }
|
||||
|
||||
describe '#id' do
|
||||
it 'returns the expected value' do
|
||||
expect(subject.id).to eq(
|
||||
DfcProvider::Engine.routes.url_helpers.api_dfc_provider_enterprise_catalog_item_url(
|
||||
enterprise_id: product.supplier_id,
|
||||
id: variant.id,
|
||||
host: 'http://test.host'
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#references' do
|
||||
it 'returns the expected value' do
|
||||
expect(subject.references).to eq(
|
||||
{
|
||||
"@id" =>
|
||||
DfcProvider::Engine.routes.url_helpers.api_dfc_provider_enterprise_supplied_product_url(
|
||||
enterprise_id: product.supplier_id,
|
||||
id: product.id,
|
||||
host: 'http://test.host'
|
||||
),
|
||||
"@type" => "@id"
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user