Commit 5a88372c authored by serenafang's avatar serenafang

Add group spec

Group spec not fully working
parent c3f0b8a0
......@@ -452,6 +452,8 @@ module EE
def execute_hooks(data, hooks_scope)
super
return unless feature_available?(:group_webhooks)
self_and_ancestor_hooks = GroupHook.where(group_id: self.self_and_ancestors)
self_and_ancestor_hooks.hooks_for(hooks_scope).each do |hook|
hook.async_execute(data, hooks_scope.to_s)
......
......@@ -249,13 +249,13 @@ RSpec.describe GroupMember do
end
it 'execute webhooks' do
group.add_guest(user)
member = group.add_guest(user)
expect(WebMock).to have_requested(:post, group_hook.url).with(
headers: { 'Content-Type' => 'application/json', 'User-Agent' => "GitLab/#{Gitlab::VERSION}", 'X-Gitlab-Event' => 'Member Hook' },
body: {
created_at: user.created_at&.xmlschema,
updated_at: user.updated_at&.xmlschema,
created_at: member.created_at&.xmlschema,
updated_at: member.updated_at&.xmlschema,
group_name: group.name,
group_path: group.path,
group_id: group.id,
......
......@@ -898,6 +898,37 @@ RSpec.describe Group do
end
end
describe "#execute_hooks" do
context "group_webhooks", :sidekiq_inline do
let(:group) { create(:group) }
let(:group_hook) { create(:group_hook, group: group, member_events: true) }
let(:data) { { some: 'info' } }
context 'when group_webhooks feature is enabled' do
before do
stub_licensed_features(group_webhooks: true)
end
let(:service) { double }
it 'executes the hook' do
expect(service).to receive(:async_execute).once
expect(WebHookService).to receive(:new)
group.execute_hooks(data, :member_hooks)
end
end
it 'does not execute the hook when the feature is disabled' do
stub_licensed_features(group_webhooks: false)
expect(WebHookService).not_to receive(:new)
group.execute_hooks(data, :member_hooks)
end
end
end
describe '#self_or_ancestor_marked_for_deletion' do
context 'delayed deletion feature is not available' do
before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment