mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
Add spec for CheckAppVersion service
This commit is contained in:
parent
e00f614b9a
commit
98d33da3d1
6 changed files with 59 additions and 4 deletions
1
Gemfile
1
Gemfile
|
|
@ -36,6 +36,7 @@ group :test do
|
|||
gem 'shoulda-matchers'
|
||||
gem 'simplecov'
|
||||
gem 'super_diff'
|
||||
gem 'webmock'
|
||||
end
|
||||
|
||||
group :development do
|
||||
|
|
|
|||
|
|
@ -91,6 +91,9 @@ GEM
|
|||
concurrent-ruby (1.2.3)
|
||||
connection_pool (2.4.1)
|
||||
content_disposition (1.0.0)
|
||||
crack (1.0.0)
|
||||
bigdecimal
|
||||
rexml
|
||||
crass (1.0.6)
|
||||
date (3.3.4)
|
||||
debug (1.9.2)
|
||||
|
|
@ -127,6 +130,7 @@ GEM
|
|||
geocoder (1.8.2)
|
||||
globalid (1.2.1)
|
||||
activesupport (>= 6.1)
|
||||
hashdiff (1.1.0)
|
||||
i18n (1.14.4)
|
||||
concurrent-ruby (~> 1.0)
|
||||
importmap-rails (2.0.1)
|
||||
|
|
@ -346,6 +350,10 @@ GEM
|
|||
unicode-display_width (2.5.0)
|
||||
warden (1.2.9)
|
||||
rack (>= 2.0.9)
|
||||
webmock (3.23.0)
|
||||
addressable (>= 2.8.0)
|
||||
crack (>= 0.3.2)
|
||||
hashdiff (>= 0.4.0, < 2.0.0)
|
||||
webrick (1.8.1)
|
||||
websocket-driver (0.7.6)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
|
|
@ -391,6 +399,7 @@ DEPENDENCIES
|
|||
tailwindcss-rails
|
||||
turbo-rails
|
||||
tzinfo-data
|
||||
webmock
|
||||
|
||||
RUBY VERSION
|
||||
ruby 3.2.3p157
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class CheckAppVersion
|
|||
def call
|
||||
begin
|
||||
latest_version = JSON.parse(Net::HTTP.get(URI.parse(@repo_url)))[0]['name']
|
||||
rescue
|
||||
rescue StandardError
|
||||
return false
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ RSpec.describe ImportJob, type: :job do
|
|||
describe '#perform' do
|
||||
subject(:perform) { described_class.new.perform(user.id, import.id) }
|
||||
|
||||
let(:file_path) { 'spec/fixtures/files/owntracks/export.json' }
|
||||
let(:file) { fixture_file_upload(file_path) }
|
||||
let(:user) { create(:user) }
|
||||
let(:import) { create(:import, user: user, file: file, name: File.basename(file.path)) }
|
||||
let(:import) { create(:import, user:, name: 'owntracks_export.json') }
|
||||
|
||||
it 'creates points' do
|
||||
expect { perform }.to change { Point.count }.by(8)
|
||||
|
|
|
|||
43
spec/services/check_app_version_spec.rb
Normal file
43
spec/services/check_app_version_spec.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CheckAppVersion do
|
||||
describe '#call' do
|
||||
subject(:check_app_version) { described_class.new.call }
|
||||
|
||||
let(:app_version) { File.read('.app_version').strip }
|
||||
|
||||
before do
|
||||
stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags')
|
||||
.to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {})
|
||||
end
|
||||
|
||||
context 'when latest version is newer' do
|
||||
before { allow(File).to receive(:read).with('.app_version').and_return('0.9.0') }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when latest version is the same' do
|
||||
before { allow(File).to receive(:read).with('.app_version').and_return('1.0.0') }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context 'when latest version is older' do
|
||||
before { allow(File).to receive(:read).with('.app_version').and_return('1.1.0') }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when request fails' do
|
||||
before do
|
||||
allow(Net::HTTP).to receive(:get).and_raise(StandardError)
|
||||
allow(File).to receive(:read).with('.app_version').and_return(app_version)
|
||||
end
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'simplecov'
|
||||
require 'webmock/rspec'
|
||||
|
||||
SimpleCov.start
|
||||
|
||||
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
||||
|
|
|
|||
Loading…
Reference in a new issue