Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Cover both sides of invitation acceptance in the store controller spec

Damian Legawiecc664538ba64c
diff --git a/spree/api/spec/controllers/spree/api/v3/store/company_invitations_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/store/company_invitations_controller_spec.rb
index 1a964bb5e6..24661eeee6 100644
--- a/spree/api/spec/controllers/spree/api/v3/store/company_invitations_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/store/company_invitations_controller_spec.rb
@@ -71,13 +71,25 @@ RSpec.describe Spree::Api::V3::Store::CompanyInvitationsController, type: :contr
context 'authenticated' do
before { request.headers.merge!(bearer_headers) }
- it 'binds the invitation to the signed-in customer' do
+ it 'binds the invitation to the customer it was addressed to' do
+ invitation.update!(email: user.email)
+
post :accept, params: { token: invitation.token }, as: :json
expect(response).to have_http_status(:created)
expect(invitation.reload.customer).to eq(user)
expect(company.memberships.sole.customer).to eq(user)
end
+
+ # The token names one person: spending it from an unrelated signed-in
+ # account would hand that account standing over the company.
+ it 'refuses when the signed-in customer owns a different email' do
+ post :accept, params: { token: invitation.token }, as: :json
+
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(invitation.reload).to be_pending
+ expect(company.memberships.reload).to be_empty
+ end
end
it '422s a spent token' do