mirror of
http://ghproxy.cn/https://github.com/multunus/onemdm-server
synced 2025-12-06 02:04:57 +00:00
API for app usage tracking
This commit is contained in:
28
spec/controllers/app_usages_controller_spec.rb
Normal file
28
spec/controllers/app_usages_controller_spec.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AppUsagesController, type: :controller do
|
||||
|
||||
describe "POST #create" do
|
||||
describe "Authorized" do
|
||||
let(:device){create(:device)}
|
||||
before(:each) do
|
||||
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(device.access_token)
|
||||
end
|
||||
it "Valid params" do
|
||||
post :create, app_usage: attributes_for(:app_usage), format: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it "InValid Params" do
|
||||
post :create, app_usage: attributes_for(:invalid_app_usage), format: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
end
|
||||
describe "POST #create" do
|
||||
it "Unauthorized" do
|
||||
post :create, app_usage: attributes_for(:app_usage), format: :json
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
13
spec/factories/app_usages.rb
Normal file
13
spec/factories/app_usages.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
FactoryGirl.define do
|
||||
factory :app_usage do
|
||||
package_name "com.facebook.katana"
|
||||
usage_duration_in_seconds 7000
|
||||
used_on Date.today - 1.day
|
||||
end
|
||||
factory :invalid_app_usage, class: AppUsage do
|
||||
package_name ""
|
||||
usage_duration_in_seconds 7000
|
||||
used_on Date.today - 1.day
|
||||
end
|
||||
|
||||
end
|
||||
9
spec/models/app_usage_spec.rb
Normal file
9
spec/models/app_usage_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AppUsage, type: :model do
|
||||
let!(:app_usage) { create(:app_usage) }
|
||||
|
||||
it { should validate_presence_of :package_name }
|
||||
it { should validate_presence_of :usage_duration_in_seconds }
|
||||
it { should validate_presence_of :used_on }
|
||||
end
|
||||
Reference in New Issue
Block a user