Browse Source

Support hiring module changes

- Update From<WrappedError<AddOpeningError>>: add message for the new error type - ApplicationRationingZeroMaxApplicants
- Cover From<WrappedError<AddOpeningError>> with tests
Shamil Gadelshin 5 years ago
parent
commit
ec05e959af
2 changed files with 46 additions and 2 deletions
  1. 4 2
      src/content_working_group/lib.rs
  2. 42 0
      src/content_working_group/tests.rs

+ 4 - 2
src/content_working_group/lib.rs

@@ -653,7 +653,7 @@ struct WrappedBeginAcceptingApplicationsError { // can this be made generic, or
 }
 */
 
-struct WrappedError<E> {
+pub(super) struct WrappedError<E> {
     // can this be made generic, or does that undermine the whole orhpan rule spirit?
     pub error: E,
 }
@@ -698,6 +698,9 @@ impl rstd::convert::From<WrappedError<hiring::AddOpeningError>> for &str {
                     }
                 }
             }
+            hiring::AddOpeningError::ApplicationRationingZeroMaxApplicants => {
+                "Application rationing policy: maximum active applicant number must be greater than zero"
+            }
         }
     }
 }
@@ -2383,7 +2386,6 @@ impl<T: Trait> Module<T> {
     ) {
         // Update name to channel mapping if there is a new name mapping
         if let Some(ref channel_name) = new_channel_name {
-
             // Remove mapping under old name
             let current_channel_name = ChannelById::<T>::get(channel_id).channel_name;
 

+ 42 - 0
src/content_working_group/tests.rs

@@ -1 +1,43 @@
+#![cfg(test)]
 
+#[test]
+fn add_opening_error_wrapper_succeeded() {
+    let mut message: &str;
+
+    message = super::lib::WrappedError {
+        error: hiring::AddOpeningError::OpeningMustActivateInTheFuture,
+    }
+    .into();
+    assert_eq!(message, "Opening must activate in the future");
+
+    message = super::lib::WrappedError {
+        error: hiring::AddOpeningError::StakeAmountLessThanMinimumCurrencyBalance(
+            hiring::StakePurpose::Role,
+        ),
+    }
+    .into();
+    assert_eq!(
+        message,
+        "Role stake amount less than minimum currency balance"
+    );
+
+    message = super::lib::WrappedError {
+        error: hiring::AddOpeningError::StakeAmountLessThanMinimumCurrencyBalance(
+            hiring::StakePurpose::Application,
+        ),
+    }
+    .into();
+    assert_eq!(
+        message,
+        "Application stake amount less than minimum currency balance"
+    );
+
+    message = super::lib::WrappedError {
+        error: hiring::AddOpeningError::ApplicationRationingZeroMaxApplicants,
+    }
+    .into();
+    assert_eq!(
+        message,
+        "Application rationing policy: maximum active applicant number must be greater than zero"
+    );
+}