Skip to content

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

Consider enterprise token valid on its expiry date

Christophe Bliard18c023f649f9
diff --git a/spec/models/enterprise_token_spec.rb b/spec/models/enterprise_token_spec.rb
index 0eaee0d65a3..3d980c2267f 100644
--- a/spec/models/enterprise_token_spec.rb
+++ b/spec/models/enterprise_token_spec.rb
@@ -374,6 +374,20 @@ RSpec.describe EnterpriseToken do
(valid_until IS NULL OR valid_until >= '2026-06-01'))
SQL
end
+
+ it "is consistent with #active?" do
+ combinations = [nil, Date.yesterday, Date.current, Date.tomorrow]
+ .then { |dates| dates.product(dates) }
+ combinations.each do |starts_at, expires_at|
+ described_class.delete_all
+ token = create_enterprise_token(starts_at:, expires_at:)
+ if token.active?
+ expect(described_class.active).to include(token), "Expected .active to have returned active token #{token.inspect}"
+ else
+ expect(described_class.active).to be_empty, "Expected .active to have NOT returned inactive token #{token.inspect}"
+ end
+ end
+ end
end
describe ".available_features" do
@@ -544,6 +558,40 @@ RSpec.describe EnterpriseToken do
end
end
+ describe "#expired?" do
+ context "when token has no expiration date" do
+ let(:token) { build_enterprise_token(expires_at: nil) }
+
+ it "is not expired" do
+ expect(token).not_to be_expired
+ end
+ end
+
+ context "when token expiration date is in the past" do
+ let(:token) { build_enterprise_token(expires_at: Date.yesterday) }
+
+ it "is expired" do
+ expect(token).to be_expired
+ end
+ end
+
+ context "when token expiration date is today" do
+ let(:token) { build_enterprise_token(expires_at: Date.current) }
+
+ it "is not expired" do
+ expect(token).not_to be_expired
+ end
+ end
+
+ context "when token expiration date is in the future" do
+ let(:token) { build_enterprise_token(expires_at: Date.tomorrow) }
+
+ it "is not expired" do
+ expect(token).not_to be_expired
+ end
+ end
+ end
+
describe "extract validity from token" do
let(:starts_at) { Date.parse("2025-01-01") }
let(:expires_at) { Date.parse("2025-01-31") }