2013-02-20 05:53:15 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe SystemHooksService, services: true do
|
2015-06-22 08:39:07 -04:00
|
|
|
let(:user) { create :user }
|
|
|
|
let(:project) { create :project }
|
|
|
|
let(:project_member) { create :project_member }
|
|
|
|
let(:key) { create(:key, user: user) }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:group_member) { create(:group_member) }
|
2013-02-20 05:53:15 -05:00
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
context 'event data' do
|
2016-01-07 12:54:35 -05:00
|
|
|
it { expect(event_data(user, :create)).to include(:event_name, :name, :created_at, :updated_at, :email, :user_id, :username) }
|
|
|
|
it { expect(event_data(user, :destroy)).to include(:event_name, :name, :created_at, :updated_at, :email, :user_id, :username) }
|
2015-05-05 11:13:11 -04:00
|
|
|
it { expect(event_data(project, :create)).to include(:event_name, :name, :created_at, :updated_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
|
2016-08-08 09:31:35 -04:00
|
|
|
it { expect(event_data(project, :update)).to include(:event_name, :name, :created_at, :updated_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
|
2015-05-05 11:13:11 -04:00
|
|
|
it { expect(event_data(project, :destroy)).to include(:event_name, :name, :created_at, :updated_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
|
2016-01-13 04:12:30 -05:00
|
|
|
it { expect(event_data(project_member, :create)).to include(:event_name, :created_at, :updated_at, :project_name, :project_path, :project_path_with_namespace, :project_id, :user_name, :user_username, :user_email, :user_id, :access_level, :project_visibility) }
|
|
|
|
it { expect(event_data(project_member, :destroy)).to include(:event_name, :created_at, :updated_at, :project_name, :project_path, :project_path_with_namespace, :project_id, :user_name, :user_username, :user_email, :user_id, :access_level, :project_visibility) }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_data(key, :create)).to include(:username, :key, :id) }
|
|
|
|
it { expect(event_data(key, :destroy)).to include(:username, :key, :id) }
|
2014-08-21 06:53:32 -04:00
|
|
|
|
2015-05-05 11:13:11 -04:00
|
|
|
it do
|
|
|
|
project.old_path_with_namespace = 'renamed_from_path'
|
|
|
|
expect(event_data(project, :rename)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :name, :created_at, :updated_at, :path, :project_id,
|
|
|
|
:owner_name, :owner_email, :project_visibility,
|
2015-05-05 11:13:11 -04:00
|
|
|
:old_path_with_namespace
|
2016-01-13 04:12:30 -05:00
|
|
|
)
|
2015-05-05 11:13:11 -04:00
|
|
|
end
|
|
|
|
it do
|
|
|
|
project.old_path_with_namespace = 'transfered_from_path'
|
|
|
|
expect(event_data(project, :transfer)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :name, :created_at, :updated_at, :path, :project_id,
|
|
|
|
:owner_name, :owner_email, :project_visibility,
|
2015-05-05 11:13:11 -04:00
|
|
|
:old_path_with_namespace
|
2016-01-13 04:12:30 -05:00
|
|
|
)
|
2015-05-05 11:13:11 -04:00
|
|
|
end
|
|
|
|
|
2014-08-21 06:53:32 -04:00
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group, :create)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :name, :created_at, :updated_at, :path, :group_id,
|
2015-05-05 11:13:11 -04:00
|
|
|
:owner_name, :owner_email
|
2014-08-21 06:53:32 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group, :destroy)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :name, :created_at, :updated_at, :path, :group_id,
|
2015-05-05 11:13:11 -04:00
|
|
|
:owner_name, :owner_email
|
2014-08-21 06:53:32 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group_member, :create)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :created_at, :updated_at, :group_name, :group_path,
|
2016-01-07 12:54:54 -05:00
|
|
|
:group_id, :user_id, :user_username, :user_name, :user_email, :group_access
|
2014-08-21 06:53:32 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
it do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(event_data(group_member, :destroy)).to include(
|
2016-01-13 04:12:30 -05:00
|
|
|
:event_name, :created_at, :updated_at, :group_name, :group_path,
|
2016-01-07 12:54:54 -05:00
|
|
|
:group_id, :user_id, :user_username, :user_name, :user_email, :group_access
|
2014-08-21 06:53:32 -04:00
|
|
|
)
|
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
context 'event names' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_name(user, :create)).to eq "user_create" }
|
|
|
|
it { expect(event_name(user, :destroy)).to eq "user_destroy" }
|
|
|
|
it { expect(event_name(project, :create)).to eq "project_create" }
|
|
|
|
it { expect(event_name(project, :destroy)).to eq "project_destroy" }
|
2015-05-05 11:13:11 -04:00
|
|
|
it { expect(event_name(project, :rename)).to eq "project_rename" }
|
|
|
|
it { expect(event_name(project, :transfer)).to eq "project_transfer" }
|
2016-08-08 09:31:35 -04:00
|
|
|
it { expect(event_name(project, :update)).to eq "project_update" }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(event_name(project_member, :create)).to eq "user_add_to_team" }
|
|
|
|
it { expect(event_name(project_member, :destroy)).to eq "user_remove_from_team" }
|
|
|
|
it { expect(event_name(key, :create)).to eq 'key_create' }
|
|
|
|
it { expect(event_name(key, :destroy)).to eq 'key_destroy' }
|
|
|
|
it { expect(event_name(group, :create)).to eq 'group_create' }
|
|
|
|
it { expect(event_name(group, :destroy)).to eq 'group_destroy' }
|
|
|
|
it { expect(event_name(group_member, :create)).to eq 'user_add_to_group' }
|
|
|
|
it { expect(event_name(group_member, :destroy)).to eq 'user_remove_from_group' }
|
2013-10-08 04:06:38 -04:00
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
def event_data(*args)
|
2014-01-15 07:26:05 -05:00
|
|
|
SystemHooksService.new.send :build_event_data, *args
|
2013-10-08 04:06:38 -04:00
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
|
2013-10-08 04:06:38 -04:00
|
|
|
def event_name(*args)
|
2014-01-15 07:26:05 -05:00
|
|
|
SystemHooksService.new.send :build_event_name, *args
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|
|
|
|
end
|