jam-cloud/web/spec/requests/artifacts_api_spec.rb

79 lines
2.4 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe "Artifact API ", :type => :api do
subject { page }
before(:each) do
ArtifactUpdate.delete_all
end
describe "versioncheck" do
before do
@artifact = FactoryGirl.create(:artifact_update)
end
it "matches an artifact" do
2016-07-09 11:06:54 +00:00
get '/api/versioncheck.json', {:os => 'Win32', :product => 'JamClient'}
last_response.status.should eql(200)
2016-07-09 11:06:54 +00:00
JSON.parse(last_response.body).should eql({"version" => @artifact.version, "uri" => Rails.application.config.jam_admin_root_url + @artifact.uri.url, "size" => @artifact.size, "sha1" => @artifact.sha1})
end
it "matches no artifact" do
@artifact.delete
2016-07-09 11:06:54 +00:00
get '/api/versioncheck.json', {:os => 'Win32', :product => 'JamClient'}
last_response.status.should eql(200)
JSON.parse(last_response.body).should eql({})
end
2016-07-09 11:06:54 +00:00
it "fails on bad product" do
@artifact.delete
2016-07-09 11:06:54 +00:00
get '/api/versioncheck.json', {:os => 'what', :product => 'JamClient'}
last_response.status.should eql(422)
2016-07-09 11:06:54 +00:00
JSON.parse(last_response.body).should eql({"errors" => {"product" => ['not a valid product']}})
end
end
describe "client_downloads" do
2016-07-09 11:06:54 +00:00
describe "desktop" do
before do
@win_client = FactoryGirl.create(:artifact_update, :product => 'JamClient/Win32')
@mac_client= FactoryGirl.create(:artifact_update, :product => 'JamClient/MacOSX')
2016-07-09 11:06:54 +00:00
get '/api/artifacts/clients.json'
last_response.status.should eql(200)
@response = JSON.parse(last_response.body)
end
it {
@response.length.should == 2
@response[@mac_client.product]["size"].should == @mac_client.size
@response[@mac_client.product]["uri"].should_not be_nil
@response["JamClient/Win32"]["size"].should == @win_client.size
@response["JamClient/Win32"]["uri"].should_not be_nil
}
end
describe "jamblaster" do
before do
@jb_client = FactoryGirl.create(:artifact_update, :product => 'JamClient/JamBlaster')
2016-07-09 11:20:42 +00:00
get '/api/artifacts/JamBlaster.json', {serialno: 'abcde'}
2016-07-09 11:06:54 +00:00
last_response.status.should eql(200)
@response = JSON.parse(last_response.body)
end
2016-07-09 11:06:54 +00:00
it {
@response.length.should == 1
2016-07-09 11:20:42 +00:00
@response['JamBlaster']["size"].should == @jb_client.size
@response['JamBlaster']["uri"].should_not be_nil
2016-07-09 11:06:54 +00:00
Jamblaster.find_by_serial_no('abcde').should_not be_nil
}
end
end
end