OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Implement trial status checks
Oliver Güntherfcb8f8e3be5d
diff --git a/app/components/enterprise_trials/dialog_component.rb b/app/components/enterprise_trials/dialog_component.rbindex 2f4df3c4f7c..31ec95920d0 100644--- a/app/components/enterprise_trials/dialog_component.rb+++ b/app/components/enterprise_trials/dialog_component.rb@@ -1,4 +1,5 @@# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/app/components/enterprise_trials/form_component.rb b/app/components/enterprise_trials/form_component.rbindex 01ae64d70ce..023695a89f8 100644--- a/app/components/enterprise_trials/form_component.rb+++ b/app/components/enterprise_trials/form_component.rb@@ -1,4 +1,5 @@# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/app/components/enterprise_trials/status_component.html.erb b/app/components/enterprise_trials/status_component.html.erbindex ca61b894446..1c207f04e2b 100644--- a/app/components/enterprise_trials/status_component.html.erb+++ b/app/components/enterprise_trials/status_component.html.erb@@ -1,3 +1,34 @@-<% if @trial_status %>- <%= @trial_status.inspect %>+<% if @trial_key %>+ <%= I18n.t("ee.trial.confirmation_info",+ date: helpers.format_date(@trial_key.created_at),+ email: @trial_key.data[:email],+ ) %>++ <%=+ flex_layout do |flex|+ flex.with_row(flex_layout: true, align_items: :center) do |row|+ row.with_column do+ render Primer::Beta::Button.new(+ tag: :a,+ href: request_resend_enterprise_trial_path,+ data: { turbo_method: :post },+ ) do+ I18n.t("ee.trial.resend_action")+ end+ end++ row.with_column(ml: 1) do+ render Primer::Beta::Button.new(+ tag: :a,+ href: trial_dialog_enterprise_trial_path,+ data: { turbo_stream: true },+ ) do+ I18n.t("ee.trial.start_over")+ end+ end+ end+ end+ %>+<% else %>+ <%= render EnterpriseTrials::TrialButtonComponent.new %><% end %>diff --git a/app/components/enterprise_trials/status_component.rb b/app/components/enterprise_trials/status_component.rbindex 0e6b5ab19e2..f97618efa8d 100644--- a/app/components/enterprise_trials/status_component.rb+++ b/app/components/enterprise_trials/status_component.rb@@ -1,4 +1,5 @@# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -34,15 +35,10 @@ module EnterpriseTrialsinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- def initialize(trial_key)- @trial_key = trial_key- @trial_status = EnterpriseTrials::AugurLoadTrialService.new(@trial_key).call+ def initialize+ @trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)superend-- def render?- @trial_status.present?- endendenddiff --git a/app/components/enterprise_trials/trial_button_component.rb b/app/components/enterprise_trials/trial_button_component.rbindex f05cea3a3d9..5fa4a3f0ab7 100644--- a/app/components/enterprise_trials/trial_button_component.rb+++ b/app/components/enterprise_trials/trial_button_component.rb@@ -30,7 +30,6 @@module EnterpriseTrialsclass TrialButtonComponent < ApplicationComponent-def initialize@trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)@@ -46,7 +45,7 @@ module EnterpriseTrialsrender(Primer::Beta::Button.new(tag: :a,- href: enterprise_path+ href: enterprise_tokens_path)) doI18n.t("admin.enterprise.check_trial_status")@@ -63,6 +62,5 @@ module EnterpriseTrialsendendend-endenddiff --git a/app/contracts/enterprise_trials/create_contract.rb b/app/contracts/enterprise_trials/create_contract.rbindex a814728d575..9943e9a4c9b 100644--- a/app/contracts/enterprise_trials/create_contract.rb+++ b/app/contracts/enterprise_trials/create_contract.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/app/controllers/enterprise_tokens_controller.rb b/app/controllers/enterprise_tokens_controller.rbindex 9fa152ecdcf..bfd2ba15a3e 100644--- a/app/controllers/enterprise_tokens_controller.rb+++ b/app/controllers/enterprise_tokens_controller.rb@@ -37,7 +37,7 @@ class EnterpriseTokensController < ApplicationControllerbefore_action :require_adminbefore_action :check_user_limit, only: [:index]before_action :find_token, only: %i[destroy destroy_dialog]- before_action :get_trial_key, only: [:show]+ before_action :check_trial_status, only: [:index]def index# TODO: delete next line. @current_token is used in the old angular thingy.@@ -116,7 +116,24 @@ class EnterpriseTokensController < ApplicationControllerendend- def get_trial_key+ def check_trial_status@trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)+ return if @trial_key.nil?++ @trial_status = EnterpriseTrials::AugurLoadTrialService.new(@trial_key).call+ case @trial_status.result+ when EnterpriseTrials::AugurLoadTrialService::STATUS_WAITING_CONFIRMATION+ flash.now[:warning] = {+ message: @trial_status.message,+ action_button_arguments: {+ tag: :a,+ href: request_resend_enterprise_trial_path,+ data: { turbo_method: :post }+ },+ action_button_content: I18n.t("ee.trial.resend_action")+ }+ else+ @trial_status.apply_flash_message!(flash)+ endendenddiff --git a/app/controllers/enterprise_trials_controller.rb b/app/controllers/enterprise_trials_controller.rbindex 92580c32652..082f1c25d99 100644--- a/app/controllers/enterprise_trials_controller.rb+++ b/app/controllers/enterprise_trials_controller.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -30,23 +32,27 @@ class EnterpriseTrialsController < ApplicationControllerinclude OpTurbo::DialogStreamHelperbefore_action :require_admin- before_action :load_trial_details, only: %i[trial_status]+ before_action :load_trial_key, only: %i[request_resend]def trial_dialogrespond_with_dialog EnterpriseTrials::DialogComponent.new(EnterpriseTrial.new)end- def trial_status+ def request_resend+ EnterpriseTrials::AugurResendConfirmationService+ .new(@trial_key)+ .call+ redirect_to enterprise_tokens_path, status: :see_otherenddef createcall = EnterpriseTrials::CreateService- .new(user: current_user)- .call(trial_params)+ .new(user: current_user)+ .call(trial_params.to_h)if call.success?- redirect_to enterprise_path, status: :see_other+ redirect_to enterprise_tokens_path, status: :see_otherelseform_component = EnterpriseTrials::FormComponent.new(call.result)update_via_turbo_stream(component: form_component, status: :bad_request)@@ -56,13 +62,12 @@ class EnterpriseTrialsController < ApplicationControllerprivate- def load_trial_details- @trial_status = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)+ def load_trial_key+ @trial_key = Token::EnterpriseTrialKey.find_by!(user_id: User.system.id)enddef trial_paramsparams- .require(:enterprise_trial)- .permit(:company, :firstname, :lastname, :email, :general_consent, :newsletter_consent)+ .expect(enterprise_trial: %i[company firstname lastname email general_consent newsletter_consent])endenddiff --git a/app/forms/enterprise_trials/form.rb b/app/forms/enterprise_trials/form.rbindex 38faf487b72..9c78a134a40 100644--- a/app/forms/enterprise_trials/form.rb+++ b/app/forms/enterprise_trials/form.rb@@ -1,4 +1,5 @@# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/app/models/enterprise_trial.rb b/app/models/enterprise_trial.rbindex 7f3a3f4d282..d64d8b72e21 100644--- a/app/models/enterprise_trial.rb+++ b/app/models/enterprise_trial.rb@@ -40,12 +40,12 @@ class EnterpriseTrial < ApplicationRecordattribute :general_consent, :boolean, default: falseattribute :newsletter_consent, :boolean, default: false- validates_presence_of :company, :firstname, :lastname, :email+ validates :company, :firstname, :lastname, :email, presence: truevalidates :email, email: true, if: Proc.new { |data| data.email.present? }validate :accepted_terms- def to_json+ def to_h{company:,first_name: firstname,diff --git a/app/services/enterprise_trials/augur_create_trial_service.rb b/app/services/enterprise_trials/augur_create_trial_service.rbindex 6421442955d..719e4250a3b 100644--- a/app/services/enterprise_trials/augur_create_trial_service.rb+++ b/app/services/enterprise_trials/augur_create_trial_service.rb@@ -41,7 +41,7 @@ module EnterpriseTrialshandle_response(OpenProject.httpx.post(URI.join(augur_host, "/public/v1/trials"),- json: trial.to_json.merge(+ json: trial.to_h.merge(version: OpenProject::VERSION.to_semver,token_version: OpenProject::Token::VERSION,domain: Setting.host_name@@ -71,7 +71,8 @@ module EnterpriseTrialsreturn ServiceResult.failure(result: trial)end- trial_key = Token::EnterpriseTrialKey.create!(user_id: User.system.id, value:)+ data = { email: trial.email }+ trial_key = Token::EnterpriseTrialKey.create!(user_id: User.system.id, value:, data:)ServiceResult.success(result: trial_key)enddiff --git a/app/services/enterprise_trials/augur_load_trial_service.rb b/app/services/enterprise_trials/augur_load_trial_service.rbindex 33caddaab9b..3c73000d6f5 100644--- a/app/services/enterprise_trials/augur_load_trial_service.rb+++ b/app/services/enterprise_trials/augur_load_trial_service.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -28,6 +30,8 @@module EnterpriseTrialsclass AugurLoadTrialService+ STATUS_WAITING_CONFIRMATION = :awaiting_confirmation+def initialize(trial_key)@trial_key = trial_keyend@@ -50,7 +54,9 @@ module EnterpriseTrials@trial_key.destroyServiceResult.failure(message: I18n.t("ee.trial.not_found"))in { status: 422 }- ServiceResult.failure(message: I18n.t("ee.trial.wait_for_confirmation"))+ ServiceResult.failure(result: STATUS_WAITING_CONFIRMATION,+ message: I18n.t("ee.trial.wait_for_confirmation"),+ message_type: :warning)elseRails.logger.error { "Unexpected response from Augur: #{response.inspect}" }ServiceResult.failure(message: I18n.t("js.error.internal"))@@ -62,9 +68,11 @@ module EnterpriseTrialstoken = EnterpriseToken.new(encoded_token: trial_json["token"])if token.save@trial_key.destroy- return ServiceResult.success(result: token, message: I18n.t("ee.trial.already_retrieved"))+ return ServiceResult.success(result: token, message: I18n.t("ee.trial.successfully_saved"))else- return ServiceResult.failure(result: token)+ return ServiceResult.failure(result: token,+ message_type: :info,+ message: I18n.t("ee.trial.successfully_saved"))endenddiff --git a/app/services/enterprise_trials/delete_service.rb b/app/services/enterprise_trials/augur_resend_confirmation_service.rbsimilarity index 60%rename from app/services/enterprise_trials/delete_service.rbrename to app/services/enterprise_trials/augur_resend_confirmation_service.rbindex d0f2bfcc54d..66526b77783 100644--- a/app/services/enterprise_trials/delete_service.rb+++ b/app/services/enterprise_trials/augur_resend_confirmation_service.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -27,6 +29,35 @@#++module EnterpriseTrials- class DeleteService < BaseServices::Delete+ class AugurResendConfirmationService+ def initialize(trial_key)+ @trial_key = trial_key+ end++ def call+ handle_response(+ OpenProject.httpx.post(+ URI.join(augur_host, "/public/v1/trials/", @trial_key.value, "/resend")+ )+ )+ end++ private++ def handle_response(response)+ case response+ in { status: 202 }+ ServiceResult.success(result: nil)+ in { status: 404 }+ ServiceResult.failure(message: I18n.t("ee.trial.not_found"))+ else+ Rails.logger.error { "Unexpected response from Augur: #{response.inspect}" }+ ServiceResult.failure(message: I18n.t("js.error.internal"))+ end+ end++ def augur_host+ OpenProject::Configuration.enterprise_trial_creation_host+ endendenddiff --git a/app/services/enterprise_trials/create_service.rb b/app/services/enterprise_trials/create_service.rbindex 52534e6cb2c..6f94aea16e8 100644--- a/app/services/enterprise_trials/create_service.rb+++ b/app/services/enterprise_trials/create_service.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -28,7 +30,6 @@module EnterpriseTrialsclass CreateService < BaseServices::Create-def persist(call)trial = call.resultAugurCreateTrialService.new(trial).calldiff --git a/app/services/enterprise_trials/set_attributes_service.rb b/app/services/enterprise_trials/set_attributes_service.rbindex 85316708b91..f69a0d3120f 100644--- a/app/services/enterprise_trials/set_attributes_service.rb+++ b/app/services/enterprise_trials/set_attributes_service.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/app/views/enterprise_tokens/_info.html.erb b/app/views/enterprise_tokens/_info.html.erbindex 44aba244bfd..cba6073e4f0 100644--- a/app/views/enterprise_tokens/_info.html.erb+++ b/app/views/enterprise_tokens/_info.html.erb@@ -32,12 +32,7 @@ See COPYRIGHT and LICENSE files for more details.<% end %><div class="upsell--information-container">-- <% if @trial_key.present? %>- <%= render EnterpriseTrials::StatusComponent.new(@trial_key) %>- <% else %>- <%= render EnterpriseTrials::TrialButtonComponent.new %>- <% end %>+ <%= render EnterpriseTrials::StatusComponent.new %><div class='upsell-actions'><a href="#"diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 7ae050f1566..83b1d1b4bc2 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2189,9 +2189,15 @@ en:title: "Write internal comments only a small group can see"description: " "trial:- not_found: "The trial object could not be found."- wait_for_confirmation: "Waiting for email confirmation."- already_retrieved: "Trial token was already retrieved. Please reach out to our support team if you need a new one."+ not_found: "You have requested a trial token, but that request is no longer available. Please try again."+ wait_for_confirmation: "We sent you an email to confirm your address in order to retrieve a trial token."+ already_retrieved: "Your trial enterprise token was already retrieved. Please reach out to our support team if you need a new one."+ successfully_saved: "Your trial enterprise token has been successfully retrieved."+ start_over: "Start over trial request"+ resend_action: "Resend confirmation email"+ confirmation_info: >+ We sent you an email on %{date} to %{email}.+ Please check your inbox and click the confirmation link provided to start your 14 days trial.domain_caption:The token will be valid for your currently configured host name.receive_newsletter_html: >diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 8935b76f6e7..fa1f76e5da8 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -229,9 +229,6 @@ en:text_expired: "expired"trial:confirmation: "Confirmation of email address"- confirmation_info: >- We sent you an email on %{date} to %{email}.- Please check your inbox and click the confirmation link provided to start your 14 days trial.form:general_consent: >I agree with the <a target="_blank" href="%{link_terms}">terms of service</a>diff --git a/config/routes.rb b/config/routes.rbindex 16f7712a576..9310877d468 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -490,6 +490,7 @@ Rails.application.routes.draw doresource :enterprise_trial, only: %i[show create destroy] doget :trial_dialog+ post :request_resend, on: :collectionendenddiff --git a/spec/requests/enterprise_trials/enterprise_trials_spec.rb b/spec/requests/enterprise_trials/enterprise_trials_spec.rbnew file mode 100644index 00000000000..f38af105a0e--- /dev/null+++ b/spec/requests/enterprise_trials/enterprise_trials_spec.rb@@ -0,0 +1,268 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "spec_helper"++RSpec.describe "Enterprise Trials",+ :skip_csrf,+ type: :rails_request do+ shared_let(:admin) { create(:admin) }+ shared_let(:user) { create(:user) }++ subject do+ request+ response+ end++ before do+ login_as current_user+ end++ describe "GET /admin/enterprise_trial/trial_dialog" do+ let(:current_user) { admin }++ let(:request) { get trial_dialog_enterprise_trial_path, as: :turbo_stream }++ it "returns success" do+ expect(subject).to have_http_status(:ok)+ end++ context "when not logged in as admin" do+ let(:current_user) { user }++ it "returns forbidden" do+ expect(subject).to have_http_status(:forbidden)+ end+ end++ context "when not logged in" do+ let(:current_user) { User.anonymous }++ it "returns 401" do+ expect(subject).to have_http_status(:unauthorized)+ end+ end+ end++ describe "POST /admin/enterprise_trial/request_resend" do+ let(:current_user) { admin }+ let!(:trial_key) { Token::EnterpriseTrialKey.create!(user: User.system) }++ let(:service_double) { instance_double(EnterpriseTrials::AugurResendConfirmationService) }+ let(:request) { post request_resend_enterprise_trial_path }++ before do+ allow(EnterpriseTrials::AugurResendConfirmationService)+ .to receive(:new)+ .with(trial_key)+ .and_return(service_double)+ end++ context "when resend service succeeds" do+ before do+ allow(service_double).to receive(:call)+ end++ it "calls the resend service and redirects to enterprise path" do+ expect(subject).to have_http_status(:see_other)+ expect(response).to redirect_to(enterprise_tokens_path)+ expect(service_double).to have_received(:call)+ end+ end++ context "when trial key does not exist" do+ before { trial_key.destroy! }++ it "renders an error" do+ expect(subject).to have_http_status(:not_found)+ end+ end++ context "when not logged in as admin" do+ let(:current_user) { user }++ it "returns forbidden" do+ expect(subject).to have_http_status(:forbidden)+ end+ end++ context "when not logged in" do+ let(:current_user) { User.anonymous }++ it "redirects to login" do+ expect(subject).to have_http_status(:found)+ expect(response).to redirect_to(signin_path(back_url: request_resend_enterprise_trial_url))+ end+ end+ end++ describe "POST /admin/enterprise_trial" do+ let(:current_user) { admin }+ let(:valid_params) do+ {+ enterprise_trial: {+ company: "Test Company",+ firstname: "John",+ lastname: "Doe",+ email: "[email protected]",+ general_consent: "1",+ newsletter_consent: "1"+ }+ }+ end++ let(:request) { post enterprise_trial_path, as: :turbo_stream, params: params }++ context "with valid parameters" do+ let(:params) { valid_params }+ let(:service_result) { ServiceResult.success }+ let(:create_service) { instance_double(EnterpriseTrials::CreateService) }++ before do+ allow(EnterpriseTrials::CreateService)+ .to receive(:new)+ .with(user: admin)+ .and_return(create_service)+ allow(create_service).to receive(:call).and_return(service_result)+ end++ it "creates enterprise trial and redirects to enterprise path" do+ expect(subject).to have_http_status(:see_other)+ expect(response).to redirect_to(enterprise_tokens_path)+ expect(create_service).to have_received(:call).with(+ company: "Test Company",+ firstname: "John",+ lastname: "Doe",+ email: "[email protected]",+ general_consent: "1",+ newsletter_consent: "1"+ )+ end+ end++ context "with invalid parameters" do+ let(:params) { valid_params }+ let(:trial_with_errors) { EnterpriseTrial.new(valid_params[:enterprise_trial]) }+ let(:service_result) { ServiceResult.failure(result: trial_with_errors) }+ let(:create_service) { instance_double(EnterpriseTrials::CreateService) }++ before do+ trial_with_errors.errors.add(:email, "is invalid")++ allow(EnterpriseTrials::CreateService)+ .to receive(:new)+ .with(user: admin)+ .and_return(create_service)+ allow(create_service).to receive(:call).and_return(service_result)+ end++ it "returns bad request and renders form with errors via turbo stream" do+ expect(subject).to have_http_status(:bad_request)+ expect(response.content_type).to include("text/vnd.turbo-stream.html")+ end+ end++ context "with missing required parameters" do+ let(:params) do+ {+ enterprise_trial: {+ company: "Test Company"+ }+ }+ end++ it "handles the request without raising parameter errors" do+ expect { subject }.not_to raise_error+ end+ end++ context "when not logged in as admin" do+ let(:current_user) { user }+ let(:params) { valid_params }++ it "returns forbidden" do+ expect(subject).to have_http_status(:forbidden)+ end+ end++ context "when not logged in" do+ let(:params) { valid_params }+ let(:current_user) { User.anonymous }++ it "returns a 401" do+ expect(subject).to have_http_status(:unauthorized)+ end+ end+ end++ describe "parameter filtering" do+ let(:current_user) { admin }++ context "when unexpected parameters are provided" do+ let(:params) do+ {+ enterprise_trial: {+ company: "Test Company",+ firstname: "John",+ lastname: "Doe",+ email: "[email protected]",+ general_consent: "1",+ newsletter_consent: "1",+ admin_flag: "true",+ sensitive_data: "should not be passed"+ }+ }+ end+ let(:service_result) { ServiceResult.success }+ let(:create_service) { instance_double(EnterpriseTrials::CreateService) }++ before do+ allow(EnterpriseTrials::CreateService)+ .to receive(:new)+ .with(user: admin)+ .and_return(create_service)+ allow(create_service).to receive(:call).and_return(service_result)+ end++ it "filters out unpermitted parameters" do+ post enterprise_trial_path, params: params++ expect(create_service).to have_received(:call).with(+ company: "Test Company",+ firstname: "John",+ lastname: "Doe",+ email: "[email protected]",+ general_consent: "1",+ newsletter_consent: "1"+ )+ end+ end+ end+enddiff --git a/spec/services/enterprise_trials/augur_create_trial_service_spec.rb b/spec/services/enterprise_trials/augur_create_trial_service_spec.rbindex 365035dbda1..caf95d6cee4 100644--- a/spec/services/enterprise_trials/augur_create_trial_service_spec.rb+++ b/spec/services/enterprise_trials/augur_create_trial_service_spec.rb@@ -68,7 +68,7 @@ RSpec.describe EnterpriseTrials::AugurCreateTrialService, :webmock doversion: OpenProject::VERSION.to_semver,token_version: OpenProject::Token::VERSION,domain: Setting.host_name- }.to_json,+ }.to_json).to_return(status: 202, body: success_response.to_json, headers: { "Content-Type" => "application/json" })end@@ -279,7 +279,7 @@ RSpec.describe EnterpriseTrials::AugurCreateTrialService, :webmock doversion: OpenProject::VERSION.to_semver,token_version: OpenProject::Token::VERSION,domain: Setting.host_name- }.to_json,+ }.to_json).to_return(status: 202, body: success_response.to_json, headers: { "Content-Type" => "application/json" })diff --git a/spec/services/enterprise_trials/augur_load_trial_service_spec.rb b/spec/services/enterprise_trials/augur_load_trial_service_spec.rbindex f797557c222..425f8845051 100644--- a/spec/services/enterprise_trials/augur_load_trial_service_spec.rb+++ b/spec/services/enterprise_trials/augur_load_trial_service_spec.rb@@ -63,7 +63,7 @@ RSpec.describe EnterpriseTrials::AugurLoadTrialService, :webmock doresult = service.callexpect(result).to be_success- expect(result.message).to eq(I18n.t("ee.trial.already_retrieved"))+ expect(result.message).to eq(I18n.t("ee.trial.successfully_saved"))expect(Token::EnterpriseTrialKey).not_to exist(trial_key.id)expect(token_double).to have_received(:save)diff --git a/spec/services/enterprise_trials/create_service_spec.rb b/spec/services/enterprise_trials/create_service_spec.rbnew file mode 100644index 00000000000..a491d5ceace--- /dev/null+++ b/spec/services/enterprise_trials/create_service_spec.rb@@ -0,0 +1,82 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "spec_helper"+require "services/base_services/behaves_like_create_service"++RSpec.describe EnterpriseTrials::CreateService, type: :model do+ let(:user) { build_stubbed(:admin) }+ let(:instance) { described_class.new(user:) }+ let(:valid_params) do+ {+ company: "Foo Corp",+ firstname: "Albert",+ lastname: "Einstein",+ email: "[email protected]",+ newsletter_consent: true,+ general_consent: true+ }+ end+ let(:params) { valid_params }+ let(:augur_double) { instance_double(EnterpriseTrials::AugurCreateTrialService) }+ let(:augur_result) { ServiceResult.success(result: nil) }++ subject { instance.call(params) }++ before do+ allow(EnterpriseTrials::AugurCreateTrialService).to receive(:new).and_return(augur_double)+ allow(augur_double).to receive(:call).and_return(augur_result)+ end++ context "with valid params" do+ it "requests a trial request using the AugurCreateTrialService" do+ expect(subject).to be_success+ expect(augur_double).to have_received(:call)+ end+ end++ context "with invalid params" do+ let(:params) { valid_params.merge(email: "invalid_email") }++ it "returns an error" do+ expect(subject).to be_failure+ expect(subject.errors.symbols_for(:email)).to contain_exactly(:email)+ end+ end++ context "when user is not an admin" do+ let(:user) { build_stubbed(:user) }++ it "returns an error" do+ expect(subject).to be_failure+ expect(subject.errors.symbols_for(:base)).to contain_exactly(:error_unauthorized)+ end+ end+end