Class: Xplenty::Kensa::ProvisionResponseCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/xplenty/kensa/check.rb

Instance Attribute Summary

Attributes inherited from Check

#data, #screen

Instance Method Summary collapse

Methods inherited from Check

#call, #check, #env, #error, #initialize, #run, #test, #to_proc, #url

Constructor Details

This class inherits a constructor from Xplenty::Kensa::Check

Instance Method Details

#call!Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/xplenty/kensa/check.rb', line 168

def call!
  response = data[:provision_response]
  test "response"

  check "contains an id" do
    response.is_a?(Hash) && response.has_key?("id")
  end

  screen.message " (id #{response['id']})"

  if response.has_key?("config")
    test "config data"
    check "is a hash" do
      response["config"].is_a?(Hash)
    end

    check "all config keys were previously defined in the manifest" do
      response["config"].keys.each do |key|
        error "#{key} is not in the manifest" unless data["api"]["config_vars"].include?(key)
      end
      true
    end

    check "all keys in the manifest are present" do
      difference = data['api']['config_vars'] - response['config'].keys 
      unless difference.empty?
        verb = (difference.size == 1) ? "is" : "are"
        error "#{difference.join(', ')} #{verb} missing from the manifest"
      end
      true
    end

    check "all config values are strings" do
      response["config"].each do |k, v|
        if v.is_a?(String)
          true
        else
          error "the key #{k} doesn't contain a string (#{v.inspect})"
        end
      end
    end

    check "URL configs vars" do
      response["config"].each do |key, value|
        next unless key =~ /_URL$/
        begin
          uri = URI.parse(value)
          error "#{value} is not a valid URI - missing host" unless uri.host
          error "#{value} is not a valid URI - missing scheme" unless uri.scheme
          error "#{value} is not a valid URI - pointing to localhost" if env == 'production' && uri.host == 'localhost'
        rescue URI::Error
          error "#{value} is not a valid URI"
        end
      end
    end

  end
end