diff --git a/Gemfile b/Gemfile index c40d733..2b2ea88 100644 --- a/Gemfile +++ b/Gemfile @@ -18,3 +18,7 @@ gem 'byebug' # Development gem 'faker' gem 'rubocop' + +# Testing +gem 'rack-test', group: :test +gem 'minitest', group: :test \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index c4af85b..12d4c02 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,6 +51,8 @@ GEM rack (2.2.8) rack-protection (3.1.0) rack (~> 2.2, >= 2.2.4) + rack-test (2.1.0) + rack (>= 1.3) rainbow (3.1.1) rake (13.1.0) rb-fsevent (0.11.2) @@ -97,7 +99,9 @@ DEPENDENCIES bcrypt byebug faker + minitest puma + rack-test rake rerun rubocop diff --git a/README.md b/README.md index 7289355..75d377f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,13 @@ To install `tu|du|di`, follow these steps: openssl req -new -x509 -key server.key -out server.crt -days 365 ``` +### DB setup +1. Execute the migrations + + ```bash + rake db:migrate + ``` + ### Create your user 1. Open console ```bash @@ -76,6 +83,14 @@ To start the application, run the following command in your terminal: puma -C app/config/puma.rb ``` +### Testing + +To run tests: + +```bash +bundle exec ruby -Itest test/test_app.rb +``` + Open your browser and navigate to `http://localhost:9292` to access the application and login with the email and the password you created. ## Contributing diff --git a/test/test_app.rb b/test/test_app.rb new file mode 100644 index 0000000..52706a7 --- /dev/null +++ b/test/test_app.rb @@ -0,0 +1,28 @@ +require 'minitest/autorun' +require 'rack/test' +require_relative '../app' + +class AppTest < Minitest::Test + include Rack::Test::Methods + + def app + Sinatra::Application + end + + def setup + ActiveRecord::Base.logger.level = Logger::WARN + User.create(email: 'test@example.com', password: 'password') + end + + def test_get_home + post '/login', { email: 'test@example.com', password: 'password' } + get '/' + assert last_response.ok? + end + + def test_get_inbox + post '/login', { email: 'test@example.com', password: 'password' } + get '/inbox' + assert last_response.ok? + end +end