闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.4 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe JsonLdHelper do
  4. describe '#equals_or_includes?' do
  5. it 'returns true when value equals' do
  6. expect(helper.equals_or_includes?('foo', 'foo')).to be true
  7. end
  8. it 'returns false when value does not equal' do
  9. expect(helper.equals_or_includes?('foo', 'bar')).to be false
  10. end
  11. it 'returns true when value is included' do
  12. expect(helper.equals_or_includes?(%w(foo baz), 'foo')).to be true
  13. end
  14. it 'returns false when value is not included' do
  15. expect(helper.equals_or_includes?(%w(foo baz), 'bar')).to be false
  16. end
  17. end
  18. describe '#first_of_value' do
  19. pending
  20. end
  21. describe '#supported_context?' do
  22. pending
  23. end
  24. describe '#fetch_resource' do
  25. context 'when the second argument is false' do
  26. it 'returns resource even if the retrieved ID and the given URI does not match' do
  27. stub_request(:get, 'https://bob.test/').to_return body: '{"id": "https://alice.test/"}'
  28. stub_request(:get, 'https://alice.test/').to_return body: '{"id": "https://alice.test/"}'
  29. expect(fetch_resource('https://bob.test/', false)).to eq({ 'id' => 'https://alice.test/' })
  30. end
  31. it 'returns nil if the object identified by the given URI and the object identified by the retrieved ID does not match' do
  32. stub_request(:get, 'https://mallory.test/').to_return body: '{"id": "https://marvin.test/"}'
  33. stub_request(:get, 'https://marvin.test/').to_return body: '{"id": "https://alice.test/"}'
  34. expect(fetch_resource('https://mallory.test/', false)).to eq nil
  35. end
  36. end
  37. context 'when the second argument is true' do
  38. it 'returns nil if the retrieved ID and the given URI does not match' do
  39. stub_request(:get, 'https://mallory.test/').to_return body: '{"id": "https://alice.test/"}'
  40. expect(fetch_resource('https://mallory.test/', true)).to eq nil
  41. end
  42. end
  43. end
  44. describe '#fetch_resource_without_id_validation' do
  45. it 'returns nil if the status code is not 200' do
  46. stub_request(:get, 'https://host.test/').to_return status: 400, body: '{}'
  47. expect(fetch_resource_without_id_validation('https://host.test/')).to eq nil
  48. end
  49. it 'returns hash' do
  50. stub_request(:get, 'https://host.test/').to_return status: 200, body: '{}'
  51. expect(fetch_resource_without_id_validation('https://host.test/')).to eq({})
  52. end
  53. end
  54. end