1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSubscriptions::ApplyTrialService do
subject(:execute) { described_class.new.execute(apply_trial_params) }
let_it_be(:namespace) { create(:namespace) }
let(:apply_trial_params) do
{
trial_user: {
namespace_id: namespace.id
}
}
end
describe '#execute' do
before do
allow(Gitlab::SubscriptionPortal::Client).to receive(:generate_trial).and_return(response)
end
context 'trial applied successfully' do
let(:response) { { success: true }}
it 'returns success: true' do
expect(execute).to eq({ success: true })
end
it_behaves_like 'records an onboarding progress action', :trial_started
end
context 'error while applying the trial' do
let(:response) { { success: false, data: { errors: ['some error'] } }}
it 'returns success: false with errors' do
expected_response = {
success: false,
errors: ['some error']
}
expect(execute).to eq(expected_response)
end
it_behaves_like 'does not record an onboarding progress action'
end
end
end