require 'rails_helper'

module NovacastSDK
  module RSpec
    module Helpers
      def generate_path(template, params)
        path = template.sub('{format}','json')
        params.reduce(path) do |result, (key, type)|
          value = case type.downcase
                    when 'integer', 'number'
                      123456
                    when 'boolean'
                      true
                    else
                      'string'
                  end
          result.sub("{#{key}}", value)
        end
      end

      def expect_path_not_routable(path)
        expect(path).not_to be_routable
      end
    end

    def self.init
      ::RSpec.configure do |c|
        c.include Helpers
      end
    end

{{#apiInfo}}
{{#apis}}
  {{#operations}}
    class {{classname}}Paths
      def self.specs
      {{#operation}}
        ::RSpec.describe '{{httpMethod}} {{path}}', type: :routing do
          it 'is a valid endpoint' do
            path_params = {
            {{#pathParams}}
              :'{{paramName}}' => '{{dataType}}'{{#hasMore}},{{newline}}{{/hasMore}}
            {{/pathParams}}
            }
            expect_path_not_routable(:{{httpMethod}} => generate_path('{{#contextPath}}{{contextPath}}{{/contextPath}}{{path}}', path_params))
          end
        end
      {{/operation}}
      end
    end
  {{/operations}}
{{/apis}}
{{/apiInfo}}
  end
end

require 'rails_helper'

module NovacastSDK
  module RSpec
    module Helpers
      def generate_path(template, params)
        path = template.sub('{format}','json')
        params.reduce(path) do |result, (key, type)|
          value = case type.downcase
                    when 'integer', 'number'
                      123456
                    when 'boolean'
                      true
                    else
                      'string'
                  end
          result.sub("{#{key}}", value)
        end
      end

      def expect_path_routable(path)
        expect(path).to be_routable
      end
    end

{{#apiInfo}}
{{#apis}}
  {{#operations}}
    class {{classname}}Paths
      def self.specs
      {{#operation}}
        ::RSpec.describe '{{httpMethod}} {{path}}', type: :routing do
          it 'is a valid endpoint' do
            path_params = {
            {{#pathParams}}
              :'{{paramName}}' => '{{dataType}}'{{#hasMore}},{{newline}}{{/hasMore}}
            {{/pathParams}}
            }
            expect_path_routable(:{{httpMethod}} => generate_path('{{#contextPath}}{{contextPath}}{{/contextPath}}{{path}}', path_params))
          end
        end
      {{/operation}}
      end
    end
  {{/operations}}
{{/apis}}
{{/apiInfo}}
  end
end

RSpec.configure do |c|
  c.include NovacastSDK::RSpec::Helpers
end

Fix the wrongly named method to expect_path_routable
Fix the wrongly named method to expect_path_routable
