Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/activity_pub/releases_subscription_spec.rb')
-rw-r--r--spec/models/activity_pub/releases_subscription_spec.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/models/activity_pub/releases_subscription_spec.rb b/spec/models/activity_pub/releases_subscription_spec.rb
new file mode 100644
index 00000000000..0c873a5c18a
--- /dev/null
+++ b/spec/models/activity_pub/releases_subscription_spec.rb
@@ -0,0 +1,79 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ActivityPub::ReleasesSubscription, type: :model, feature_category: :release_orchestration do
+ describe 'factory' do
+ subject { build(:activity_pub_releases_subscription) }
+
+ it { is_expected.to be_valid }
+ end
+
+ describe 'associations' do
+ it { is_expected.to belong_to(:project).optional(false) }
+ end
+
+ describe 'validations' do
+ it { is_expected.to validate_presence_of(:subscriber_url) }
+
+ describe 'subscriber_url' do
+ subject { build(:activity_pub_releases_subscription) }
+
+ it { is_expected.to validate_uniqueness_of(:subscriber_url).case_insensitive.scoped_to([:project_id]) }
+ it { is_expected.to allow_value("http://example.com/actor").for(:subscriber_url) }
+ it { is_expected.not_to allow_values("I'm definitely not a URL").for(:subscriber_url) }
+ end
+
+ describe 'subscriber_inbox_url' do
+ subject { build(:activity_pub_releases_subscription) }
+
+ it { is_expected.to validate_uniqueness_of(:subscriber_inbox_url).case_insensitive.scoped_to([:project_id]) }
+ it { is_expected.to allow_value("http://example.com/actor").for(:subscriber_inbox_url) }
+ it { is_expected.not_to allow_values("I'm definitely not a URL").for(:subscriber_inbox_url) }
+ end
+
+ describe 'shared_inbox_url' do
+ subject { build(:activity_pub_releases_subscription) }
+
+ it { is_expected.to allow_value("http://example.com/actor").for(:shared_inbox_url) }
+ it { is_expected.not_to allow_values("I'm definitely not a URL").for(:shared_inbox_url) }
+ end
+
+ describe 'payload' do
+ it { is_expected.not_to allow_value("string").for(:payload) }
+ it { is_expected.not_to allow_value(1.0).for(:payload) }
+
+ it do
+ is_expected.to allow_value({
+ '@context': 'https://www.w3.org/ns/activitystreams',
+ id: 'https://example.com/actor#follow/1',
+ type: 'Follow',
+ actor: 'https://example.com/actor',
+ object: 'http://localhost/user/project/-/releases'
+ }).for(:payload)
+ end
+ end
+ end
+
+ describe '.find_by_subscriber_url' do
+ let_it_be(:subscription) { create(:activity_pub_releases_subscription) }
+
+ it 'returns a record if arguments match' do
+ result = described_class.find_by_subscriber_url(subscription.subscriber_url)
+
+ expect(result).to eq(subscription)
+ end
+
+ it 'returns a record if arguments match case insensitively' do
+ result = described_class.find_by_subscriber_url(subscription.subscriber_url.upcase)
+
+ expect(result).to eq(subscription)
+ end
+
+ it 'returns nil if project does not match' do
+ result = described_class.find_by_subscriber_url('I really should not exist')
+
+ expect(result).to be(nil)
+ end
+ end
+end