43 lines
1.3 KiB
Ruby
43 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'test_helper'
|
|
|
|
class ReadingsControllerTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
@reading = JSON.parse(File.read(Rails.root.join(*%w[test fixtures files 20220318165621-565ca662-a6dc-11ec-95a5-574e273d29ba])))
|
|
@signature = File.read(Rails.root.join(*%w[test fixtures files 20220318165621-565ca662-a6dc-11ec-95a5-574e273d29ba.sig])).split("\n").tap do |s|
|
|
s.pop
|
|
s.reverse!
|
|
s.pop
|
|
s.reverse!
|
|
end.join('')
|
|
end
|
|
|
|
test 'se puede probar la conexión' do
|
|
post readings_url, as: :json
|
|
|
|
assert_response :ok
|
|
end
|
|
|
|
test 'se pueden enviar lecturas' do
|
|
post readings_url, as: :json, headers: {
|
|
'X-Signature': @signature
|
|
}, params: @reading
|
|
|
|
assert_response :ok
|
|
assert_equal @reading['transaction_uuid'], response.body
|
|
assert (reading = Reading.find(response.body))
|
|
|
|
assert reading.raspberry
|
|
assert_equal @reading['controller_id'], reading.raspberry.name
|
|
assert_equal @reading['serial_number'], reading.raspberry.serial_number
|
|
|
|
assert_equal 1, reading.arduinos.count
|
|
assert_equal 2, reading.sensors.count
|
|
|
|
# XXX: Este JSON no se puede verificar porque hay espacios en el
|
|
# original que no llegaron con el envío a través de params
|
|
assert_not reading.verified
|
|
end
|
|
end
|