From 02ecd19f58b4f1dc936611dab8c0df7ba12e8e6c Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 6 Apr 2016 20:51:54 -0700 Subject: [PATCH] provide latest ipfs hash for api --- app/api.rb | 3 ++- tests/api_tests.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/api.rb b/app/api.rb index b9d5ed8e..5a58902f 100644 --- a/app/api.rb +++ b/app/api.rb @@ -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 diff --git a/tests/api_tests.rb b/tests/api_tests.rb index de50312b..4a26dde8 100644 --- a/tests/api_tests.rb +++ b/tests/api_tests.rb @@ -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'