-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
class InboundWebhook < ApplicationRecord | ||
belongs_to :organization | ||
|
||
validates :event_type, :payload, :source, :status, presence: true | ||
|
||
STATUSES = {pending: "pending"} | ||
|
||
enum :status, STATUSES | ||
end | ||
|
||
# == Schema Information | ||
# | ||
# Table name: inbound_webhooks | ||
# | ||
# id :uuid not null, primary key | ||
# code :string | ||
# event_type :string not null | ||
# payload :jsonb not null | ||
# signature :string | ||
# source :string not null | ||
# status :string default("pending"), not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# organization_id :uuid not null | ||
# | ||
# Indexes | ||
# | ||
# index_inbound_webhooks_on_organization_id (organization_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (organization_id => organizations.id) | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateInboundWebhooks < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :inbound_webhooks, id: :uuid do |t| | ||
t.string :source, null: false | ||
t.string :event_type, null: false | ||
t.jsonb :payload, null: false | ||
t.string :status, null: false, default: 'pending' | ||
t.belongs_to :organization, null: false, foreign_key: true, type: :uuid, index: true | ||
t.string :code | ||
t.string :signature | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :inbound_webhook do | ||
organization | ||
|
||
source { "stripe" } | ||
event_type { "payment_intent.succeeded" } | ||
status { "pending" } | ||
code { "webhook-endpoint-code" } | ||
signature { "MySignature" } | ||
|
||
payload do | ||
File.read(Rails.root.join('spec/fixtures/stripe/payment_intent_event.json')) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe InboundWebhook, type: :model do | ||
subject(:inbound_webhook) { build(:inbound_webhook) } | ||
|
||
it { is_expected.to belong_to(:organization) } | ||
|
||
it { is_expected.to validate_presence_of(:event_type) } | ||
it { is_expected.to validate_presence_of(:payload) } | ||
it { is_expected.to validate_presence_of(:source) } | ||
it { is_expected.to validate_presence_of(:status) } | ||
|
||
it { is_expected.to be_pending } | ||
end |