link_headers_spec.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'Link headers' do
  4. describe 'on the account show page' do
  5. let(:account) { Fabricate(:account, username: 'test') }
  6. before do
  7. get short_account_path(username: account)
  8. end
  9. it 'contains webfinger url in link header' do
  10. link_header = link_header_with_type('application/jrd+json')
  11. expect(link_header.href).to match 'http://www.example.com/.well-known/webfinger?resource=acct%3Atest%40cb6e6126.ngrok.io'
  12. expect(link_header.attr_pairs.first).to eq %w(rel lrdd)
  13. end
  14. it 'contains activitypub url in link header' do
  15. link_header = link_header_with_type('application/activity+json')
  16. expect(link_header.href).to eq 'https://cb6e6126.ngrok.io/users/test'
  17. expect(link_header.attr_pairs.first).to eq %w(rel alternate)
  18. end
  19. def link_header_with_type(type)
  20. response.headers['Link'].links.find do |link|
  21. link.attr_pairs.any? { |pair| pair == ['type', type] }
  22. end
  23. end
  24. end
  25. end