smoke.rs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. use super::*;
  2. use crate::mock::*;
  3. use sp_std::collections::btree_set::BTreeSet;
  4. /**
  5. Main hiring workflow:
  6. 1. add_opening
  7. 1.1 (optional) ensure_can_add_application
  8. 2. add_application
  9. 3. begin_review
  10. 4. fill_opening
  11. Not covered:
  12. - begin_accepting_applications
  13. - unstaked
  14. - cancel_opening
  15. - deactive_application
  16. Smoke-test concept:
  17. https://en.wikipedia.org/wiki/Smoke_testing_(software)
  18. **/
  19. #[test]
  20. fn full_hiring_workflow_successful_path() {
  21. build_test_externalities().execute_with(|| {
  22. // 1. Add opening
  23. let expected_opening_id = 0;
  24. let activation_at = ActivateOpeningAt::CurrentBlock;
  25. let max_review_period_length = 672;
  26. let application_rationing_policy = None;
  27. let application_staking_policy = None;
  28. let role_staking_policy = None;
  29. let human_readable_text = "human_readable_text!!!".as_bytes().to_vec();
  30. let application_readable_text = "hrt!!".as_bytes().to_vec();
  31. // Add an opening, check that the returned value is Zero
  32. assert_eq!(
  33. Hiring::add_opening(
  34. activation_at,
  35. max_review_period_length,
  36. application_rationing_policy,
  37. application_staking_policy,
  38. role_staking_policy,
  39. human_readable_text.clone()
  40. ),
  41. Ok(expected_opening_id)
  42. );
  43. // Check that next opening id has been updated
  44. assert_eq!(Hiring::next_opening_id(), expected_opening_id + 1);
  45. // Check that our opening actually was added
  46. assert!(<OpeningById<Test>>::contains_key(expected_opening_id));
  47. let found_opening = Hiring::opening_by_id(expected_opening_id);
  48. // Check opening content
  49. assert_eq!(
  50. found_opening,
  51. Opening {
  52. created: FIRST_BLOCK_HEIGHT,
  53. stage: OpeningStage::Active {
  54. stage: ActiveOpeningStage::AcceptingApplications {
  55. started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT
  56. },
  57. applications_added: BTreeSet::new(),
  58. active_application_count: 0,
  59. unstaking_application_count: 0,
  60. deactivated_application_count: 0
  61. },
  62. max_review_period_length,
  63. application_rationing_policy: None,
  64. application_staking_policy: None,
  65. role_staking_policy: None,
  66. human_readable_text: human_readable_text.clone()
  67. }
  68. );
  69. let current_opening_id = expected_opening_id;
  70. // 1.1 (optional) ensure_can_add_application
  71. let ensure_can_add_application_result =
  72. Hiring::ensure_can_add_application(current_opening_id, None, None);
  73. // Check ensure_can_add_application result
  74. assert!(ensure_can_add_application_result.is_ok());
  75. // Check returned content
  76. let destructured_app_data = ensure_can_add_application_result.unwrap();
  77. let expected = DestructuredApplicationCanBeAddedEvaluation {
  78. opening: Opening {
  79. created: FIRST_BLOCK_HEIGHT,
  80. stage: OpeningStage::Active {
  81. stage: ActiveOpeningStage::AcceptingApplications {
  82. started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
  83. },
  84. applications_added: BTreeSet::new(),
  85. active_application_count: 0,
  86. unstaking_application_count: 0,
  87. deactivated_application_count: 0,
  88. },
  89. max_review_period_length: 672,
  90. application_rationing_policy: None,
  91. application_staking_policy: None,
  92. role_staking_policy: None,
  93. human_readable_text: human_readable_text.clone(),
  94. },
  95. active_stage: ActiveOpeningStage::AcceptingApplications {
  96. started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
  97. },
  98. applications_added: BTreeSet::new(),
  99. active_application_count: 0,
  100. unstaking_application_count: 0,
  101. deactivated_application_count: 0,
  102. would_get_added_success: ApplicationAddedSuccess::Unconditionally,
  103. };
  104. assert_eq!(destructured_app_data, expected);
  105. // 2. add_application
  106. let add_application_result = Hiring::add_application(
  107. current_opening_id,
  108. None,
  109. None,
  110. application_readable_text.clone(),
  111. );
  112. // Check add_application result
  113. assert!(add_application_result.is_ok());
  114. // Check that application wasn't crowded_out
  115. let app_added = add_application_result.unwrap();
  116. assert_eq!(app_added.application_id_crowded_out, None);
  117. let new_application_id = app_added.application_id_added;
  118. // Check that our application actually was added
  119. assert!(<ApplicationById<Test>>::contains_key(new_application_id));
  120. let new_application = Hiring::application_by_id(new_application_id);
  121. // Check application content
  122. assert_eq!(
  123. new_application,
  124. Application {
  125. opening_id: 0,
  126. application_index_in_opening: 0,
  127. add_to_opening_in_block: FIRST_BLOCK_HEIGHT,
  128. active_role_staking_id: None,
  129. active_application_staking_id: None,
  130. stage: ApplicationStage::Active,
  131. human_readable_text: application_readable_text.clone()
  132. }
  133. );
  134. // 3. begin_review
  135. let begin_review_result = Hiring::begin_review(current_opening_id);
  136. // Check begin_review result
  137. assert!(begin_review_result.is_ok());
  138. let updated_opening_after_begin_review = Hiring::opening_by_id(current_opening_id);
  139. let mut expected_added_apps_in_opening = BTreeSet::new();
  140. expected_added_apps_in_opening.insert(0);
  141. // Check updated opening content
  142. assert_eq!(
  143. updated_opening_after_begin_review,
  144. Opening {
  145. created: FIRST_BLOCK_HEIGHT,
  146. stage: OpeningStage::Active {
  147. stage: ActiveOpeningStage::ReviewPeriod {
  148. started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
  149. started_review_period_at_block: FIRST_BLOCK_HEIGHT
  150. },
  151. applications_added: expected_added_apps_in_opening.clone(),
  152. active_application_count: 1,
  153. unstaking_application_count: 0,
  154. deactivated_application_count: 0
  155. },
  156. max_review_period_length,
  157. application_rationing_policy: None,
  158. application_staking_policy: None,
  159. role_staking_policy: None,
  160. human_readable_text: human_readable_text.clone()
  161. }
  162. );
  163. // 4. fill_opening
  164. let applications = [new_application_id]
  165. .iter()
  166. .map(|&x| x)
  167. .collect::<BTreeSet<_>>();
  168. let fill_opening_result =
  169. Hiring::fill_opening(current_opening_id, applications, None, None, None);
  170. // Check fill_opening result
  171. assert!(fill_opening_result.is_ok());
  172. let updated_opening_fill_opening = Hiring::opening_by_id(current_opening_id);
  173. // Check updated opening content
  174. assert_eq!(
  175. updated_opening_fill_opening,
  176. Opening {
  177. created: FIRST_BLOCK_HEIGHT,
  178. stage: OpeningStage::Active {
  179. stage: ActiveOpeningStage::Deactivated {
  180. cause: OpeningDeactivationCause::Filled,
  181. deactivated_at_block: FIRST_BLOCK_HEIGHT,
  182. started_accepting_applicants_at_block: FIRST_BLOCK_HEIGHT,
  183. started_review_period_at_block: Some(FIRST_BLOCK_HEIGHT)
  184. },
  185. applications_added: expected_added_apps_in_opening,
  186. active_application_count: 0,
  187. unstaking_application_count: 0,
  188. deactivated_application_count: 1
  189. },
  190. max_review_period_length,
  191. application_rationing_policy: None,
  192. application_staking_policy: None,
  193. role_staking_policy: None,
  194. human_readable_text: human_readable_text.clone()
  195. }
  196. );
  197. let current_application_id = new_application_id;
  198. let application_after_fill_opening = Hiring::application_by_id(current_application_id);
  199. // Check updated application content
  200. assert_eq!(
  201. application_after_fill_opening,
  202. Application {
  203. opening_id: 0,
  204. application_index_in_opening: 0,
  205. add_to_opening_in_block: FIRST_BLOCK_HEIGHT,
  206. active_role_staking_id: None,
  207. active_application_staking_id: None,
  208. stage: ApplicationStage::Inactive {
  209. deactivation_initiated: FIRST_BLOCK_HEIGHT,
  210. deactivated: FIRST_BLOCK_HEIGHT,
  211. cause: ApplicationDeactivationCause::Hired
  212. },
  213. human_readable_text: application_readable_text.clone()
  214. }
  215. );
  216. });
  217. }