Browse Source

moderator tests added

ignazio 3 years ago
parent
commit
268ce3408d

+ 3 - 3
runtime-modules/content/src/errors.rs

@@ -37,9 +37,6 @@ decl_error! {
         /// Member authentication failed
         MemberAuthFailed,
 
-        /// Member id not valid
-        CollaboratorIsNotValidMember,
-
         /// Curator authentication failed
         CuratorAuthFailed,
 
@@ -114,5 +111,8 @@ decl_error! {
 
         /// Insufficient treasury balance
         InsufficientTreasuryBalance,
+
+        /// Invalid member id  specified
+        InvalidMemberProvided,
     }
 }

+ 1 - 2
runtime-modules/content/src/lib.rs

@@ -2135,11 +2135,10 @@ impl<T: Trait> Module<T> {
         let res = members
             .iter()
             .all(|member_id| <T as ContentActorAuthenticator>::validate_member_id(member_id));
-        ensure!(res, Error::<T>::CollaboratorIsNotValidMember);
+        ensure!(res, Error::<T>::InvalidMemberProvided);
         Ok(())
     }
 }
-
 // Giza:
 // Reset Videos and Channels on runtime upgrade but preserving next ids and categories.
 impl<T: Trait> Module<T> {

+ 2 - 2
runtime-modules/content/src/tests/channels.rs

@@ -367,7 +367,7 @@ fn unsuccessful_channel_creation_with_invalid_collaborators_set() {
             .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
             .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
             .with_collaborators(vec![COLLABORATOR_MEMBER_ID + 100].into_iter().collect())
-            .call_and_assert(Err(Error::<Test>::CollaboratorIsNotValidMember.into()));
+            .call_and_assert(Err(Error::<Test>::InvalidMemberProvided.into()));
     })
 }
 
@@ -1179,7 +1179,7 @@ fn unsuccessful_channel_update_with_invalid_collaborators_set() {
             .with_sender(DEFAULT_MEMBER_ACCOUNT_ID)
             .with_actor(ContentActor::Member(DEFAULT_MEMBER_ID))
             .with_collaborators(vec![COLLABORATOR_MEMBER_ID + 100].into_iter().collect())
-            .call_and_assert(Err(Error::<Test>::CollaboratorIsNotValidMember.into()));
+            .call_and_assert(Err(Error::<Test>::InvalidMemberProvided.into()));
     })
 }
 

+ 1 - 1
runtime-modules/content/src/tests/fixtures.rs

@@ -1122,7 +1122,7 @@ impl UpdateModeratorSetFixture {
 
         assert_eq!(actual_result, expected_result);
 
-        let channel_post = ChannelById::get(&self.channel_id);
+        let channel_post = ChannelById::<Test>::get(&self.channel_id);
 
         if actual_result.is_ok() {
             assert_eq!(

+ 104 - 1
runtime-modules/content/src/tests/posts.rs

@@ -1026,12 +1026,115 @@ pub fn successful_comment_deletion_by_moderator() {
 }
 
 #[test]
-pub fn successful_comment_deletion_by_moderator() {
+pub fn unsuccessful_moderators_update_by_unauthorized_member() {
     with_default_mock_builder(|| {
         run_to_block(1);
 
         create_initial_storage_buckets_helper();
         increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
         create_default_member_owned_channel();
+
+        UpdateModeratorSetFixture::default()
+            .with_sender(UNAUTHORIZED_MEMBER_ACCOUNT_ID)
+            .with_actor(ContentActor::Member(UNAUTHORIZED_MEMBER_ID))
+            .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()))
+    })
+}
+
+#[test]
+pub fn unsuccessful_moderators_update_by_unauthorized_curator() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_curator_owned_channel();
+
+        let unauthorized_curator_group_id = add_curator_to_new_group(UNAUTHORIZED_CURATOR_ID);
+        UpdateModeratorSetFixture::default()
+            .with_sender(UNAUTHORIZED_CURATOR_ACCOUNT_ID)
+            .with_actor(ContentActor::Curator(
+                unauthorized_curator_group_id,
+                UNAUTHORIZED_CURATOR_ID,
+            ))
+            .call_and_assert(Err(Error::<Test>::ActorNotAuthorized.into()))
+    })
+}
+
+#[test]
+pub fn unsuccessful_moderators_update_with_member_auth_failed() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_member_owned_channel();
+
+        UpdateModeratorSetFixture::default()
+            .with_actor(ContentActor::Member(UNAUTHORIZED_MEMBER_ID))
+            .call_and_assert(Err(Error::<Test>::MemberAuthFailed.into()))
+    })
+}
+
+#[test]
+pub fn unsuccessful_moderators_update_with_curator_auth_failed() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_curator_owned_channel();
+
+        let default_curator_group_id = Content::next_curator_group_id() - 1;
+        UpdateModeratorSetFixture::default()
+            .with_sender(UNAUTHORIZED_CURATOR_ACCOUNT_ID)
+            .with_actor(ContentActor::Curator(
+                default_curator_group_id,
+                DEFAULT_CURATOR_ID,
+            ))
+            .call_and_assert(Err(Error::<Test>::CuratorAuthFailed.into()))
+    })
+}
+
+#[test]
+pub fn unsuccessful_moderators_update_with_invalid_members_id() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_member_owned_channel();
+
+        UpdateModeratorSetFixture::default()
+            .with_moderators(vec![DEFAULT_MODERATOR_ID + 1].into_iter().collect())
+            .call_and_assert(Err(Error::<Test>::InvalidMemberProvided.into()))
+    })
+}
+
+#[test]
+pub fn successful_moderators_update_by_owner() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_member_owned_channel();
+
+        UpdateModeratorSetFixture::default().call_and_assert(Ok(()));
+    })
+}
+
+#[test]
+pub fn unsuccessful_moderators_update_with_invalid_channel_id() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_member_owned_channel();
+
+        UpdateModeratorSetFixture::default()
+            .with_channel_id(ChannelId::zero())
+            .call_and_assert(Err(Error::<Test>::ChannelDoesNotExist.into()))
     })
 }