From 98520b02874fcf5b4e338adc1c613d1d00238c9d Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Thu, 5 Sep 2024 21:16:40 +0200 Subject: [PATCH] Add health check endpoint --- .app_version | 2 +- .circleci/config.yml | 2 +- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 12 +++++++ Dockerfile | 2 +- Dockerfile.dev | 2 +- Gemfile | 1 - Gemfile.lock | 2 -- app/controllers/api/v1/health_controller.rb | 9 +++++ config/routes.rb | 1 + docker-compose.yml | 1 - spec/requests/api/v1/health_spec.rb | 15 ++++++++ spec/services/visits/prepare_spec.rb | 36 +++++++++---------- spec/swagger/api/v1/health_controller_spec.rb | 15 ++++++++ swagger/v1/swagger.yaml | 8 +++++ 15 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 app/controllers/api/v1/health_controller.rb create mode 100644 spec/requests/api/v1/health_spec.rb create mode 100644 spec/swagger/api/v1/health_controller_spec.rb diff --git a/.app_version b/.app_version index 54d1a4f2..c317a918 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.13.0 +0.13.1 diff --git a/.circleci/config.yml b/.circleci/config.yml index 0a645c21..572db1e6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ orbs: jobs: test: docker: - - image: cimg/ruby:3.2.3 + - image: cimg/ruby:3.3.5 environment: RAILS_ENV: test - image: circleci/postgres:13.3 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fc46671..d8795c31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: '3.2.3' + ruby-version: '3.3.5' bundler-cache: true - name: Set up Node.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 16e195d0..007683a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.13.1] — 2024-09-05 + +### Added + +- `GET /api/v1/health` endpoint to check the health of the application with swagger docs + +### Changed + +- Ruby version updated to 3.3.5 +- Visits suggestion process now will try to merge consecutive visits to the same place into one visit. + + ## [0.13.0] — 2024-09-03 The GPX and GeoJSON export release diff --git a/Dockerfile b/Dockerfile index be06ed65..b3d0ab74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:3.2.3-alpine +FROM ruby:3.3.5-alpine ENV APP_PATH /var/app ENV BUNDLE_VERSION 2.5.9 diff --git a/Dockerfile.dev b/Dockerfile.dev index 56314976..f3964792 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM ruby:3.2.3-alpine +FROM ruby:3.3.5-alpine ENV APP_PATH /var/app ENV BUNDLE_VERSION 2.5.9 diff --git a/Gemfile b/Gemfile index 363356e8..501e82d3 100644 --- a/Gemfile +++ b/Gemfile @@ -47,7 +47,6 @@ group :test do gem 'shoulda-matchers' gem 'simplecov', require: false gem 'super_diff' - gem 'timecop' gem 'webmock' end diff --git a/Gemfile.lock b/Gemfile.lock index 40c2526c..721dbe66 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -389,7 +389,6 @@ GEM tailwindcss-rails (2.7.3-x86_64-linux) railties (>= 7.0.0) thor (1.3.2) - timecop (0.9.10) timeout (0.4.1) turbo-rails (2.0.6) actionpack (>= 6.0.0) @@ -458,7 +457,6 @@ DEPENDENCIES stimulus-rails super_diff tailwindcss-rails - timecop turbo-rails tzinfo-data webmock diff --git a/app/controllers/api/v1/health_controller.rb b/app/controllers/api/v1/health_controller.rb new file mode 100644 index 00000000..1e5ab2f1 --- /dev/null +++ b/app/controllers/api/v1/health_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Api::V1::HealthController < ApiController + skip_before_action :authenticate_api_key + + def index + render json: { status: 'ok' } + end +end diff --git a/config/routes.rb b/config/routes.rb index a0dba674..8eef1d85 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,6 +56,7 @@ Rails.application.routes.draw do namespace :api do namespace :v1 do + get 'health', to: 'health#index' patch 'settings', to: 'settings#update' get 'settings', to: 'settings#index' diff --git a/docker-compose.yml b/docker-compose.yml index 469549c2..7c805c76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3' networks: dawarich: services: diff --git a/spec/requests/api/v1/health_spec.rb b/spec/requests/api/v1/health_spec.rb new file mode 100644 index 00000000..264dbdcb --- /dev/null +++ b/spec/requests/api/v1/health_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Api::V1::Healths', type: :request do + describe 'GET /index' do + context 'when user is not authenticated' do + it 'returns http success' do + get '/api/v1/health' + + expect(response).to have_http_status(:success) + end + end + end +end diff --git a/spec/services/visits/prepare_spec.rb b/spec/services/visits/prepare_spec.rb index 9aa78474..dad39f0c 100644 --- a/spec/services/visits/prepare_spec.rb +++ b/spec/services/visits/prepare_spec.rb @@ -27,26 +27,22 @@ RSpec.describe Visits::Prepare do subject { described_class.new(points).call } it 'returns correct visits' do - freezed_time = Time.current - - Timecop.freeze(freezed_time) do - expect(subject).to eq [ - { - date: 1.day.ago.to_date.to_s, - visits: [ - { - latitude: 0.0, - longitude: 0.0, - radius: 10, - points:, - duration: 105, - started_at: 1.day.ago.to_s, - ended_at: (1.day.ago + 105.minutes).to_s - } - ] - } - ] - end + expect(subject).to eq [ + { + date: 1.day.ago.to_date.to_s, + visits: [ + { + latitude: 0.0, + longitude: 0.0, + radius: 10, + points:, + duration: 105, + started_at: 1.day.ago.to_s, + ended_at: (1.day.ago + 105.minutes).to_s + } + ] + } + ] end end end diff --git a/spec/swagger/api/v1/health_controller_spec.rb b/spec/swagger/api/v1/health_controller_spec.rb new file mode 100644 index 00000000..9dca9451 --- /dev/null +++ b/spec/swagger/api/v1/health_controller_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'swagger_helper' + +describe 'Health API', type: :request do + path '/api/v1/health' do + get 'Retrieves application status' do + tags 'Health' + produces 'application/json' + response '200', 'areas found' do + run_test! + end + end + end +end diff --git a/swagger/v1/swagger.yaml b/swagger/v1/swagger.yaml index 77b18ca4..aff1d958 100644 --- a/swagger/v1/swagger.yaml +++ b/swagger/v1/swagger.yaml @@ -106,6 +106,14 @@ paths: responses: '200': description: area deleted + "/api/v1/health": + get: + summary: Retrieves application status + tags: + - Health + responses: + '200': + description: areas found "/api/v1/overland/batches": post: summary: Creates a batch of points