provide latest ipfs hash for api

This commit is contained in:
Kyle Drake 2016-04-06 20:51:54 -07:00
parent 4d223e356e
commit 02ecd19f58
2 changed files with 10 additions and 1 deletions

View file

@ -119,7 +119,8 @@ def api_info_for(site)
created_at: site.created_at.rfc2822,
last_updated: site.site_updated_at ? site.site_updated_at.rfc2822 : nil,
domain: site.domain,
tags: site.tags.collect {|t| t.name}
tags: site.tags.collect {|t| t.name},
latest_ipfs_hash: site.latest_archive ? site.latest_archive.ipfs_hash : nil
}
}
end

View file

@ -76,6 +76,7 @@ describe 'api info' do
it 'succeeds for valid sitename' do
create_site
@site.update hits: 31337, domain: 'derp.com', new_tags_string: 'derpie, man'
@site.add_archive ipfs_hash: 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU'
get '/api/info', sitename: @user
res[:result].must_equal 'success'
res[:info][:sitename].must_equal @site.username
@ -84,9 +85,16 @@ describe 'api info' do
res[:info][:last_updated].must_equal nil
res[:info][:domain].must_equal 'derp.com'
res[:info][:tags].must_equal ['derpie', 'man']
res[:info][:latest_ipfs_hash].must_equal 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU'
@site.reload.api_calls.must_equal 0
end
it 'shows latest ipfs hash as nil when not present' do
create_site
get '/api/info', sitename: @user
res[:info][:latest_ipfs_hash].must_equal nil
end
it 'fails for bad auth' do
basic_authorize 'derp', 'fake'
get '/api/info'