mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-11 18:26:50 +00:00
Add type to WebhookEnpoints
Add migration to update existing endpoint to "order_cycle_opened" type
This commit is contained in:
@@ -2,5 +2,8 @@
|
||||
|
||||
# Records a webhook url to send notifications to
|
||||
class WebhookEndpoint < ApplicationRecord
|
||||
WEBHOOK_TYPES = %w(order_cycle_opened payment_status_changed).freeze
|
||||
|
||||
validates :url, presence: true
|
||||
validates :webhook_type, presence: true, inclusion: { in: WEBHOOK_TYPES }
|
||||
end
|
||||
|
||||
16
db/migrate/20251124043324_add_type_to_webhook_endpoints.rb
Normal file
16
db/migrate/20251124043324_add_type_to_webhook_endpoints.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddTypeToWebhookEndpoints < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
# Using "order_cycle_opened" as default will update existing record
|
||||
change_table(:webhook_endpoints, bulk: true) do |t|
|
||||
t.column :webhook_type, :string, limit: 255, null: false, default: "order_cycle_opened"
|
||||
end
|
||||
# Drop the default value
|
||||
change_column_default :webhook_endpoints, :webhook_type, nil
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :webhook_endpoints, :webhook_type
|
||||
end
|
||||
end
|
||||
@@ -1143,6 +1143,7 @@ ActiveRecord::Schema[7.1].define(version: 2025_11_26_005628) do
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.bigint "user_id", default: 0, null: false
|
||||
t.string "webhook_type", limit: 255, null: false
|
||||
t.index ["user_id"], name: "index_webhook_endpoints_on_user_id"
|
||||
end
|
||||
|
||||
|
||||
@@ -5,5 +5,9 @@ require 'spec_helper'
|
||||
RSpec.describe WebhookEndpoint do
|
||||
describe "validations" do
|
||||
it { is_expected.to validate_presence_of(:url) }
|
||||
it {
|
||||
is_expected.to validate_inclusion_of(:webhook_type)
|
||||
.in_array(%w(order_cycle_opened payment_status_changed))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user