From e827b8bab9a746ec79f829e64c398e139f8abfd0 Mon Sep 17 00:00:00 2001 From: Ridhwana Date: Thu, 29 Jul 2021 17:08:41 +0200 Subject: [PATCH] Minimal Seed Data for Admin Onboarding (#14385) * minimal seeded flows * fix: remove mistake * refactor: rename the files appropriately * feat: change some text * fix: typo * chore: new commit to rebuild --- .travis.yml | 2 +- bin/e2e | 6 +++--- config/initializers/cypress_rails.rb | 7 +++++-- .../test.spec.js | 0 docs/tests/e2e-tests.md | 5 ++--- lib/tasks/e2e_seed.rake | 8 ++++++++ package.json | 2 +- spec/support/seeds/creator_onboarding_seed_e2e.rb | 3 +++ 8 files changed, 23 insertions(+), 10 deletions(-) rename cypress/integration/{nonSeededFlows => creatorOnboardingFlows}/test.spec.js (100%) create mode 100644 spec/support/seeds/creator_onboarding_seed_e2e.rb diff --git a/.travis.yml b/.travis.yml index c9b076db9..219e262d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,7 +100,7 @@ jobs: script: - bundle exec rails db:create db:schema:load assets:precompile - yarn cypress install - - SKIP_SEED_DATA=1 E2E_FOLDER=nonSeededFlows bin/e2e-ci + - CREATOR_ONBOARDING_SEED_DATA=1 E2E_FOLDER=creatorOnboardingFlows bin/e2e-ci - stage: Deploy name: Deploy DEV if: type != pull_request diff --git a/bin/e2e b/bin/e2e index 093ea3ee2..72600c45d 100755 --- a/bin/e2e +++ b/bin/e2e @@ -30,9 +30,9 @@ printf "Starting the test runner...\n\n" bundle exec rails assets:precompile; -if [ $1 = "--no-seed" ]; then - echo "Running E2E tests without seed data" - CYPRESS_RAILS_CYPRESS_OPTS="--config-file cypress.dev.json" RAILS_ENV=test E2E=true SKIP_SEED_DATA=1 E2E_FOLDER=nonSeededFlows bundle exec rake cypress:open +if [ $1 = "--creator-onboarding-seed" ]; then + echo "Running E2E tests with creator onboarding seed data" + CYPRESS_RAILS_CYPRESS_OPTS="--config-file cypress.dev.json" RAILS_ENV=test E2E=true CREATOR_ONBOARDING_SEED_DATA=1 E2E_FOLDER=creatorOnboardingFlows bundle exec rake cypress:open else CYPRESS_RAILS_CYPRESS_OPTS="--config-file cypress.dev.json" RAILS_ENV=test E2E=true bundle exec rake cypress:open fi diff --git a/config/initializers/cypress_rails.rb b/config/initializers/cypress_rails.rb index e37b2d809..5b8301588 100644 --- a/config/initializers/cypress_rails.rb +++ b/config/initializers/cypress_rails.rb @@ -8,8 +8,11 @@ CypressRails.hooks.before_server_start do # Called once, before either the transaction or the server is started puts "Starting up server for end to end tests." - if ENV["SKIP_SEED_DATA"].blank? - Rails.application.load_tasks + Rails.application.load_tasks + + if ENV["CREATOR_ONBOARDING_SEED_DATA"] + Rake::Task["db:seed:e2e_creator_onboarding"].invoke + else Rake::Task["db:seed:e2e"].invoke end end diff --git a/cypress/integration/nonSeededFlows/test.spec.js b/cypress/integration/creatorOnboardingFlows/test.spec.js similarity index 100% rename from cypress/integration/nonSeededFlows/test.spec.js rename to cypress/integration/creatorOnboardingFlows/test.spec.js diff --git a/docs/tests/e2e-tests.md b/docs/tests/e2e-tests.md index a11db0851..015697473 100644 --- a/docs/tests/e2e-tests.md +++ b/docs/tests/e2e-tests.md @@ -43,9 +43,8 @@ coordinate all this work. ### 1. From the command line, run `yarn e2e` -Note: If you want to run E2E tests that do not require seeded data, run -`yarn e2e:noseed`. Some tests, like the admin onboarding require there to be no -seeded data. +Note: If you want to run E2E tests for the creator onboarding flow, you can run +`yarn e2e:creator-onboarding-seed`. Some initial setup and checks will automatically run as part of this command: diff --git a/lib/tasks/e2e_seed.rake b/lib/tasks/e2e_seed.rake index 6fb833c52..da588b59e 100644 --- a/lib/tasks/e2e_seed.rake +++ b/lib/tasks/e2e_seed.rake @@ -10,5 +10,13 @@ namespace :db do filename = SEED_DIR.join("seeds_e2e.rb") load(filename) if File.exist?(filename) end + + desc "Creator Onboarding seed data for e2e tests" + task e2e_creator_onboarding: :environment do + raise "Attempting to seed production environment, aborting!" if Rails.env.production? + + filename = SEED_DIR.join("creator_onboarding_seed_e2e.rb") + load(filename) if File.exist?(filename) + end end end diff --git a/package.json b/package.json index bb77cde48..8ccf24cb0 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "test:watch": "jest app/javascript/ bin/ --watch", "postcss": "postcss public/assets/*.css -d public/assets 2> postcss_error.log", "e2e": "bin/e2e", - "e2e:noseed": "yarn run e2e --no-seed" + "e2e:creator-onboarding-seed": "yarn run e2e --creator-onboarding-seed" }, "lint-staged": { "app/assets/config/manifest.js": [ diff --git a/spec/support/seeds/creator_onboarding_seed_e2e.rb b/spec/support/seeds/creator_onboarding_seed_e2e.rb new file mode 100644 index 000000000..e6f3f1915 --- /dev/null +++ b/spec/support/seeds/creator_onboarding_seed_e2e.rb @@ -0,0 +1,3 @@ +return unless Rails.env.test? && ENV["E2E"].present? + +FeatureFlag.enable(:creator_onboarding)