Add spec for SuppliedProduct serializer

This commit is contained in:
François Turbelin
2020-11-25 14:38:46 +01:00
parent 4dc07d9872
commit 235a2574dc
4 changed files with 36 additions and 3 deletions

View File

@@ -18,7 +18,7 @@ module DfcProvider
def id
dfc_provider_routes.api_dfc_provider_enterprise_url(
id: object.id,
host: root_url
host: host
)
end

View File

@@ -28,7 +28,7 @@ module DfcProvider
def id
dfc_provider_routes.api_dfc_provider_person_url(
id: object.id,
host: root_url
host: host
)
end

View File

@@ -20,7 +20,7 @@ module DfcProvider
dfc_provider_routes.api_dfc_provider_enterprise_supplied_product_url(
enterprise_id: object.product.supplier_id,
id: object.id,
host: root_url
host: host
)
end

View File

@@ -0,0 +1,33 @@
# frozen_string_literal: true
require 'spec_helper'
describe DfcProvider::SuppliedProductSerializer 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_supplied_product_url(
enterprise_id: product.supplier_id,
id: variant.id,
host: 'http://test.host'
)
)
end
end
describe '#unit' do
it 'returns the rdfs label value' do
expect(subject.unit).to eq(
{
'@id' => '/unit/piece',
'rdfs:label' => 'piece'
}
)
end
end
end