mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add specs for endpoint and serializers
This commit is contained in:
@@ -81,5 +81,27 @@ module Api
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching shopfronts data" do
|
||||
let!(:hub) {
|
||||
create(:distributor_enterprise, with_payment_and_shipping: true, name: 'Shopfront Test Hub')
|
||||
}
|
||||
let!(:producer) { create(:supplier_enterprise, name: 'Shopfront Test Producer') }
|
||||
let!(:category) { create(:taxon, name: 'Fruit') }
|
||||
let!(:product) { create(:product, supplier: producer, primary_taxon: category ) }
|
||||
let!(:relationship) { create(:enterprise_relationship, parent: hub, child: producer) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { Spree::User.anonymous! }
|
||||
end
|
||||
|
||||
it "returns data for an enterprise" do
|
||||
spree_get :shopfront, id: producer.id, format: :json
|
||||
|
||||
expect(json_response['name']).to eq 'Shopfront Test Producer'
|
||||
expect(json_response['hubs'][0]['name']).to eq 'Shopfront Test Hub'
|
||||
expect(json_response['supplied_taxons'][0]['name']).to eq 'Fruit'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Api::EnterpriseShopfrontListSerializer do
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
let(:serializer) {
|
||||
Api::EnterpriseShopfrontListSerializer.new enterprise
|
||||
}
|
||||
|
||||
it "serializes enterprise attributes" do
|
||||
expect(serializer.to_json).to match enterprise.name
|
||||
end
|
||||
|
||||
it "serializes shopfront path" do
|
||||
expect(serializer.to_json).to match enterprise_shop_path(enterprise)
|
||||
end
|
||||
|
||||
it "serializes icons" do
|
||||
expect(serializer.to_json).to match "map_005-hub.svg"
|
||||
end
|
||||
end
|
||||
50
spec/serializers/api/enterprise_shopfront_serializer_spec.rb
Normal file
50
spec/serializers/api/enterprise_shopfront_serializer_spec.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Api::EnterpriseShopfrontSerializer do
|
||||
let!(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
let!(:producer) { create(:supplier_enterprise) }
|
||||
let!(:relationship) { create(:enterprise_relationship, parent: hub, child: producer) }
|
||||
|
||||
let!(:taxon1) { create(:taxon, name: 'Meat') }
|
||||
let!(:taxon2) { create(:taxon, name: 'Veg') }
|
||||
let!(:product) { create(:product, supplier: producer, primary_taxon: taxon1, taxons: [taxon1, taxon2] ) }
|
||||
|
||||
let(:close_time) { 2.days.from_now }
|
||||
let!(:oc) { create(:simple_order_cycle, orders_close_at: close_time, distributors: [hub]) }
|
||||
|
||||
let!(:ex) {
|
||||
create(:exchange, order_cycle: oc, incoming: false,
|
||||
sender: producer, receiver: hub)
|
||||
}
|
||||
|
||||
let(:serializer) { Api::EnterpriseShopfrontSerializer.new hub }
|
||||
|
||||
before do
|
||||
ex.variants << product.variants.first
|
||||
end
|
||||
|
||||
it "serializes next order cycle close time" do
|
||||
expect(serializer.serializable_hash[:orders_close_at]).to match oc.orders_close_at
|
||||
end
|
||||
|
||||
it "serializes shipping method types" do
|
||||
expect(serializer.serializable_hash[:pickup]).to eq false
|
||||
expect(serializer.serializable_hash[:delivery]).to eq true
|
||||
end
|
||||
|
||||
it "serialises an array of hubs" do
|
||||
expect(serializer.serializable_hash[:hubs]).to be_a ActiveModel::ArraySerializer
|
||||
expect(serializer.serializable_hash[:hubs].to_json).to match hub.name
|
||||
end
|
||||
|
||||
it "serialises an array of producers" do
|
||||
expect(serializer.serializable_hash[:producers]).to be_a ActiveModel::ArraySerializer
|
||||
expect(serializer.serializable_hash[:producers].to_json).to match producer.name
|
||||
end
|
||||
|
||||
it "serialises taxons" do
|
||||
expect(serializer.serializable_hash[:taxons]).to be_a ActiveModel::ArraySerializer
|
||||
expect(serializer.serializable_hash[:taxons].to_json).to match 'Meat'
|
||||
expect(serializer.serializable_hash[:taxons].to_json).to match 'Veg'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user