dawarich/spec/requests/stats_spec.rb

69 lines
1.5 KiB
Ruby
Raw Normal View History

2024-04-25 16:46:20 -04:00
# frozen_string_literal: true
2024-03-23 15:29:55 -04:00
require 'rails_helper'
2024-04-25 16:46:20 -04:00
RSpec.describe '/stats', type: :request do
before do
stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags')
.to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {})
end
2024-03-23 15:29:55 -04:00
context 'when user is not signed in' do
describe 'GET /index' do
it 'redirects to the sign in page' do
get stats_url
expect(response.status).to eq(302)
end
end
describe 'GET /show' do
it 'redirects to the sign in page' do
get stats_url(2024)
expect(response.status).to eq(401)
end
end
end
context 'when user is signed in' do
before do
sign_in user
end
let(:user) { create(:user) }
describe 'GET /index' do
it 'renders a successful response' do
get stats_url
expect(response.status).to eq(200)
end
end
describe 'GET /show' do
let(:stat) { create(:stat, user:, year: 2024) }
it 'renders a successful response' do
get stats_url(stat.year)
expect(response.status).to eq(200)
end
end
describe 'POST /update' do
let(:stat) { create(:stat, user:, year: 2024) }
2024-12-06 10:52:36 -05:00
it 'enqueues Stats::CalculatingJob for each tracked year and month' do
allow(user).to receive(:years_tracked).and_return([2024])
post stats_url
(1..12).each do |month|
expect(Stats::CalculatingJob).to have_been_enqueued.with(user.id, 2024, month)
end
end
2024-03-23 15:29:55 -04:00
end
end
end