Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajoute un model claim pour gérer les demandes #6

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/interactors/create_shipment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateShipment < BaseInteractor
def call
shipment = Shipment.new(params)
if shipment.save
context.shipment = shipment
else
context.fail!(message: shipment.errors.full_messages)
end
end

private

def params
{
sub: context.identity.sub,
hubee_folder_id: context.folder.id,
}
end
end
5 changes: 5 additions & 0 deletions app/models/pivot_identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PivotIdentity
map from("info/last_name"), to("last_name")
map from("extra/raw_info/birthcountry"), to("birth_country")
map from("extra/raw_info/birthplace"), to("birthplace")
map from("extra/raw_info/sub"), to("sub")

map from("credentials/token"), to("token")

Expand All @@ -34,6 +35,10 @@ def authenticated?
@auth.present?
end

def sub
self[:sub]
end

def token
self[:token]
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/shipment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Shipment < ApplicationRecord
end
2 changes: 1 addition & 1 deletion app/organizers/store_quotient_familial.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class StoreQuotientFamilial < BaseOrganizer
organize UploadQuotientFamilialToHubEE
organize UploadQuotientFamilialToHubEE, CreateShipment
end
10 changes: 10 additions & 0 deletions db/migrate/20240603084727_create_shipments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateShipments < ActiveRecord::Migration[7.1]
def change
create_table :shipments do |t|
t.string :sub
t.string :hubee_folder_id

t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions spec/factories/shipments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :shipment do
sub { "uuid" }
hubee_folder_id { "folder_uuid" }
end
end
24 changes: 24 additions & 0 deletions spec/interactors/create_shipment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "rails_helper"

RSpec.describe CreateShipment, type: :interactor do
describe ".call" do
subject(:interactor) { described_class.call(**params) }

let(:folder) { instance_double("HubEE::Folder", id: "folder_uuid") }
let(:identity) { instance_double("PivotIdentity", sub: "real_uuid") }
let(:params) do
{
identity:,
folder:,
}
end

context "when the params are valid" do
it { is_expected.to be_a_success }

it "creates a shipment" do
expect { interactor }.to change(Shipment, :count).by(1)
end
end
end
end
31 changes: 31 additions & 0 deletions spec/organizers/store_quotient_familial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,41 @@
let(:interactors) do
[
UploadQuotientFamilialToHubEE,
CreateShipment,
]
end
jbfeldis marked this conversation as resolved.
Show resolved Hide resolved

it "setups the folder, sends it to HubEE and cleans afterwards" do
expect(described_class).to organize interactors
end

describe ".call" do
subject(:organizer) { described_class.call(**params) }

let(:folder) { build(:hubee_folder) }
let(:identity) { PivotIdentity.new(recipient:, auth: {info: {first_name: "David", last_name: "Heinemeier Hansson"}}) }
let(:recipient) { build(:hubee_recipient) }
let(:params) do
{
folder:,
identity:,
recipient:,
}
end

before do
allow(SecureRandom).to receive(:hex).and_return("abcdef1234567thiswontbeused")

stub_hubee_token
stub_hubee_create_folder
stub_hubee_upload_attachment
stub_hubee_mark_folder_complete
end

it { is_expected.to be_a_success }

it "creates a shipment" do
expect { organizer }.to change(Shipment, :count).by(1)
end
end
end