logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

jsonld_helper_spec.rb (2363B)


  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/').to_return body: '{"id": "https://alice/"}'
  28. stub_request(:get, 'https://alice/').to_return body: '{"id": "https://alice/"}'
  29. expect(fetch_resource('https://bob/', false)).to eq({ 'id' => 'https://alice/' })
  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/').to_return body: '{"id": "https://marvin/"}'
  33. stub_request(:get, 'https://marvin/').to_return body: '{"id": "https://alice/"}'
  34. expect(fetch_resource('https://mallory/', 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/').to_return body: '{"id": "https://alice/"}'
  40. expect(fetch_resource('https://mallory/', 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/').to_return status: 400, body: '{}'
  47. expect(fetch_resource_without_id_validation('https://host/')).to eq nil
  48. end
  49. it 'returns hash' do
  50. stub_request(:get, 'https://host/').to_return status: 200, body: '{}'
  51. expect(fetch_resource_without_id_validation('https://host/')).to eq({})
  52. end
  53. end
  54. end