Tests for mark_as_seen

pull/384/head
Rick Carlino 2017-08-08 08:01:32 -05:00
parent 32fcc96166
commit 4a9ec3fb67
1 changed files with 20 additions and 1 deletions

View File

@ -4,7 +4,13 @@ describe Api::PointsController do
include Devise::Test::ControllerHelpers
describe '#index' do
let(:device) { FactoryGirl.create(:device) }
let(:user) { FactoryGirl.create(:user, device: device) }
let(:user) do
FactoryGirl.create(:user, device: device, password: "password123")
end
let(:auth_token) do
Auth::CreateToken
.run!(email: user.email, password: "password123")[:token].encoded
end
it 'lists points' do
sign_in user
@ -56,5 +62,18 @@ describe Api::PointsController do
expect(response.status).to eq(426)
expect(json[:error]).to include("Upgrade to latest FarmBot OS")
end
it "marks device as seen when they download points" do
old_last_seen = user.device.last_seen
ua = "FARMBOTOS/9.8.7 (RPI3) RPI3 (6.5.4)"
allow(request).to receive(:user_agent).and_return(ua)
request.env["HTTP_USER_AGENT"] = ua
request.headers["Authorization"] = "bearer #{auth_token}"
FactoryGirl.create_list(:point, 1, device: device)
get :index
new_last_seen = user.device.reload.last_seen
expect(response.status).to eq(200)
expect(new_last_seen).not_to eq(old_last_seen)
end
end
end