2024-04-06 16:31:33 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
2024-04-25 16:46:20 -04:00
|
|
|
RSpec.describe 'Imports', 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
|
|
|
|
|
|
|
|
|
|
describe 'GET /imports' do
|
2024-04-06 16:31:33 -04:00
|
|
|
context 'when user is logged in' do
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
sign_in user
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-25 16:46:20 -04:00
|
|
|
it 'returns http success' do
|
2024-04-06 16:31:33 -04:00
|
|
|
get imports_path
|
|
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user has imports' do
|
|
|
|
|
let!(:import) { create(:import, user: user) }
|
|
|
|
|
|
|
|
|
|
it 'displays imports' do
|
|
|
|
|
get imports_path
|
|
|
|
|
|
|
|
|
|
expect(response.body).to include(import.name)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-25 16:46:20 -04:00
|
|
|
describe 'POST /imports' do
|
2024-04-06 16:31:33 -04:00
|
|
|
context 'when user is logged in' do
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
let(:file) { fixture_file_upload('owntracks/export.json', 'application/json') }
|
|
|
|
|
|
|
|
|
|
before { sign_in user }
|
|
|
|
|
|
|
|
|
|
it 'queues import job' do
|
|
|
|
|
expect {
|
|
|
|
|
post imports_path, params: { import: { source: 'owntracks', files: [file] } }
|
|
|
|
|
}.to have_enqueued_job(ImportJob).on_queue('default').at_least(1).times
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'creates a new import' do
|
|
|
|
|
expect {
|
|
|
|
|
post imports_path, params: { import: { source: 'owntracks', files: [file] } }
|
|
|
|
|
}.to change(user.imports, :count).by(1)
|
|
|
|
|
|
|
|
|
|
expect(response).to redirect_to(imports_path)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|