payload_renderer_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Webhooks::PayloadRenderer do
  4. subject(:renderer) { described_class.new(json) }
  5. let(:event) { Webhooks::EventPresenter.new(type, object) }
  6. let(:payload) { ActiveModelSerializers::SerializableResource.new(event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json }
  7. let(:json) { Oj.dump(payload) }
  8. describe '#render' do
  9. context 'when event is account.approved' do
  10. let(:type) { 'account.approved' }
  11. let(:object) { Fabricate(:account, display_name: 'Foo"') }
  12. it 'renders event-related variables into template' do
  13. expect(renderer.render('foo={{event}}')).to eq 'foo=account.approved'
  14. end
  15. it 'renders event-specific variables into template' do
  16. expect(renderer.render('foo={{object.username}}')).to eq "foo=#{object.username}"
  17. end
  18. it 'escapes values for use in JSON' do
  19. expect(renderer.render('foo={{object.account.display_name}}')).to eq 'foo=Foo\\"'
  20. end
  21. end
  22. end
  23. end