Skip to content

Commit

Permalink
chore: Test backfilling meta default values
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrubisch committed Nov 27, 2024
1 parent afe545a commit 01cc79a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT

GIT
remote: https://github.com/avo-hq/avo-meta.git
revision: 0bb45bf773286ff4a0f57450812d818d0930cada
revision: eebe10c85a961a938493282a4330343abd70441c
branch: main
specs:
avo-meta (0.1.0)
Expand Down
46 changes: 31 additions & 15 deletions spec/system/avo/meta/meta_schema_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "rails_helper"

RSpec.describe "MetaSchema", type: :system do
include ActiveJob::TestHelper

let!(:user) { create :user }
let!(:post) { create :post }
let!(:schema) { create :meta_schema }
Expand Down Expand Up @@ -35,13 +37,7 @@
end

it "allows to add new entries to the user meta schema, which can instantly be used" do
visit avo.resources_meta_schemas_path

within "#avo_meta_schemas_list" do
find("td", text: "User").click
end

click_on "Edit"
visit avo.edit_resources_meta_schema_path(schema)

click_on "Add a new property"

Expand All @@ -68,13 +64,7 @@
end

it "allows to add new entries to the user meta schema with default" do
visit avo.resources_meta_schemas_path

within "#avo_meta_schemas_list" do
find("td", text: "User").click
end

click_on "Edit"
visit avo.edit_resources_meta_schema_path(schema)

click_on "Add a new property"

Expand All @@ -90,7 +80,33 @@
visit avo.new_resources_user_path

expect(page).to have_field("Driving license", with: "B")
end

it "ensures that existing meta entries are not touched by backfilling defaults" do
perform_enqueued_jobs

visit avo.edit_resources_user_path(User.first)

fill_in "Shoe size", with: "10"

save

visit avo.edit_resources_meta_schema_path(schema)

click_on "Add a new property"

fill_in "Name", with: "driving_license"
select "Text", from: find('select[name*="[schema_entries_attributes]["][name*="][as]"]')[:id]
fill_in "Default", with: "B"

save

perform_enqueued_jobs

# assert that backfilling worked but didn't touch the existing meta properties
visit avo.resources_user_path(User.first)

# TODO test backfilling
expect(find("[data-field-id=\"shoe_size\"]")).to have_text "10"
expect(find("[data-field-id=\"driving_license\"]")).to have_text "B"
end
end

0 comments on commit 01cc79a

Please sign in to comment.