-
Notifications
You must be signed in to change notification settings - Fork 161
Assembla Deep Integration: Travis API Endpoint #1380
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
Merged
mshahzaib-travis
merged 15 commits into
prd-asm_integration_dev
from
TBT-381-assembla-jwt-login-endpoint
Aug 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
447f8e3
[TBT-381] Integrated assembla JWT login endpoint
1934be6
[TBT-381] Fixed assembla spec
mshahzaib-travis e461de2
[TBT-381] Fixed build failure Env issue
mshahzaib-travis 0526c13
[TBT-381] Create beta_plan for org
mshahzaib-travis 7b5948a
[TBT-381] - Sync and Create Subscription
mshahzaib-travis ab5b727
[TBT-381] Feedback incorporated
mshahzaib-travis a1bf5c3
[TBT-381] Feedback incorporated
mshahzaib-travis 1a2c602
[TBT-381] used default values in spec
mshahzaib-travis 5f79e3b
[TBT-381] changed config to use array
mshahzaib-travis fb82a6a
Sync only passed space and repository
daaafb7
[TBT-382] specs fixed
mshahzaib-travis db9cadb
Generated access token
mshahzaib-travis bf4eb60
Confirm user and fix spec
mshahzaib-travis 65a72ca
Fixed membership admin
mshahzaib-travis e4227ba
Merge pull request #1385 from travis-ci/TBT-382-sync-org-and-repo
mshahzaib-travis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
require 'spec_helper' | ||
require 'factory_bot' | ||
mshahzaib-travis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
RSpec.describe Travis::Services::AssemblaUserService do | ||
let(:payload) do | ||
{ | ||
'id' => '12345', | ||
'name' => 'Test User', | ||
'email' => '[email protected]', | ||
'login' => 'testuser', | ||
'refresh_token' => 'refresh123', | ||
|
@@ -12,39 +14,30 @@ | |
end | ||
|
||
let(:service) { described_class.new(payload) } | ||
let(:user) { double('User', id: 1, login: 'testuser', email: '[email protected]', name: 'Test User') } | ||
let(:organization) { double('Organization', id: 2) } | ||
|
||
describe '#initialize' do | ||
it 'stores the payload' do | ||
expect(service.instance_variable_get(:@payload)).to eq(payload) | ||
end | ||
end | ||
let(:user) { FactoryBot.create(:user, vcs_id: payload['id'], email: payload['email'], login: payload['login'], name: payload['name']) } | ||
let(:organization) { FactoryBot.create(:org, vcs_id: payload['space_id'], vcs_type: 'AssemblaOrganization') } | ||
|
||
describe '#find_or_create_user' do | ||
let(:expected_attrs) do | ||
{ | ||
vcs_id: '12345', | ||
email: '[email protected]', | ||
login: 'testuser', | ||
vcs_id: payload['id'], | ||
email: payload['email'], | ||
name: payload['name'], | ||
login: payload['login'], | ||
vcs_type: 'AssemblaUser' | ||
} | ||
end | ||
|
||
before do | ||
allow(::User).to receive(:find_or_create_by!).with(expected_attrs).and_return(user) | ||
allow(user).to receive(:update) | ||
allow(Travis::RemoteVCS::User).to receive(:new).and_return(double(sync: true)) | ||
end | ||
|
||
it 'finds or creates a user with correct attributes' do | ||
expect(::User).to receive(:find_or_create_by!).with(expected_attrs) | ||
service.find_or_create_user | ||
end | ||
|
||
it 'returns the user' do | ||
result = service.find_or_create_user | ||
expect(result).to eq(user) | ||
service_user = service.find_or_create_user | ||
expect(service_user.login).to eq(expected_attrs[:login]) | ||
expect(service_user.email).to eq(expected_attrs[:email]) | ||
expect(service_user.name).to eq(expected_attrs[:name]) | ||
expect(service_user.vcs_id).to eq(expected_attrs[:vcs_id]) | ||
end | ||
|
||
context 'when sync fails' do | ||
|
@@ -60,60 +53,26 @@ | |
end | ||
|
||
describe '#find_or_create_organization' do | ||
let(:organizations_relation) { double('organizations') } | ||
let(:expected_attrs) do | ||
{ | ||
vcs_id: '67890', | ||
vcs_id: payload['space_id'], | ||
vcs_type: 'AssemblaOrganization' | ||
} | ||
end | ||
|
||
before do | ||
allow(user).to receive(:organizations).and_return(organizations_relation) | ||
end | ||
|
||
it 'finds or creates organization with correct attributes' do | ||
expect(organizations_relation).to receive(:find_or_create_by).with(expected_attrs).and_return(organization) | ||
service_org = service.find_or_create_organization(user) | ||
|
||
result = service.find_or_create_organization(user) | ||
expect(result).to eq(organization) | ||
expect(service_org.vcs_type).to eq(expected_attrs[:vcs_type]) | ||
expect(service_org.vcs_id).to eq(expected_attrs[:vcs_id]) | ||
end | ||
end | ||
|
||
describe '#create_org_subscription' do | ||
let(:billing_client) { double('BillingClient') } | ||
let(:expected_subscription_params) do | ||
{ | ||
'plan' => 'beta_plan', | ||
'organization_id' => 2, | ||
'billing_info' => { | ||
'address' => 'System-generated for user testuser (1)', | ||
'city' => 'AutoCity-1', | ||
'country' => 'Poland', | ||
'first_name' => 'Test', | ||
'last_name' => 'User', | ||
'zip_code' => '0001', | ||
'billing_email' => '[email protected]' | ||
}, | ||
'credit_card_info' => { 'token' => nil } | ||
} | ||
end | ||
|
||
before do | ||
allow(Travis::API::V3::BillingClient).to receive(:new).with(1).and_return(billing_client) | ||
end | ||
|
||
it 'creates a billing client with user id' do | ||
expect(Travis::API::V3::BillingClient).to receive(:new).with(1) | ||
allow(billing_client).to receive(:create_v2_subscription) | ||
|
||
service.create_org_subscription(user, 2) | ||
end | ||
|
||
it 'calls create_v2_subscription with correct params' do | ||
expect(billing_client).to receive(:create_v2_subscription).with(expected_subscription_params) | ||
|
||
service.create_org_subscription(user, 2) | ||
allow(Travis::API::V3::BillingClient).to receive(:new).with(user.id).and_return(billing_client) | ||
end | ||
|
||
context 'when billing client raises an error' do | ||
|
@@ -122,23 +81,10 @@ | |
it 'returns error hash' do | ||
allow(billing_client).to receive(:create_v2_subscription).and_raise(error) | ||
|
||
result = service.create_org_subscription(user, 2) | ||
expect(result).to eq({ error: true, details: 'Billing error' }) | ||
end | ||
end | ||
|
||
context 'when user has no name' do | ||
let(:user_without_name) { double('User', id: 1, login: 'testuser', email: '[email protected]', name: nil) } | ||
|
||
it 'handles nil name gracefully' do | ||
expected_params = expected_subscription_params.dup | ||
expected_params['billing_info']['first_name'] = nil | ||
expected_params['billing_info']['last_name'] = nil | ||
|
||
expect(billing_client).to receive(:create_v2_subscription).with(expected_params) | ||
|
||
service.create_org_subscription(user_without_name, 2) | ||
result = service.create_org_subscription(user, organization.id) | ||
expect(result[:error]).to be_truthy | ||
expect(result[:details]).to be_present | ||
mshahzaib-travis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
end | ||
end | ||
end | ||
mshahzaib-travis marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.