Update links to n8n server

This commit is contained in:
Maikel Linke
2024-05-02 15:55:16 +10:00
parent 2e004a026b
commit b0a89372ab
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
# frozen_string_literal: true
# We got a new n8n server.
# But we still have some database rows with a URL to the old server.
class UpdateN8nUrl < ActiveRecord::Migration[7.0]
def up
execute <<~SQL.squish
UPDATE connected_apps
SET data = replace(
data::text,
'n8n.openfoodnetwork.org.uk',
'n8n.openfoodnetwork.org'
)::jsonb
WHERE data IS NOT NULL;
SQL
end
end

View File

@@ -0,0 +1,50 @@
# frozen_string_literal: true
require 'spec_helper'
require_relative '../../db/migrate/20240502035220_update_n8n_url'
describe UpdateN8nUrl do
# We may want to move this to a support file if this syntax is useful in
# other places. Reference:
# - https://stackoverflow.com/a/34969429/3377535
RSpec::Matchers.define_negated_matcher :not_change, :change
let(:enterprise) { create(:enterprise) }
let(:old_data) {
{
link: "https://link-to-form",
destroy: "https://n8n.openfoodnetwork.org.uk/webhook/remove-enterprise?key=abc&id=123",
}
}
let(:new_data) {
{
link: "https://link-to-form",
destroy: "https://n8n.openfoodnetwork.org/webhook/remove-enterprise?key=abc&id=123",
}
}
it "updates old connected app links" do
app = ConnectedApp.create!(enterprise:, data: old_data,)
expect {
subject.up
app.reload
}.to change {
app.data["destroy"]
}.to("https://n8n.openfoodnetwork.org/webhook/remove-enterprise?key=abc&id=123")
.and not_change {
app.data["link"]
}
end
it "keeps new connected app links" do
app = ConnectedApp.create!(enterprise:, data: new_data,)
expect {
subject.up
app.reload
}.not_to change {
app.data
}
end
end