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
# 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 trial management",
:js,
:webmock do
include Redmine::I18n
let(:admin) { create(:admin) }
let(:trial_id) { "1b6486b4-5a30-4042-8714-99d7c8e6b637" }
let(:created_body) do
{
_type: "enterprise-trial",
id: trial_id,
_links:
{
self:
{
href: "https://start.openproject-edge.com/public/v1/trials/#{trial_id}"
},
details:
{
href: "https://start.openproject-edge.com/public/v1/trials/#{trial_id}/details"
}
}
}
end
let(:waiting_body) do
{
_type: "error",
code: 422,
identifier: "waiting_for_email_verification",
description: "User has to confirm their email address",
_links: {
resend: {
href: "https://start.openproject-edge.com/public/v1/trials/#{trial_id}/resend",
method: "POST"
},
details: {
href: "https://start.openproject-edge.com/public/v1/trials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WUpoS05uSGI1a3lYcy9MRkhOWW05c1xuN2hBOVdS
RUxWQi9Tc2x5RjJQczNzSHJQaGtZM1BGZElSeU9Kb2JxdnZoaUpPTVA5dDVu
MUxUeTFjbkhGXG5DbTBDM0U1bWFjTi9hOE5OSXk2dGhia3JJVE5XK2I4K2Jw
VDN3OGkxSDVYNCtodlJ5T1g0Y0JEVWhNN2pcbnN3Wkw0citmWlRmaGlNQkZi
K2NmSUZ0U2lyMVBpdz09XG4iLCJpdiI6IjFxbEZqRWM4QzcrMjg4QWR6cXdL
OEE9PVxuIn0=
-----END OPENPROJECT-EE TOKEN-----
EOS
end
let (:confirmed_body) do
{
_type: "enterprise-trial",
id: trial_id,
token: expired_token,
token_retrieved: false,
_links: {
self: {
href: "https://start.openproject-edge.com/public/v1/trials/#{trial_id}"
}
}
}
end
let(:mail_in_use_body) do
{
_type: "error",
code: 422,
identifier: "user_already_created_trial",
description: "Each user can only create one trial."
}
end
let(:domain_in_use_body) do
{
_type: "error",
code: 422,
identifier: "domain_taken",
description: "There can only be one active trial per domain."
}
end
let(:other_error_body) do
{
_type: "error",
code: 409,
description: "Token version is invalid",
identifier: "token_version_too_old",
errors: {
token_version: [
"does not have a valid value"
]
}
}
end
before do
login_as(admin)
visit enterprise_tokens_path
end
def fill_out_modal(mail: "[email protected]")
fill_in "Company", with: "Foo Corp."
fill_in "First name", with: "Foo"
fill_in "Last name", with: "Bar"
fill_in "Email", with: mail
retry_block do
check "enterprise_trial_general_consent", allow_label_click: true
expect(page).to have_checked_field("enterprise_trial_general_consent")
end
end
it "does not send a request when an internal validation fails" do
click_link_or_button("Start free trial")
fill_in "Company", with: "Foo Corp."
# No stubbed request with webmock -> No allowed requests
click_link_or_button("Continue")
page.within("#enterprise-trial-dialog") do
expect(page).to have_text("First name can't be blank.")
expect(page).to have_text("Last name can't be blank.")
expect(page).to have_text("Email can't be blank.")
end
end
it "blocks the request assuming the mail was used" do
stub_request(:post, "https://start.openproject-edge.com:443/public/v1/trials")
.to_return(status: 422, headers: { "Content-Type" => "application/json" }, body: mail_in_use_body.to_json)
click_link_or_button("Start free trial")
fill_out_modal
click_link_or_button("Continue")
page.within("#enterprise-trial-dialog") do
expect(page).to have_text("Email was already used to create a trial.")
end
end
it "blocks the request assuming the domain was used" do
stub_request(:post, "https://start.openproject-edge.com:443/public/v1/trials")
.to_return(status: 422, headers: { "Content-Type" => "application/json" }, body: domain_in_use_body.to_json)
click_link_or_button("Start free trial")
fill_out_modal
click_link_or_button("Continue")
page.within("#enterprise-trial-dialog") do
expect(page).to have_text("Domain was already used to create a trial.")
end
end
it "shows an error in case of other errors" do
stub_request(:post, "https://start.openproject-edge.com:443/public/v1/trials")
.to_return(status: 409, headers: { "Content-Type" => "application/json" }, body: other_error_body.to_json)
click_link("Start free trial")
fill_out_modal
click_link_or_button("Continue")
page.within("#enterprise-trial-dialog") do
expect(page).to have_text("Token version is invalid")
end
end
context "with a waiting request pending" do
before do
stub_request(:post, "https://start.openproject-edge.com:443/public/v1/trials")
.to_return(status: 202, headers: { "Content-Type" => "application/json" }, body: created_body.to_json)
stub_request(:get, "https://start.openproject-edge.com:443/public/v1/trials/#{trial_id}")
.to_return(status: 422, headers: { "Content-Type" => "application/json" }, body: waiting_body.to_json)
stub_request(:post, "https://start.openproject-edge.com:443/public/v1/trials/#{trial_id}/resend")
.to_return(status: 200, headers: { "Content-Type" => "application/json" }, body: waiting_body.to_json)
click_link("Start free trial")
fill_out_modal
click_link_or_button("Continue")
wait_for_network_idle
end
it "can get the trial if reloading the page" do
# Stub with successful body
# Stub the proxy to a successful return
# which marks the user has confirmed the mail link
stub_request(:get, "https://start.openproject-edge.com:443/public/v1/trials/#{trial_id}")
.to_return(status: 200, headers: { "Content-Type" => "application/json" }, body: confirmed_body.to_json)
visit enterprise_tokens_path
expect(page).to have_text("Quick feature overview")
expect(page).to have_css("#enterprise-trial-welcome-dialog video")
page.find('[data-close-dialog-id="enterprise-trial-welcome-dialog"]').click
expect(page).to have_text("Enterprise Plan")
expect(page).to have_text("Expired")
expect(page).to have_text("OpenProject Test")
expect(page).to have_text("5")
expect(page).to have_text("01/01/2020 – 01/02/2020")
end
it "can confirm that trial regularly" do
expect(page).to have_text "We sent you an email on #{format_date(Date.current)} to [email protected]"
# Stub the proxy to a successful return
# which marks the user has confirmed the mail link
stub_request(:get, "https://start.openproject-edge.com:443/public/v1/trials/#{trial_id}")
.to_return(status: 200, headers: { "Content-Type" => "application/json" }, body: confirmed_body.to_json)
# Expect flash with resend link
page.within("#primerized-flash-messages") do
click_link_or_button("Resend confirmation email")
end
expect(page).to have_text("Quick feature overview")
expect(page).to have_css("#enterprise-trial-welcome-dialog video")
expect(page).to have_text("Enterprise Plan")
expect(page).to have_text("Expired")
expect(page).to have_text("OpenProject Test")
expect(page).to have_text("5")
expect(page).to have_text("01/01/2020 – 01/02/2020")
end
end
end