Sha256: 4ccf5ce5c882defd2cc8255aeffc79483169281106e33a237de5cd0ee9138253

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

require 'fortnox/api'
require 'fortnox/api/mappers'

shared_context 'JSON conversion' do
  before do
    module Test
      class BaseMapper
      end

      class CategoryMapper < BaseMapper
        KEY_MAP = { id: 'ID' }.freeze
      end

      class ProductDesignerMapper < BaseMapper
        KEY_MAP = { id: 'ID' }.freeze
      end

      class ProductMapper < BaseMapper
        KEY_MAP = {
          vat: 'VAT',
          url: '@url' # TODO: How to handle url attribute?
        }.freeze
        JSON_ENTITY_WRAPPER = 'Product'.freeze
        JSON_COLLECTION_WRAPPER = 'Products'.freeze
      end

      class Category < Fortnox::API::Model::Base
        attribute :name, 'strict.string'
        attribute :id, 'strict.string'
      end

      class ProductDesigner < Fortnox::API::Model::Base
        attribute :name, 'strict.string'
        attribute :id, 'strict.string'
      end

      class Product < Fortnox::API::Model::Base
        attribute :url, 'strict.string'
        attribute :name, 'strict.string'
        attribute :vat, 'strict.float'
        attribute :categories, Dry::Types['coercible.array'].member( Test::Category )
        attribute :designer, Test::ProductDesigner
      end
    end

    def register_mapper( mapper_sym, mapper )
      unless Fortnox::API::Registry.key? mapper_sym
        Fortnox::API::Registry.register( mapper_sym, mapper )
      end
    end

    register_mapper( :category, Test::CategoryMapper)
    register_mapper( :productdesigner, Test::ProductDesignerMapper )
    register_mapper( :product, Test::ProductMapper )
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fortnox-api-0.5.2 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.5.1 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.5.0 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.4.0 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.3.0 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.2.0 spec/fortnox/api/mappers/contexts/json_conversion.rb