mirror of
http://ghproxy.cn/https://github.com/multunus/onemdm-server
synced 2025-12-06 02:04:57 +00:00
Add heartbeat model, next_heartbeat_time and update_heartbeat_time on device registration
This commit is contained in:
6
spec/factories/heartbeats.rb
Normal file
6
spec/factories/heartbeats.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :heartbeat do
|
||||
association :device
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Device, type: :model do
|
||||
let(:device) { create(:device) }
|
||||
let!(:device) { create(:device) }
|
||||
|
||||
it { should validate_presence_of :unique_id }
|
||||
it { should validate_presence_of :model }
|
||||
@@ -12,4 +12,14 @@ RSpec.describe Device, type: :model do
|
||||
expect(device.access_token).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "heartbeat" do
|
||||
it "last heartbeat time to updated with updated_at time" do
|
||||
expect(Device.last.last_heartbeat_recd_time).not_to be_nil
|
||||
end
|
||||
|
||||
it "next hearbeat time" do
|
||||
expect(Device.last.next_heartbeat_time).not_to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
15
spec/models/heartbeat_spec.rb
Normal file
15
spec/models/heartbeat_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Heartbeat, type: :model do
|
||||
let(:heartbeat){create(:heartbeat)}
|
||||
|
||||
it "update device heartbeat details" do
|
||||
device = heartbeat.device
|
||||
expect(device.last_heartbeat_recd_time).to eq(heartbeat.created_at)
|
||||
expect(device.heartbeats_count).to eq(1)
|
||||
end
|
||||
|
||||
it "next heartbeat" do
|
||||
expect(heartbeat.next_heartbeat_time).not_to be_nil
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user