diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 8a28e66..6d11605 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -1,11 +1,21 @@ require "uuid" +require "file_utils" require "spec-kemal" require "micrate" +require "dotenv" +Dotenv.load ".env.#{ENV["ENV"]}" + require "../bit" Spec.before_suite do + # Delete the SQLite database file if it exists + db_file_path = ENV["DATABASE_URL"].split("sqlite3://").last.split("?").first + if File.exists?(db_file_path) + File.delete(db_file_path) + end + Micrate::DB.connection_url = ENV["DATABASE_URL"] Micrate::Cli.run_up @@ -20,7 +30,8 @@ def create_test_user changeset = App::Lib::Database.insert(user) if !changeset.valid? - raise "Test user creation failed" + error_messages = changeset.errors.map { |error| "#{error}" }.join(", ") + raise "Test user creation failed #{error_messages}" end user @@ -29,13 +40,14 @@ end def create_test_link(user, url) link = App::Models::Link.new link.id = UUID.v4.to_s + link.slug = App::Services::SlugService.shorten_url(url) link.url = url - link.slug = Random::Secure.urlsafe_base64(4) link.user = user changeset = App::Lib::Database.insert(link) - if !changeset.valid? - raise "Test link creation failed" + unless changeset.valid? + error_messages = changeset.errors.map { |error| "#{error}" }.join(", ") + raise "Test link creation failed: #{error_messages} #{url} #{link.slug}" end link.clicks = [] of App::Models::Click