This commit is contained in:
Kara Diaby 2022-07-25 09:16:07 +02:00
parent d18d89b41b
commit 058d6baae6
9 changed files with 158 additions and 2 deletions

View file

@ -0,0 +1,19 @@
RSpec.describe Cron::Datagouv::AccountByMonthJob, type: :job do
let!(:user) { create(:user, created_at: 1.month.ago) }
let(:status) { 200 }
let(:body) { "ok" }
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) }
describe 'perform' do
before do
stub
end
subject { Cron::Datagouv::AccountByMonthJob.perform_now }
it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end
end

View file

@ -0,0 +1,19 @@
RSpec.describe Cron::Datagouv::AdministrateurByMonthJob, type: :job do
let!(:administrateur) { create(:administrateur, created_at: 1.month.ago) }
let(:status) { 200 }
let(:body) { "ok" }
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) }
describe 'perform' do
before do
stub
end
subject { Cron::Datagouv::AdministrateurByMonthJob.perform_now }
it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end
end

View file

@ -0,0 +1,19 @@
RSpec.describe Cron::Datagouv::FileByMonthJob, type: :job do
let!(:dossier) { create(:dossier, created_at: 1.month.ago) }
let(:status) { 200 }
let(:body) { "ok" }
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) }
describe 'perform' do
before do
stub
end
subject { Cron::Datagouv::FileByMonthJob.perform_now }
it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end
end

View file

@ -0,0 +1,19 @@
RSpec.describe Cron::Datagouv::InstructeurByMonthJob, type: :job do
let!(:instructeur) { create(:instructeur, created_at: 1.month.ago) }
let(:status) { 200 }
let(:body) { "ok" }
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) }
describe 'perform' do
before do
stub
end
subject { Cron::Datagouv::InstructeurByMonthJob.perform_now }
it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end
end

View file

@ -0,0 +1,20 @@
RSpec.describe Cron::Datagouv::InstructeurConnectedByMonthJob, type: :job do
let!(:user) { create(:user) }
let!(:instructeur) { create(:instructeur, user: user, created_at: 1.month.ago) }
let(:status) { 200 }
let(:body) { "ok" }
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) }
describe 'perform' do
before do
stub
end
subject { Cron::Datagouv::InstructeurConnectedByMonthJob.perform_now }
it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end
end

View file

@ -0,0 +1,19 @@
RSpec.describe Cron::Datagouv::ProcedureByMonthJob, type: :job do
let!(:procedure) { create(:procedure, created_at: 1.month.ago) }
let(:status) { 200 }
let(:body) { "ok" }
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) }
describe 'perform' do
before do
stub
end
subject { Cron::Datagouv::ProcedureByMonthJob.perform_now }
it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end
end

View file

@ -0,0 +1,19 @@
RSpec.describe Cron::Datagouv::ProcedureClosedByMonthJob, type: :job do
let!(:procedure) { create(:procedure, closed_at: 1.month.ago) }
let(:status) { 200 }
let(:body) { "ok" }
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) }
describe 'perform' do
before do
stub
end
subject { Cron::Datagouv::ProcedureClosedByMonthJob.perform_now }
it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end
end

View file

@ -0,0 +1,19 @@
RSpec.describe Cron::Datagouv::ProcedureDeletedByMonthJob, type: :job do
let!(:procedure) { create(:procedure, hidden_at: 1.month.ago) }
let(:status) { 200 }
let(:body) { "ok" }
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) }
describe 'perform' do
before do
stub
end
subject { Cron::Datagouv::ProcedureDeletedByMonthJob.perform_now }
it 'send POST request to datagouv' do
subject
expect(stub).to have_been_requested
end
end
end

View file

@ -1,9 +1,12 @@
describe APIDatagouv::API do
describe '#upload' do
let(:subject) { APIDatagouv::API.upload(Tempfile.new.path) }
let(:dataset) { :descriptif_demarches_dataset }
let(:resource) { :descriptif_demarches_resource }
let(:datagouv_secret) { Rails.application.secrets.datagouv }
let(:subject) { APIDatagouv::API.upload(Tempfile.new, dataset, resource) }
before do
stub_request(:post, /https:\/\/www.data.gouv.fr\/api/)
stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/1\/datasets\/#{datagouv_secret[dataset]}\/resources\/#{datagouv_secret[resource]}\/upload\//)
.to_return(body: body, status: status)
end