* Start with webhooks: table and model * Start with webhooks api * Start with webhooks api * Webhook::Event class and events list * Remove commented callbacks * Start with sending events to webhook endpoints * A couple of tests for Articles::Creator * Send event to webhook endpoint on article destroy * Dispatch event on article update * Dispatch event when an article updated from admin * Spec for the webhook job * One more test for the dispatch event job * Integration-like spec for event dispatching to webhook endpoints when creating an article * Use Addressable::URI to parse endpoint url * Add oj as a faster fast_jsonapi backend * Renamed serializers * Move article serialization out of a model * Don't allow to create a webhook event with invalid type * Add fields for ArticleSerializer * Fix webhook event job specs * Specify timeout when dispatching events * Fix webhook job spec * Change webhook events queue name * Change serialized article fields for the dispatchable events * Include user data when serializing an article for webhook event * Moved decorating out of Webhook::DispatchEvent, fixed most specs * Fix route in ArticleSerializer * Move Article decoration to Webhook::PayloadAdapter * Refactor image url helpers to avoid including helpers into serializer * Fix specs * Default url options for production
35 lines
1.2 KiB
Ruby
35 lines
1.2 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Webhook::PayloadAdapter, type: :service do
|
|
it "raises an exception when invalid object is passed" do
|
|
expect do
|
|
described_class.new(User.new).hash
|
|
end.to raise_error(Webhook::InvalidPayloadObject)
|
|
end
|
|
|
|
describe "#hash" do
|
|
let(:user) { create(:user) }
|
|
let!(:article) { create(:article, title: "I'm super", user: user) }
|
|
|
|
it "returns a hash for a persisted article" do
|
|
data = described_class.new(article).hash
|
|
expect(data).to be_kind_of(Hash)
|
|
expect(data[:data][:attributes][:title]).to eq(article.title)
|
|
expect(data[:data][:attributes][:body_markdown]).to be_truthy
|
|
end
|
|
|
|
it "returns a hash with a user" do
|
|
data = described_class.new(article).hash
|
|
expect(data[:data][:attributes][:user][:data][:attributes][:username]).to eq(user.username)
|
|
end
|
|
|
|
it "returns a hash for a destroyed article" do
|
|
article = create(:article, title: "hello")
|
|
article.destroy
|
|
data = described_class.new(article).hash
|
|
expect(data).to be_kind_of(Hash)
|
|
expect(data[:data][:attributes][:title]).to eq("hello")
|
|
expect(data[:data][:attributes][:body_markdown]).to be_falsey
|
|
end
|
|
end
|
|
end
|