Skip to content

Commit

Permalink
use Valkryie for all test setup in edit_permissions_service_spec
Browse files Browse the repository at this point in the history
makes this test compatible with Valkyrie by refactoring out ActiveFedora based
factories.

the methodology i used here is to:

  - stand up dassie;
  - refactor for tidiness/to remove AF based mocks;
  - rewrite with Valkyrie factories;
  - test on dassie;
  - test on koppie
  • Loading branch information
tamsin johnson committed Aug 23, 2023
1 parent 55cfc34 commit d6b370b
Showing 1 changed file with 47 additions and 21 deletions.
68 changes: 47 additions & 21 deletions spec/services/hyrax/edit_permissions_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,60 @@
# build collections for testing
# my_user has no manage rights to admin_set
let(:admin_set) do
FactoryBot.create(:adminset_lw,
id: 'default_admin_set',
user: coll_creator,
with_permission_template: { manage_users: [mgr1], view_users: [vw1] })
FactoryBot.valkyrie_create(:hyrax_admin_set,
:with_permission_template,
user: coll_creator,
access_grants: [{ access: Hyrax::PermissionTemplateAccess::MANAGE,
agent_id: mgr1.user_key,
agent_type: Hyrax::PermissionTemplateAccess::USER },
{ access: Hyrax::PermissionTemplateAccess::VIEW,
agent_id: vw1.user_key,
agent_type: Hyrax::PermissionTemplateAccess::USER }])
end

let(:sharable_type) { FactoryBot.create(:collection_type, :sharable) }
let(:nonsharable_type) { FactoryBot.create(:collection_type, :not_sharable) }

# my_user has manage rights to this collection
let(:sharable_coll1) do
FactoryBot.create(:collection_lw,
id: 'sharable_coll1',
user: coll_creator,
collection_type_settings: [:sharable],
with_permission_template: { manage_users: [mgr2, my_user], view_users: [vw2] })
FactoryBot.valkyrie_create(:hyrax_collection,
user: coll_creator,
collection_type_gid: sharable_type.to_global_id.to_s,
access_grants: [{ access: Hyrax::PermissionTemplateAccess::MANAGE,
agent_id: mgr2.user_key,
agent_type: Hyrax::PermissionTemplateAccess::USER },
{ access: Hyrax::PermissionTemplateAccess::MANAGE,
agent_id: my_user.user_key,
agent_type: Hyrax::PermissionTemplateAccess::USER },
{ access: Hyrax::PermissionTemplateAccess::VIEW,
agent_id: vw2.user_key,
agent_type: Hyrax::PermissionTemplateAccess::USER }])
end

# my_user has no manage rights to this collection
let(:sharable_coll2) do
FactoryBot.create(:collection_lw,
id: 'sharable_coll2',
user: coll_creator,
collection_type_settings: [:sharable],
with_permission_template: { manage_users: [mgr3], view_users: [vw3] })
FactoryBot.valkyrie_create(:hyrax_collection,
user: coll_creator,
collection_type_gid: sharable_type.to_global_id.to_s,
access_grants: [{ access: Hyrax::PermissionTemplateAccess::MANAGE,
agent_id: mgr3.user_key,
agent_type: Hyrax::PermissionTemplateAccess::USER },
{ access: Hyrax::PermissionTemplateAccess::VIEW,
agent_id: vw3.user_key,
agent_type: Hyrax::PermissionTemplateAccess::USER }])
end

# non-sharable collections do not impact the permissions of the works
let(:nonsharable_collection) do
FactoryBot.create(:collection_lw,
id: 'nonsharable_coll',
user: coll_creator,
collection_type_settings: [:not_sharable],
with_permission_template: { manage_users: [mgr4], view_users: [vw4] })
FactoryBot.valkyrie_create(:hyrax_collection,
user: coll_creator,
collection_type_gid: nonsharable_type.to_global_id.to_s,
access_grants: [{ access: Hyrax::PermissionTemplateAccess::MANAGE,
agent_id: mgr4.user_key,
agent_type: Hyrax::PermissionTemplateAccess::USER },
{ access: Hyrax::PermissionTemplateAccess::VIEW,
agent_id: vw4.user_key,
agent_type: Hyrax::PermissionTemplateAccess::USER }])
end

# @note: We are using multiple collections only in order to test the complex situations
Expand All @@ -53,7 +79,7 @@
# However, since we don't know which work's permissions were actually inherited from a
# sharable collection, we have to assume they all need to be restricted.
# build work for testing:
let(:generic_work) do
let(:work) do
FactoryBot.valkyrie_create(:hyrax_work,
depositor: my_user.user_key,
edit_users: [mgr2, mgr3, mgr4, mgr5],
Expand All @@ -63,7 +89,7 @@
admin_set_id: admin_set.id)
end

subject(:work_permission_service) { described_class.new(object: generic_work, ability: ability) }
subject(:work_permission_service) { described_class.new(object: work, ability: ability) }

# defined for expectations
let(:admin_set_manager) { Hash[id: admin_set.id, name: mgr1.user_key] }
Expand Down

0 comments on commit d6b370b

Please sign in to comment.