2024-05-18 07:58:02 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-04-06 13:09:38 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
2024-05-18 07:58:02 -04:00
|
|
|
RSpec.describe 'Api::V1::Overland::Batches', type: :request do
|
|
|
|
|
describe 'POST /index' do
|
2024-04-06 16:31:33 -04:00
|
|
|
let(:file_path) { 'spec/fixtures/files/overland/geodata.json' }
|
2024-04-06 13:09:38 -04:00
|
|
|
let(:file) { File.open(file_path) }
|
|
|
|
|
let(:json) { JSON.parse(file.read) }
|
|
|
|
|
let(:params) { json }
|
|
|
|
|
|
2024-05-25 06:47:25 -04:00
|
|
|
context 'with invalid api key' do
|
|
|
|
|
it 'returns http unauthorized' do
|
|
|
|
|
post '/api/v1/overland/batches', params: params
|
2024-04-06 13:09:38 -04:00
|
|
|
|
2024-05-25 06:47:25 -04:00
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
|
end
|
2024-04-06 13:09:38 -04:00
|
|
|
end
|
|
|
|
|
|
2024-05-25 06:47:25 -04:00
|
|
|
context 'with valid api key' do
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
|
post "/api/v1/overland/batches?api_key=#{user.api_key}", params: params
|
|
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:created)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'enqueues a job' do
|
|
|
|
|
expect do
|
|
|
|
|
post "/api/v1/overland/batches?api_key=#{user.api_key}", params: params
|
|
|
|
|
end.to have_enqueued_job(Overland::BatchCreatingJob)
|
|
|
|
|
end
|
2025-02-19 15:23:11 -05:00
|
|
|
|
|
|
|
|
context 'when user is inactive' do
|
|
|
|
|
before do
|
2025-04-04 15:12:42 -04:00
|
|
|
user.update(status: :inactive, active_until: 1.day.ago)
|
2025-02-19 15:23:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'returns http unauthorized' do
|
|
|
|
|
post "/api/v1/overland/batches?api_key=#{user.api_key}", params: params
|
|
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-04-06 13:09:38 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|