Skip to content

Commit

Permalink
test: Write system test for happy path of creating a new schema entry
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrubisch committed Nov 27, 2024
1 parent ba830e3 commit a63b966
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ brakeman_results.html

.env
.env.test
*~
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,5 @@ gem "pagy", "> 8"
gem "csv"

gem "avo-meta", github: "avo-hq/avo-meta", branch: "main"

gem "store_model"
3 changes: 2 additions & 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: 874345836c3e686c2d716a0ae542caaad3aa8cab
revision: 92a9977f0389015e5229fa0552db52045a41ea78
branch: main
specs:
avo-meta (0.1.0)
Expand Down Expand Up @@ -762,6 +762,7 @@ DEPENDENCIES
spring-commands-rspec
sprockets-rails
standard
store_model
test-prof
tzinfo-data
web-console (>= 3.3.0)
Expand Down
11 changes: 10 additions & 1 deletion db/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

factory :project do
name { Faker::App.name }
status { ['closed', :rejected, :failed, 'loading', :running, :waiting].sample }
status { ["closed", :rejected, :failed, "loading", :running, :waiting].sample }
stage { ["Discovery", "Idea", "Done", "On hold", "Cancelled", "Drafting"].sample }
budget { Faker::Number.decimal(l_digits: 4) }
country { Faker::Address.country_code }
Expand Down Expand Up @@ -148,4 +148,13 @@
name { Faker::Company.name }
size { ["small", "medium", "large"].sample }
end

factory :meta_schema, class: "Avo::Meta::Schema" do
resource_name { "User" }
schema_entries {
[
Avo::Meta::SchemaEntry.new(name: "shoe_size", type: "integer", as: "number")

Check failure on line 156 in db/factories.rb

View workflow job for this annotation

GitHub Actions / lint / runner / standardrb

[rubocop] reported by reviewdog 🐶 [Corrected] Layout/FirstArrayElementIndentation: Use 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is. Raw Output: db/factories.rb:156:11: C: [Corrected] Layout/FirstArrayElementIndentation: Use 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is. Avo::Meta::SchemaEntry.new(name: "shoe_size", type: "integer", as: "number") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
]
}
end
end
12 changes: 0 additions & 12 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@
t.index ["resource_name"], name: "index_avo_meta_schemas_on_resource_name", unique: true
end

create_table "avo_resources", force: :cascade do |t|
t.string "name", null: false
t.json "fields", null: false
t.json "includes"
t.json "attachments"
t.json "single_includes"
t.json "single_attachments"
t.json "meta", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "cities", force: :cascade do |t|
t.string "name"
t.integer "population"
Expand Down
71 changes: 71 additions & 0 deletions spec/system/avo/meta/meta_schema_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require "rails_helper"

RSpec.describe "MetaSchema", type: :system do
let!(:user) { create :user }
let!(:post) { create :post }
let!(:schema) { create :meta_schema }

it "allows to add new entries to the user meta schema" do
visit "/admin/resources/meta_schemas"

click_on "User"
end

it "allows to create completely new meta schemas" do
visit avo.resources_post_path(Post.first)

expect(page).not_to have_text("GUEST AUTHOR NAME")

visit avo.resources_meta_schemas_path

click_on "Create new meta schema"

select "Post", from: "avo/meta/schema[resource_name]"

click_on "Add a new property"

fill_in "Name", with: "guest_author_name"
select "string", from: find('select[name*="[schema_entries_attributes]["][name*="][type]"]')[:id]
select "text", from: find('select[name*="[schema_entries_attributes]["][name*="][as]"]')[:id]

save

visit avo.resources_post_path(Post.first)

expect(page).to have_text("GUEST AUTHOR NAME")
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"

click_on "Add a new property"

fill_in "Name", with: "nickname"
select "string", from: find('select[name*="[schema_entries_attributes]["][name*="][type]"]')[:id]
select "text", from: find('select[name*="[schema_entries_attributes]["][name*="][as]"]')[:id]

save

expect(page).to have_text("Meta schema was successfully updated")

# assert that the new attribute is actually present and editable
visit avo.resources_user_path(User.last)

expect(page).to have_text("Meta")
expect(page).to have_text("NICKNAME")

click_on "Edit"

fill_in "user_meta_nickname", with: "Ace Ventura"

save

expect(page).to have_text("Ace Ventura")
end
end

0 comments on commit a63b966

Please sign in to comment.