Sha256: d4c7b5253a61aebd6832fc0b83397450461caaee71c7e74a9cd01028d91fc204

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

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

shared_context 'with 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'
        JSON_COLLECTION_WRAPPER = 'Products'
      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'].of(Test::Category)
        attribute :designer, Test::ProductDesigner
      end
    end

    def register_mapper(mapper_sym, mapper)
      return if Fortnox::API::Registry.key? mapper_sym
      Fortnox::API::Registry.register(mapper_sym, mapper)
    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.8.2 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.8.1 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.8.0 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.7.2 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.7.1 spec/fortnox/api/mappers/contexts/json_conversion.rb
fortnox-api-0.7.0 spec/fortnox/api/mappers/contexts/json_conversion.rb