Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Gate a seller's approval on the marketplace's checklist
Damian Legawiec0b6a666874b7
diff --git a/spree/core/app/models/spree/seller.rb b/spree/core/app/models/spree/seller.rbindex de5087660c..4471a5de6a 100644--- a/spree/core/app/models/spree/seller.rb+++ b/spree/core/app/models/spree/seller.rb@@ -97,6 +97,12 @@ module Spree# be worse than no record at all.has_many :commission_lines, class_name: 'Spree::CommissionLine', dependent: nil+ # What this seller has done about the marketplace's requirements — their+ # attestations, the documents they uploaded, what the operator made of+ # them. Goes with the seller, since it means nothing without them.+ has_many :requirement_submissions, class_name: 'Spree::SellerRequirementSubmission',+ dependent: :destroy, inverse_of: :seller+## Attachments#@@ -160,6 +166,61 @@ module Spreeterms_accepted_at.present?end+ # How many products this seller lists. Memoized because two readers ask+ # on every list row — the operator's column and the minimum-products+ # requirement — and a catalog is the one thing here that can run to+ # thousands, so it is counted in SQL once rather than loaded or counted+ # twice.+ #+ # @return [Integer]+ def products_count+ @products_count ||= products.count+ end++ # Where this seller stands against the marketplace's checklist+ # (docs/plans/6.0-seller-onboarding-requirements.md), for the operator's+ # views of them. Computed on read, never stored: a column would be wrong+ # the moment a product was deleted or a document sent back.+ #+ # Memoized per instance, like the store's own setup checklist: one seller+ # page reads it several times — the badge, the bar, the list.+ #+ # Reads the store's checklist off its loaded association when the store+ # was eager-loaded with it (the admin list and profile do), so a page of+ # sellers loads the rows once; a seller reached any other way queries.+ #+ # @return [Array<Spree::SellerRequirementStatus>]+ def onboarding_requirements+ @onboarding_requirements ||= Spree::Sellers::Requirements.new(+ self, preloaded: store&.association(:seller_requirements)&.loaded? || false+ ).statuses+ end++ # @return [Hash{Symbol => Integer}] done, total and percentage over the+ # whole checklist, optional requirements included+ def onboarding_progress+ @onboarding_progress ||= Spree::Sellers::Requirements.progress_of(onboarding_requirements)+ end++ # @return [Integer] 0..100+ def onboarding_percentage+ onboarding_progress[:percentage]+ end++ # @return [Boolean] whether nothing required is outstanding+ def onboarding_complete?+ onboarding_requirements.none?(&:blocking?)+ end++ # Drops the memoized checklist with the rest of the instance's state, so a+ # flow that changes something and re-reads within one request sees it.+ def reload(options = nil)+ @onboarding_requirements = nil+ @onboarding_progress = nil+ @products_count = nil+ super+ end+privatedef normalize_slugdiff --git a/spree/core/app/subscribers/spree/seller_onboarding_subscriber.rb b/spree/core/app/subscribers/spree/seller_onboarding_subscriber.rbnew file mode 100644index 0000000000..6d72b55f7e--- /dev/null+++ b/spree/core/app/subscribers/spree/seller_onboarding_subscriber.rb@@ -0,0 +1,32 @@+# frozen_string_literal: true++module Spree+ # Opens onboarding when someone accepts an invitation to run a seller.+ #+ # Acceptance is the moment a seller becomes a business with a person behind+ # it, and it happens on the shared invitation path rather than anywhere+ # marketplace-specific — so the seller's own lifecycle picks it up from the+ # event rather than the invitation flow having to know about sellers.+ class SellerOnboardingSubscriber < Spree::Subscriber+ # Synchronous: the person who just accepted is being sent straight into+ # the seller panel, and it has to find them `onboarding` on arrival — a+ # job that runs a moment later would show them a checklist they cannot+ # yet submit. The transition itself is one row update, so there is no+ # queue worth of work to defer.+ subscribes_to 'invitation.accepted', async: false++ on 'invitation.accepted', :start_seller_onboarding++ private++ def start_seller_onboarding(event)+ invitation = Spree::Invitation.find_by_prefix_id(event.payload['id'])+ return if invitation.nil?++ seller = invitation.resource+ return unless seller.is_a?(Spree::Seller)++ Spree::Sellers::StartOnboarding.call(seller: seller)+ end+ end+enddiff --git a/spree/core/app/workflows/spree/sellers/approve.rb b/spree/core/app/workflows/spree/sellers/approve.rbindex 087e7b623e..e6888da028 100644--- a/spree/core/app/workflows/spree/sellers/approve.rb+++ b/spree/core/app/workflows/spree/sellers/approve.rb@@ -5,12 +5,21 @@ module Spreeclass Approve < Spree::Workflowhooks :validate, :after_approve+ # Requirement statuses that were outstanding at approval — empty+ # unless the operator overrode them.+ # @return [Array<Spree::SellerRequirementStatus>]+ attr_reader :unmet_requirements+# @param seller [Spree::Seller]# @param approver [Object, nil] the staff member approving- def perform(seller:, approver: nil)+ # @param override_requirements [Boolean] admit the seller even though+ # the marketplace's checklist is not finished — the operator's+ # deliberate exception, recorded on the event+ def perform(seller:, approver: nil, override_requirements: false)superstep :ensure_approvable+ step :ensure_requirements_metrun_hooks :validateApplicationRecord.transaction do@@ -18,7 +27,9 @@ module Spreeendrun_hooks :after_approve- seller.publish_event('seller.approved')+ seller.publish_event('seller.approved', nil,+ requirements_overridden: override_requirements,+ unmet_requirements: unmet_requirement_names)success(seller.reload)end@@ -33,6 +44,39 @@ module Spreefailure(seller, :not_approvable)end+ # The checklist gates admission, and the operator can step over it —+ # they know things about a seller the marketplace never asked for. What+ # they cannot do is step over it without saying so, which is what makes+ # the override worth recording on the event.+ #+ # A suspended seller being reinstated is not re-measured: they were+ # admitted once, and lifting a suspension undoes that decision rather+ # than making it again.+ #+ # A rejected seller is the opposite case, even though both are+ # "reinstatements" in the loose sense: Sellers::Reject refuses an+ # approved seller outright, so every rejected seller is an applicant+ # who was turned away before admission. Approving one is the original+ # decision, and skipping the checklist for it would admit a seller with+ # unmet requirements while the event recorded no override.+ def ensure_requirements_met+ @unmet_requirements = []+ return if seller.suspended?++ requirements = Spree::Sellers::Requirements.new(seller)+ @unmet_requirements = requirements.blocking+ return if unmet_requirements.empty?+ return if override_requirements++ requirements.record_blocking(errors)+ failure(seller, errors)+ end++ # @return [Array<String>]+ def unmet_requirement_names+ Array(unmet_requirements).map(&:name)+ end+# Lifting a suspension clears the holiday with it: a seller coming back# is coming back to sell, and leaving them invisible would look like the# approval had not worked.diff --git a/spree/core/app/workflows/spree/sellers/reopen_onboarding.rb b/spree/core/app/workflows/spree/sellers/reopen_onboarding.rbnew file mode 100644index 0000000000..86c8d656a5--- /dev/null+++ b/spree/core/app/workflows/spree/sellers/reopen_onboarding.rb@@ -0,0 +1,55 @@+module Spree+ module Sellers+ # Sends a seller back to onboarding: the operator looked at them and+ # something has to be redone.+ #+ # Distinct from Reject, which turns a seller away. This one expects them+ # back, which is why it carries a note — a seller told only "not yet" has+ # nothing to act on.+ class ReopenOnboarding < Spree::Workflow+ hooks :validate, :after_reopen++ # @param seller [Spree::Seller]+ # @param note [String, nil] what the seller has to fix+ # @param reopened_by [Object, nil] the staff member sending it back+ def perform(seller:, note: nil, reopened_by: nil)+ super++ step :ensure_reopenable+ run_hooks :validate++ ApplicationRecord.transaction do+ step :mark_onboarding+ end++ run_hooks :after_reopen+ seller.publish_event('seller.onboarding_reopened')+ success(seller.reload)+ end++ private++ # Only a seller waiting on the operator can be sent back. One already+ # approved is suspended instead, which says the right thing to the+ # shopper as well as to the seller.+ def ensure_reopenable+ return if seller.ready_for_review?++ failure(seller, :not_reopenable)+ end++ def mark_onboarding+ seller.update!(status: 'onboarding')+ record_note+ end++ # A note about one decision, replaced by the next one — metadata rather+ # than a column, like the suspension reason beside it.+ def record_note+ return if note.blank?++ seller.update!(metadata: seller.metadata.to_h.merge('onboarding_reopened_note' => note))+ end+ end+ end+enddiff --git a/spree/core/app/workflows/spree/sellers/start_onboarding.rb b/spree/core/app/workflows/spree/sellers/start_onboarding.rbnew file mode 100644index 0000000000..accb48106a--- /dev/null+++ b/spree/core/app/workflows/spree/sellers/start_onboarding.rb@@ -0,0 +1,46 @@+module Spree+ module Sellers+ # Opens onboarding: the seller now has someone who can sign in and work+ # through the marketplace's requirements.+ #+ # Run when an invitation to a seller's team is accepted, which is the+ # moment the seller stops being a record the operator created and starts+ # being a business doing something about it.+ class StartOnboarding < Spree::Workflow+ hooks :validate, :after_start_onboarding++ # @param seller [Spree::Seller]+ def perform(seller:)+ super++ step :ensure_startable+ run_hooks :validate++ ApplicationRecord.transaction do+ step :mark_onboarding+ end++ run_hooks :after_start_onboarding+ seller.publish_event('seller.onboarding_started')+ success(seller.reload)+ end++ private++ # A seller already working through their checklist is left alone rather+ # than refused: a second teammate accepting an invitation must not read+ # as an error, and it must not reset anything either.+ def ensure_startable+ halt!(seller) if seller.onboarding?++ return if seller.pending? || seller.invited?++ failure(seller, :not_startable)+ end++ def mark_onboarding+ seller.update!(status: 'onboarding')+ end+ end+ end+enddiff --git a/spree/core/app/workflows/spree/sellers/submit_for_review.rb b/spree/core/app/workflows/spree/sellers/submit_for_review.rbnew file mode 100644index 0000000000..1a0a941cbc--- /dev/null+++ b/spree/core/app/workflows/spree/sellers/submit_for_review.rb@@ -0,0 +1,76 @@+module Spree+ module Sellers+ # The seller says they are ready. One of the two places the onboarding+ # checklist is enforced (docs/plans/6.0-seller-onboarding-requirements.md);+ # the other is Spree::Sellers::Approve.+ #+ # A marketplace that trusts its checklist can let this approve outright —+ # the `auto_approve_sellers` store preference — which is what turns the+ # checklist from a queue for the operator into the admission decision.+ class SubmitForReview < Spree::Workflow+ hooks :validate, :after_submit++ # Requirement statuses that stood in the way, for hook handlers and+ # for the caller rendering the refusal.+ # @return [Array<Spree::SellerRequirementStatus>]+ attr_reader :blocking_requirements++ # @param seller [Spree::Seller]+ # @param submitted_by [Object, nil] the seller's own staff member+ def perform(seller:, submitted_by: nil)+ super++ step :ensure_submittable+ step :ensure_requirements_met+ run_hooks :validate++ ApplicationRecord.transaction do+ step :mark_ready_for_review+ end++ run_hooks :after_submit+ seller.publish_event('seller.submitted_for_review')++ # Approval is its own workflow with its own mail and hooks, so+ # automatic admission runs it rather than reproducing it — and does so+ # outside this workflow's transaction, since approving is not part of+ # submitting and must not roll it back.+ return step :auto_approve if auto_approve?++ success(seller.reload)+ end++ private++ def ensure_submittable+ failure(seller, :already_submitted) if seller.ready_for_review?+ failure(seller, :already_approved) if seller.approved?++ return if seller.onboarding?++ failure(seller, :not_submittable)+ end++ def ensure_requirements_met+ requirements = Spree::Sellers::Requirements.new(seller)+ @blocking_requirements = requirements.blocking+ return if blocking_requirements.empty?++ requirements.record_blocking(errors)+ failure(seller, errors)+ end++ def mark_ready_for_review+ seller.update!(status: 'ready_for_review')+ end++ def auto_approve?+ seller.store&.preferred_auto_approve_sellers.present?+ end++ def auto_approve+ Spree::Sellers::Approve.call(seller: seller.reload, approver: nil)+ end+ end+ end+enddiff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.ymlindex a8658f5792..883726ed3d 100644--- a/spree/core/config/locales/en.yml+++ b/spree/core/config/locales/en.yml@@ -907,6 +907,7 @@ en:invalid_order_routing_rule: is not a registered order routing ruleinvalid_order_routing_strategy: is not a registered order routing strategyinvalid_refund_method: must be one of original_payment, store_credit+ invalid_seller_requirement: is not a registered seller requirementinvalid_storefront_access: is not a valid storefront access levelmust_be_greater_than_min_amount: must be greater than or equal to the minimummust_be_origin_only: must be an origin (scheme and host) without path, query, or fragment@@ -921,6 +922,7 @@ en:promotion_discount_not_editable: promotion discounts are managed by recalculation and cannot be editedrate_provider_requires_shipping: "%{provider} quotes shipments, so this method must ship to an address"rate_provider_unavailable: is not available for this store — connect its integration first+ seller_requirement_store_mismatch: must belong to the same store as the sellerstore_association_can_not_be_changed: The store association can not be changedstore_is_already_set: Store is already setservices:@@ -1521,6 +1523,38 @@ en:message: Selling on %{store_name} has been paused for your account. Your products and order history are unaffected.subject: Your %{store_name} account has been suspendedseller_membership_required: This account does not belong to any seller.+ seller_requirement_types:+ accept_terms:+ description: The seller has accepted your marketplace terms+ name: Accept terms+ attestation:+ description: Something you ask the seller to confirm themselves+ name: Seller confirmation+ billing_address:+ description: The seller has given a billing address+ name: Billing address+ complete_profile:+ description: The seller has filled in their public profile+ name: Complete profile+ document:+ description: A file the seller uploads and you review+ name: Document+ minimum_products:+ description: The seller has listed at least this many products+ name: Minimum products+ operator_review:+ description: Something you check by hand before admitting the seller+ name: Manual check+ required_custom_fields:+ description: The seller has filled in the custom fields you ask for+ name: Required custom fields+ returns_address:+ description: The seller has given an address for customer returns+ name: Returns address+ seller_requirements:+ file_required: A file is required for this requirement+ file_type_not_accepted: This requirement accepts %{types}+ incomplete: "%{name} is not complete"send_consumer_transactional_emails: Send Customer Transactional Emailsseo: SEOseo_title: SEO Titlediff --git a/spree/core/lib/spree/core/dependencies.rb b/spree/core/lib/spree/core/dependencies.rbindex 185aa41a0f..d040b0da2d 100644--- a/spree/core/lib/spree/core/dependencies.rb+++ b/spree/core/lib/spree/core/dependencies.rb@@ -110,6 +110,13 @@ module Spreeseller_approve_workflow: 'Spree::Sellers::Approve',seller_suspend_workflow: 'Spree::Sellers::Suspend',seller_reject_workflow: 'Spree::Sellers::Reject',+ seller_start_onboarding_workflow: 'Spree::Sellers::StartOnboarding',+ seller_submit_for_review_workflow: 'Spree::Sellers::SubmitForReview',+ seller_reopen_onboarding_workflow: 'Spree::Sellers::ReopenOnboarding',+ seller_requirement_submission_create_workflow: 'Spree::SellerRequirementSubmissions::Create',+ seller_requirement_submission_accept_workflow: 'Spree::SellerRequirementSubmissions::Accept',+ seller_requirement_submission_reject_workflow: 'Spree::SellerRequirementSubmissions::Reject',+ seller_requirement_submission_waive_workflow: 'Spree::SellerRequirementSubmissions::Waive',# commissions — what a marketplace charges its sellers. Swappable# because the pricing of a marketplace's own service is exactly thediff --git a/spree/core/spec/models/spree/seller_spec.rb b/spree/core/spec/models/spree/seller_spec.rbindex 2bd6b073f9..1a8c327173 100644--- a/spree/core/spec/models/spree/seller_spec.rb+++ b/spree/core/spec/models/spree/seller_spec.rb@@ -236,4 +236,49 @@ describe Spree::Seller doexpect(Spree::Invitation.where(resource: seller)).to be_emptyendend++ describe 'onboarding progress' do+ let(:store) { @default_store }+ let(:seller) { create(:seller, :onboarding, store: store) }++ before { store.seller_requirements.destroy_all }++ it 'reads as finished when the marketplace asks for nothing' do+ expect(seller.onboarding_percentage).to eq(100)+ expect(seller).to be_onboarding_complete+ end++ it 'counts what is done over what is asked' do+ create(:accept_terms_requirement, store: store)+ create(:billing_address_requirement, store: store)+ seller.update!(terms_accepted_at: Time.current)++ seller.reload+ expect(seller.onboarding_progress).to eq(done: 1, total: 2, percentage: 50)+ expect(seller.onboarding_percentage).to eq(50)+ expect(seller).not_to be_onboarding_complete+ end++ it 'is complete once every required requirement is met, whatever the optional ones say' do+ create(:accept_terms_requirement, store: store, required: true)+ create(:billing_address_requirement, store: store, required: false)+ seller.update!(terms_accepted_at: Time.current)++ seller.reload+ expect(seller).to be_onboarding_complete+ expect(seller.onboarding_percentage).to eq(50)+ end++ it 'forgets what it computed on reload' do+ create(:accept_terms_requirement, store: store)+ seller.reload+ expect(seller.onboarding_percentage).to eq(0)++ seller.update!(terms_accepted_at: Time.current)+ seller.reload++ expect(seller.onboarding_percentage).to eq(100)+ end+ end+enddiff --git a/spree/core/spec/workflows/spree/sellers/approve_requirements_spec.rb b/spree/core/spec/workflows/spree/sellers/approve_requirements_spec.rbnew file mode 100644index 0000000000..315d0e2d09--- /dev/null+++ b/spree/core/spec/workflows/spree/sellers/approve_requirements_spec.rb@@ -0,0 +1,77 @@+require 'spec_helper'++RSpec.describe Spree::Sellers::Approve, 'onboarding requirements' do+ let(:store) { @default_store }+ let(:seller) { create(:seller, :onboarding, store: store) }++ before { store.seller_requirements.destroy_all }++ it 'refuses while something required is unmet' do+ create(:accept_terms_requirement, store: store)++ result = described_class.call(seller: seller)++ expect(result).to be_failure+ expect(result.error.value.full_messages.join).to include('Accept terms')+ expect(seller.reload).not_to be_approved+ end++ it 'lets the operator step over it deliberately' do+ create(:accept_terms_requirement, store: store)++ result = described_class.call(seller: seller, override_requirements: true)++ expect(result).to be_success+ expect(seller.reload).to be_approved+ end++ it 'announces what was outstanding when the operator overrode it' do+ create(:accept_terms_requirement, store: store)+ workflow = described_class.new+ published = nil+ allow(seller).to receive(:publish_event) do |name, _payload, metadata|+ published = metadata if name == 'seller.approved'+ end++ workflow.perform(seller: seller, override_requirements: true)++ expect(published[:requirements_overridden]).to be true+ expect(published[:unmet_requirements]).to include('Accept terms')+ end++ it 'goes through with no override once the checklist is done' do+ create(:accept_terms_requirement, store: store)+ seller.update!(terms_accepted_at: Time.current)++ expect(described_class.call(seller: seller.reload)).to be_success+ end++ # Sellers::Reject refuses an approved seller, so a rejected one is always an+ # applicant who never got in. Approving them is the original admission+ # decision, not the undoing of one.+ it 'measures a rejected applicant, who was never admitted in the first place' do+ create(:accept_terms_requirement, store: store)+ rejected = create(:seller, store: store, status: 'rejected')++ result = described_class.call(seller: rejected)++ expect(result).to be_failure+ expect(rejected.reload).not_to be_approved+ end++ it 'lets the operator override a rejected applicant deliberately' do+ create(:accept_terms_requirement, store: store)+ rejected = create(:seller, store: store, status: 'rejected')++ expect(described_class.call(seller: rejected, override_requirements: true)).to be_success+ expect(rejected.reload).to be_approved+ end++ it 'does not re-measure a suspended seller being reinstated' do+ create(:accept_terms_requirement, store: store)+ suspended = create(:seller, :suspended, store: store)++ expect(described_class.call(seller: suspended)).to be_success+ expect(suspended.reload).to be_approved+ end+enddiff --git a/spree/core/spec/workflows/spree/sellers/onboarding_lifecycle_spec.rb b/spree/core/spec/workflows/spree/sellers/onboarding_lifecycle_spec.rbnew file mode 100644index 0000000000..aed22636cc--- /dev/null+++ b/spree/core/spec/workflows/spree/sellers/onboarding_lifecycle_spec.rb@@ -0,0 +1,75 @@+require 'spec_helper'++RSpec.describe 'seller onboarding lifecycle' do+ let(:store) { @default_store }++ describe Spree::Sellers::StartOnboarding do+ it 'opens onboarding for an invited seller' do+ seller = create(:seller, store: store, status: 'invited')++ expect(described_class.call(seller: seller)).to be_success+ expect(seller.reload).to be_onboarding+ end++ it 'leaves a seller already onboarding alone rather than erroring' do+ seller = create(:seller, :onboarding, store: store)++ expect(described_class.call(seller: seller)).to be_success+ expect(seller.reload).to be_onboarding+ end++ it 'refuses a seller who is already trading' do+ seller = create(:seller, :approved, store: store)++ expect(described_class.call(seller: seller)).to be_failure+ end+ end++ describe Spree::Sellers::ReopenOnboarding do+ it 'sends a seller awaiting review back with a note' do+ seller = create(:seller, store: store, status: 'ready_for_review')++ result = described_class.call(seller: seller, note: 'Returns address is a PO box')++ expect(result).to be_success+ expect(seller.reload).to be_onboarding+ expect(seller.metadata['onboarding_reopened_note']).to eq('Returns address is a PO box')+ end++ it 'refuses a seller who is not awaiting review' do+ seller = create(:seller, :approved, store: store)++ expect(described_class.call(seller: seller)).to be_failure+ end+ end++ describe 'accepting an invitation to a seller' do+ it 'opens onboarding' do+ seller = create(:seller, store: store, status: 'invited')+ invitation = create(:invitation, resource: seller, role: seller.default_user_role)++ Spree::SellerOnboardingSubscriber.new.send(+ :start_seller_onboarding,+ instance_double(Spree::Event, payload: { 'id' => invitation.prefixed_id })+ )++ expect(seller.reload).to be_onboarding+ end++ # Through the real event bus, with the subscribers the engine registers:+ # calling the handler directly proves the handler, not that anything ever+ # calls it. This is the difference between the flow working in a spec and+ # working in a running marketplace.+ it 'opens onboarding through the event the acceptance publishes', events: true do+ seller = create(:seller, store: store, status: 'invited')+ invitee = create(:admin_user, :without_admin_role)+ invitation = create(:invitation, resource: seller, email: invitee.email,+ role: seller.default_user_role)++ invitation.update!(invitee: invitee)+ invitation.accept!++ expect(seller.reload).to be_onboarding+ end+ end+enddiff --git a/spree/core/spec/workflows/spree/sellers/submit_for_review_spec.rb b/spree/core/spec/workflows/spree/sellers/submit_for_review_spec.rbnew file mode 100644index 0000000000..ddf44cccae--- /dev/null+++ b/spree/core/spec/workflows/spree/sellers/submit_for_review_spec.rb@@ -0,0 +1,58 @@+require 'spec_helper'++RSpec.describe Spree::Sellers::SubmitForReview do+ let(:store) { @default_store }+ let(:seller) { create(:seller, :onboarding, store: store) }++ before { store.seller_requirements.destroy_all }++ it 'refuses while a required requirement is unmet, and says which' do+ create(:accept_terms_requirement, store: store)++ result = described_class.call(seller: seller)++ expect(result).to be_failure+ expect(result.error.value.full_messages.join).to include('Accept terms')+ expect(seller.reload).to be_onboarding+ end++ it 'ignores optional requirements' do+ create(:accept_terms_requirement, store: store, required: false)++ result = described_class.call(seller: seller)++ expect(result).to be_success+ expect(seller.reload).to be_ready_for_review+ end++ it 'goes through once every required requirement is met' do+ create(:accept_terms_requirement, store: store)+ seller.update!(terms_accepted_at: Time.current)++ result = described_class.call(seller: seller.reload)++ expect(result).to be_success+ expect(seller.reload).to be_ready_for_review+ end++ it 'refuses a seller who is not onboarding' do+ approved = create(:seller, :approved, store: store)++ expect(described_class.call(seller: approved)).to be_failure+ end++ it 'admits the seller outright when the marketplace asks it to' do+ stub_store_preferences(store, auto_approve_sellers: true)++ expect(described_class.call(seller: seller)).to be_success+ expect(seller.reload).to be_approved+ end++ it 'does not admit outright while something required is missing' do+ stub_store_preferences(store, auto_approve_sellers: true)+ create(:accept_terms_requirement, store: store)++ expect(described_class.call(seller: seller)).to be_failure+ expect(seller.reload).to be_onboarding+ end+end