Add test cases and fix possible logic error in conditional version handler?

pull/553/head
Rick Carlino 2017-12-06 08:12:14 -06:00
parent fefc7526fc
commit 704394f9ec
4 changed files with 17 additions and 3 deletions

View File

@ -16,7 +16,7 @@ class SessionToken < AbstractJwtToken
EXPIRY = 40.days
VHOST = ENV.fetch("MQTT_VHOST") { "/" }
# If version <= this, you can't just fast forward to the latest FBOS version.
FBOS_CUTOFF = Gem::Version.new("5.0.8")
FBOS_CUTOFF = Gem::Version.new("5.0.6")
# If you have a really, really old FBOS
OLD_OS_URL = "https://api.github.com/repos/farmbot/farmbot_os/releases/8772352"
def self.issue_to(user,

View File

@ -10,7 +10,7 @@ unless Rails.env == "production"
DATE_RANGE_LO = 1..3
DATE_RANGE_HI = 3..8
ENV['MQTT_HOST'] = "blooper.io"
ENV['OS_UPDATE_SERVER'] = "http://blah.com"
ENV['OS_UPDATE_SERVER'] = "http://non_legacy_update_url.com"
Point.destroy_all
Device.destroy_all
User.destroy_all

View File

@ -36,6 +36,20 @@ describe SessionToken do
fbos_version: Gem::Version.new("9.9.9"))
end
it 'conditionally sets `os_update_server`' do
test_case = -> (ver) do
SessionToken
.issue_to(user, fbos_version: Gem::Version.new(ver))
.unencoded[:os_update_server]
end
expect(test_case["0.0.0"]).to eq(SessionToken::OLD_OS_URL)
expect(test_case["5.0.6"]).to eq(SessionToken::OLD_OS_URL)
expect(test_case["5.0.7"]).to eq(SessionToken::OS_RELEASE)
expect(test_case["5.0.8"]).to eq(SessionToken::OS_RELEASE)
expect(test_case["5.1.0"]).to eq(SessionToken::OS_RELEASE)
end
it "doesn't honor expired tokens" do
user.update_attributes!(confirmed_at: Time.now)
token = SessionToken.issue_to(user, iat: 000,

View File

@ -1,5 +1,5 @@
ENV['MQTT_HOST'] = "blooper.io"
ENV['OS_UPDATE_SERVER'] = "http://blah.com"
ENV['OS_UPDATE_SERVER'] = "http://non_legacy_update_url.com"
require 'simplecov'
#Ignore anything with the word 'spec' in it. No need to test your tests.
SimpleCov.start do