mod.rs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. mod mock;
  2. use crate::constraints::InputValidationLengthConstraint;
  3. use crate::types::{
  4. Lead, OpeningPolicyCommitment, RewardPolicy, Worker, WorkerApplication, WorkerOpening,
  5. WorkerRoleStage,
  6. };
  7. use crate::{Instance1, RawEvent};
  8. use mock::{build_test_externalities, Balances, Bureaucracy1, Membership, System, TestEvent};
  9. use srml_support::StorageValue;
  10. use std::collections::{BTreeMap, BTreeSet};
  11. use system::{EventRecord, Phase, RawOrigin};
  12. struct FillWorkerOpeningFixture {
  13. origin: RawOrigin<u64>,
  14. opening_id: u64,
  15. successful_worker_application_ids: BTreeSet<u64>,
  16. role_account: u64,
  17. reward_policy: Option<RewardPolicy<u64, u64>>,
  18. }
  19. impl FillWorkerOpeningFixture {
  20. pub fn default_for_ids(opening_id: u64, application_ids: Vec<u64>) -> Self {
  21. let application_ids: BTreeSet<u64> = application_ids.iter().map(|x| *x).collect();
  22. FillWorkerOpeningFixture {
  23. origin: RawOrigin::Signed(1),
  24. opening_id,
  25. successful_worker_application_ids: application_ids,
  26. role_account: 1,
  27. reward_policy: None,
  28. }
  29. }
  30. fn with_origin(self, origin: RawOrigin<u64>) -> Self {
  31. FillWorkerOpeningFixture { origin, ..self }
  32. }
  33. pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
  34. let saved_worker_next_id = Bureaucracy1::next_worker_id();
  35. let actual_result = Bureaucracy1::fill_worker_opening(
  36. self.origin.clone().into(),
  37. self.opening_id,
  38. self.successful_worker_application_ids.clone(),
  39. self.reward_policy.clone(),
  40. );
  41. assert_eq!(actual_result.clone(), expected_result);
  42. if actual_result.is_ok() {
  43. assert_eq!(Bureaucracy1::next_worker_id(), saved_worker_next_id + 1);
  44. let worker_id = saved_worker_next_id;
  45. let actual_worker = Bureaucracy1::worker_by_id(worker_id);
  46. let expected_worker = Worker {
  47. role_account: self.role_account,
  48. reward_relationship: None,
  49. role_stake_profile: None,
  50. stage: WorkerRoleStage::Active,
  51. };
  52. assert_eq!(actual_worker, expected_worker);
  53. }
  54. }
  55. }
  56. struct BeginReviewWorkerApplicationsFixture {
  57. origin: RawOrigin<u64>,
  58. opening_id: u64,
  59. }
  60. impl BeginReviewWorkerApplicationsFixture {
  61. pub fn default_for_opening_id(opening_id: u64) -> Self {
  62. BeginReviewWorkerApplicationsFixture {
  63. origin: RawOrigin::Signed(1),
  64. opening_id,
  65. }
  66. }
  67. fn with_origin(self, origin: RawOrigin<u64>) -> Self {
  68. BeginReviewWorkerApplicationsFixture { origin, ..self }
  69. }
  70. pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
  71. let actual_result = Bureaucracy1::begin_worker_applicant_review(
  72. self.origin.clone().into(),
  73. self.opening_id,
  74. );
  75. assert_eq!(actual_result, expected_result);
  76. }
  77. }
  78. struct TerminateApplicationFixture {
  79. origin: RawOrigin<u64>,
  80. worker_application_id: u64,
  81. }
  82. impl TerminateApplicationFixture {
  83. fn with_signer(self, account_id: u64) -> Self {
  84. TerminateApplicationFixture {
  85. origin: RawOrigin::Signed(account_id),
  86. ..self
  87. }
  88. }
  89. fn with_origin(self, origin: RawOrigin<u64>) -> Self {
  90. TerminateApplicationFixture { origin, ..self }
  91. }
  92. pub fn default_for_application_id(application_id: u64) -> Self {
  93. TerminateApplicationFixture {
  94. origin: RawOrigin::Signed(1),
  95. worker_application_id: application_id,
  96. }
  97. }
  98. pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
  99. let actual_result = Bureaucracy1::terminate_worker_application(
  100. self.origin.clone().into(),
  101. self.worker_application_id,
  102. );
  103. assert_eq!(actual_result.clone(), expected_result);
  104. }
  105. }
  106. struct WithdrawApplicationFixture {
  107. origin: RawOrigin<u64>,
  108. worker_application_id: u64,
  109. }
  110. impl WithdrawApplicationFixture {
  111. fn with_signer(self, account_id: u64) -> Self {
  112. WithdrawApplicationFixture {
  113. origin: RawOrigin::Signed(account_id),
  114. ..self
  115. }
  116. }
  117. fn with_origin(self, origin: RawOrigin<u64>) -> Self {
  118. WithdrawApplicationFixture { origin, ..self }
  119. }
  120. pub fn default_for_application_id(application_id: u64) -> Self {
  121. WithdrawApplicationFixture {
  122. origin: RawOrigin::Signed(1),
  123. worker_application_id: application_id,
  124. }
  125. }
  126. pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
  127. let actual_result = Bureaucracy1::withdraw_worker_application(
  128. self.origin.clone().into(),
  129. self.worker_application_id,
  130. );
  131. assert_eq!(actual_result.clone(), expected_result);
  132. }
  133. }
  134. pub(crate) fn increase_total_balance_issuance_using_account_id(account_id: u64, balance: u64) {
  135. let _ =
  136. <Balances as srml_support::traits::Currency<u64>>::deposit_creating(&account_id, balance);
  137. }
  138. fn setup_members(count: u8) {
  139. let authority_account_id = 1;
  140. Membership::set_screening_authority(RawOrigin::Root.into(), authority_account_id).unwrap();
  141. for i in 0..count {
  142. let account_id: u64 = i as u64;
  143. let handle: [u8; 20] = [i; 20];
  144. Membership::add_screened_member(
  145. RawOrigin::Signed(authority_account_id).into(),
  146. account_id,
  147. membership::members::UserInfo {
  148. handle: Some(handle.to_vec()),
  149. avatar_uri: None,
  150. about: None,
  151. },
  152. )
  153. .unwrap();
  154. }
  155. }
  156. struct ApplyOnWorkerOpeningFixture {
  157. origin: RawOrigin<u64>,
  158. member_id: u64,
  159. worker_opening_id: u64,
  160. role_account: u64,
  161. opt_role_stake_balance: Option<u64>,
  162. opt_application_stake_balance: Option<u64>,
  163. human_readable_text: Vec<u8>,
  164. }
  165. impl ApplyOnWorkerOpeningFixture {
  166. fn with_text(self, text: Vec<u8>) -> Self {
  167. ApplyOnWorkerOpeningFixture {
  168. human_readable_text: text,
  169. ..self
  170. }
  171. }
  172. fn with_role_stake(self, stake: u64) -> Self {
  173. ApplyOnWorkerOpeningFixture {
  174. opt_role_stake_balance: Some(stake),
  175. ..self
  176. }
  177. }
  178. fn with_application_stake(self, stake: u64) -> Self {
  179. ApplyOnWorkerOpeningFixture {
  180. opt_application_stake_balance: Some(stake),
  181. ..self
  182. }
  183. }
  184. pub fn default_for_opening_id(opening_id: u64) -> Self {
  185. ApplyOnWorkerOpeningFixture {
  186. origin: RawOrigin::Signed(1),
  187. member_id: 1,
  188. worker_opening_id: opening_id,
  189. role_account: 1,
  190. opt_role_stake_balance: None,
  191. opt_application_stake_balance: None,
  192. human_readable_text: Vec::new(),
  193. }
  194. }
  195. pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
  196. let saved_application_next_id = Bureaucracy1::next_worker_application_id();
  197. let actual_result = Bureaucracy1::apply_on_worker_opening(
  198. self.origin.clone().into(),
  199. self.member_id,
  200. self.worker_opening_id,
  201. self.role_account,
  202. self.opt_role_stake_balance,
  203. self.opt_application_stake_balance,
  204. self.human_readable_text.clone(),
  205. );
  206. assert_eq!(actual_result.clone(), expected_result);
  207. if actual_result.is_ok() {
  208. assert_eq!(
  209. Bureaucracy1::next_worker_application_id(),
  210. saved_application_next_id + 1
  211. );
  212. let application_id = saved_application_next_id;
  213. let actual_application = Bureaucracy1::worker_application_by_id(application_id);
  214. let expected_application = WorkerApplication {
  215. role_account: self.role_account,
  216. worker_opening_id: self.worker_opening_id,
  217. member_id: self.member_id,
  218. application_id,
  219. };
  220. assert_eq!(actual_application, expected_application);
  221. let current_opening = Bureaucracy1::worker_opening_by_id(self.worker_opening_id);
  222. assert!(current_opening
  223. .worker_applications
  224. .contains(&application_id));
  225. }
  226. }
  227. }
  228. struct AcceptWorkerApplicationsFixture {
  229. origin: RawOrigin<u64>,
  230. opening_id: u64,
  231. }
  232. impl AcceptWorkerApplicationsFixture {
  233. pub fn default_for_opening_id(opening_id: u64) -> Self {
  234. AcceptWorkerApplicationsFixture {
  235. origin: RawOrigin::Signed(1),
  236. opening_id,
  237. }
  238. }
  239. pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
  240. let actual_result =
  241. Bureaucracy1::accept_worker_applications(self.origin.clone().into(), self.opening_id);
  242. assert_eq!(actual_result, expected_result);
  243. }
  244. }
  245. struct SetLeadFixture;
  246. impl SetLeadFixture {
  247. fn set_lead(lead_account_id: u64) {
  248. assert_eq!(
  249. Bureaucracy1::set_lead(RawOrigin::Root.into(), 1, lead_account_id),
  250. Ok(())
  251. );
  252. }
  253. }
  254. struct AddWorkerOpeningFixture {
  255. origin: RawOrigin<u64>,
  256. activate_at: hiring::ActivateOpeningAt<u64>,
  257. commitment: OpeningPolicyCommitment<u64, u64>,
  258. human_readable_text: Vec<u8>,
  259. }
  260. impl Default for AddWorkerOpeningFixture {
  261. fn default() -> Self {
  262. AddWorkerOpeningFixture {
  263. origin: RawOrigin::Signed(1),
  264. activate_at: hiring::ActivateOpeningAt::CurrentBlock,
  265. commitment: <OpeningPolicyCommitment<u64, u64>>::default(),
  266. human_readable_text: Vec::new(),
  267. }
  268. }
  269. }
  270. impl AddWorkerOpeningFixture {
  271. pub fn call_and_assert(&self, expected_result: Result<(), &str>) {
  272. let saved_opening_next_id = Bureaucracy1::next_worker_opening_id();
  273. let actual_result = Bureaucracy1::add_worker_opening(
  274. self.origin.clone().into(),
  275. self.activate_at.clone(),
  276. self.commitment.clone(),
  277. self.human_readable_text.clone(),
  278. );
  279. assert_eq!(actual_result.clone(), expected_result);
  280. if actual_result.is_ok() {
  281. assert_eq!(
  282. Bureaucracy1::next_worker_opening_id(),
  283. saved_opening_next_id + 1
  284. );
  285. let opening_id = saved_opening_next_id;
  286. let actual_opening = Bureaucracy1::worker_opening_by_id(opening_id);
  287. let expected_opening = WorkerOpening::<u64, u64, u64, u64> {
  288. opening_id,
  289. worker_applications: BTreeSet::new(),
  290. policy_commitment: OpeningPolicyCommitment::default(),
  291. };
  292. assert_eq!(actual_opening, expected_opening);
  293. }
  294. }
  295. fn with_text(self, text: Vec<u8>) -> Self {
  296. AddWorkerOpeningFixture {
  297. human_readable_text: text,
  298. ..self
  299. }
  300. }
  301. fn with_activate_at(self, activate_at: hiring::ActivateOpeningAt<u64>) -> Self {
  302. AddWorkerOpeningFixture {
  303. activate_at,
  304. ..self
  305. }
  306. }
  307. }
  308. struct EventFixture;
  309. impl EventFixture {
  310. fn assert_crate_events(
  311. expected_raw_events: Vec<
  312. RawEvent<u64, u64, u64, u64, std::collections::BTreeMap<u64, u64>, crate::Instance1>,
  313. >,
  314. ) {
  315. let converted_events = expected_raw_events
  316. .iter()
  317. .map(|ev| TestEvent::bureaucracy_Instance1(ev.clone()))
  318. .collect::<Vec<TestEvent>>();
  319. Self::assert_global_events(converted_events)
  320. }
  321. fn assert_global_events(expected_raw_events: Vec<TestEvent>) {
  322. let expected_events = expected_raw_events
  323. .iter()
  324. .map(|ev| EventRecord {
  325. phase: Phase::ApplyExtrinsic(0),
  326. event: ev.clone(),
  327. topics: vec![],
  328. })
  329. .collect::<Vec<EventRecord<_, _>>>();
  330. assert_eq!(System::events(), expected_events);
  331. }
  332. }
  333. #[test]
  334. fn set_forum_sudo_set() {
  335. build_test_externalities().execute_with(|| {
  336. // Ensure that lead is default
  337. assert_eq!(Bureaucracy1::current_lead(), None);
  338. let lead_account_id = 1;
  339. let lead_member_id = 1;
  340. // Set lead
  341. assert_eq!(
  342. Bureaucracy1::set_lead(RawOrigin::Root.into(), lead_member_id, lead_account_id),
  343. Ok(())
  344. );
  345. let lead = Lead {
  346. member_id: lead_member_id,
  347. role_account_id: lead_account_id,
  348. };
  349. assert_eq!(Bureaucracy1::current_lead(), Some(lead));
  350. EventFixture::assert_crate_events(vec![RawEvent::LeaderSet(
  351. lead_member_id,
  352. lead_account_id,
  353. )]);
  354. });
  355. }
  356. #[test]
  357. fn add_worker_opening_succeeds() {
  358. build_test_externalities().execute_with(|| {
  359. let lead_account_id = 1;
  360. SetLeadFixture::set_lead(lead_account_id);
  361. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  362. add_worker_opening_fixture.call_and_assert(Ok(()));
  363. EventFixture::assert_crate_events(vec![
  364. RawEvent::LeaderSet(1, lead_account_id),
  365. RawEvent::WorkerOpeningAdded(0),
  366. ]);
  367. });
  368. }
  369. #[test]
  370. fn add_worker_opening_fails_with_lead_is_not_set() {
  371. build_test_externalities().execute_with(|| {
  372. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  373. add_worker_opening_fixture.call_and_assert(Err(crate::MSG_CURRENT_LEAD_NOT_SET));
  374. });
  375. }
  376. #[test]
  377. fn add_worker_opening_fails_with_invalid_human_readable_text() {
  378. build_test_externalities().execute_with(|| {
  379. SetLeadFixture::set_lead(1);
  380. <crate::OpeningHumanReadableText<Instance1>>::put(InputValidationLengthConstraint {
  381. min: 1,
  382. max_min_diff: 5,
  383. });
  384. let add_worker_opening_fixture = AddWorkerOpeningFixture::default().with_text(Vec::new());
  385. add_worker_opening_fixture.call_and_assert(Err(crate::MSG_OPENING_TEXT_TOO_SHORT));
  386. let add_worker_opening_fixture =
  387. AddWorkerOpeningFixture::default().with_text(b"Long text".to_vec());
  388. add_worker_opening_fixture.call_and_assert(Err(crate::MSG_OPENING_TEXT_TOO_LONG));
  389. });
  390. }
  391. #[test]
  392. fn add_worker_opening_fails_with_hiring_error() {
  393. build_test_externalities().execute_with(|| {
  394. SetLeadFixture::set_lead(1);
  395. let add_worker_opening_fixture = AddWorkerOpeningFixture::default()
  396. .with_activate_at(hiring::ActivateOpeningAt::ExactBlock(0));
  397. add_worker_opening_fixture.call_and_assert(Err(
  398. crate::errors::MSG_ADD_WORKER_OPENING_ACTIVATES_IN_THE_PAST,
  399. ));
  400. });
  401. }
  402. #[test]
  403. fn accept_worker_applications_succeeds() {
  404. build_test_externalities().execute_with(|| {
  405. let lead_account_id = 1;
  406. SetLeadFixture::set_lead(lead_account_id);
  407. let add_worker_opening_fixture = AddWorkerOpeningFixture::default()
  408. .with_activate_at(hiring::ActivateOpeningAt::ExactBlock(5));
  409. add_worker_opening_fixture.call_and_assert(Ok(()));
  410. let opening_id = 0; // newly created opening
  411. let accept_worker_applications_fixture =
  412. AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
  413. accept_worker_applications_fixture.call_and_assert(Ok(()));
  414. EventFixture::assert_crate_events(vec![
  415. RawEvent::LeaderSet(1, lead_account_id),
  416. RawEvent::WorkerOpeningAdded(opening_id),
  417. RawEvent::AcceptedWorkerApplications(opening_id),
  418. ]);
  419. });
  420. }
  421. #[test]
  422. fn accept_worker_applications_fails_with_hiring_error() {
  423. build_test_externalities().execute_with(|| {
  424. SetLeadFixture::set_lead(1);
  425. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  426. add_worker_opening_fixture.call_and_assert(Ok(()));
  427. let opening_id = 0; // newly created opening
  428. let accept_worker_applications_fixture =
  429. AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
  430. accept_worker_applications_fixture.call_and_assert(Err(
  431. crate::errors::MSG_ACCEPT_WORKER_APPLICATIONS_OPENING_IS_NOT_WAITING_TO_BEGIN,
  432. ));
  433. });
  434. }
  435. #[test]
  436. fn accept_worker_applications_fails_with_not_lead() {
  437. build_test_externalities().execute_with(|| {
  438. SetLeadFixture::set_lead(1);
  439. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  440. add_worker_opening_fixture.call_and_assert(Ok(()));
  441. SetLeadFixture::set_lead(2);
  442. let opening_id = 0; // newly created opening
  443. let accept_worker_applications_fixture =
  444. AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
  445. accept_worker_applications_fixture.call_and_assert(Err(crate::MSG_IS_NOT_LEAD_ACCOUNT));
  446. });
  447. }
  448. #[test]
  449. fn accept_worker_applications_fails_with_no_opening() {
  450. build_test_externalities().execute_with(|| {
  451. SetLeadFixture::set_lead(1);
  452. let opening_id = 0; // newly created opening
  453. let accept_worker_applications_fixture =
  454. AcceptWorkerApplicationsFixture::default_for_opening_id(opening_id);
  455. accept_worker_applications_fixture
  456. .call_and_assert(Err(crate::MSG_WORKER_OPENING_DOES_NOT_EXIST));
  457. });
  458. }
  459. #[test]
  460. fn apply_on_worker_opening_succeeds() {
  461. build_test_externalities().execute_with(|| {
  462. let lead_account_id = 1;
  463. SetLeadFixture::set_lead(lead_account_id);
  464. setup_members(2);
  465. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  466. add_worker_opening_fixture.call_and_assert(Ok(()));
  467. let opening_id = 0; // newly created opening
  468. let appy_on_worker_opening_fixture =
  469. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  470. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  471. EventFixture::assert_global_events(vec![
  472. TestEvent::bureaucracy_Instance1(RawEvent::LeaderSet(1, lead_account_id)),
  473. TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
  474. TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
  475. TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningAdded(opening_id)),
  476. TestEvent::bureaucracy_Instance1(RawEvent::AppliedOnWorkerOpening(opening_id, 0)),
  477. ]);
  478. });
  479. }
  480. #[test]
  481. fn apply_on_worker_opening_fails_with_no_opening() {
  482. build_test_externalities().execute_with(|| {
  483. let lead_account_id = 1;
  484. SetLeadFixture::set_lead(lead_account_id);
  485. setup_members(2);
  486. let opening_id = 0; // newly created opening
  487. let appy_on_worker_opening_fixture =
  488. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  489. appy_on_worker_opening_fixture
  490. .call_and_assert(Err(crate::MSG_WORKER_OPENING_DOES_NOT_EXIST));
  491. });
  492. }
  493. #[test]
  494. fn apply_on_worker_opening_fails_with_not_set_members() {
  495. build_test_externalities().execute_with(|| {
  496. let lead_account_id = 1;
  497. SetLeadFixture::set_lead(lead_account_id);
  498. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  499. add_worker_opening_fixture.call_and_assert(Ok(()));
  500. let opening_id = 0; // newly created opening
  501. let appy_on_worker_opening_fixture =
  502. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  503. appy_on_worker_opening_fixture
  504. .call_and_assert(Err(crate::MSG_ORIGIN_IS_NEITHER_MEMBER_CONTROLLER_OR_ROOT));
  505. });
  506. }
  507. #[test]
  508. fn apply_on_worker_opening_fails_with_hiring_error() {
  509. build_test_externalities().execute_with(|| {
  510. increase_total_balance_issuance_using_account_id(1, 500000);
  511. let lead_account_id = 1;
  512. SetLeadFixture::set_lead(lead_account_id);
  513. setup_members(2);
  514. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  515. add_worker_opening_fixture.call_and_assert(Ok(()));
  516. let opening_id = 0; // newly created opening
  517. let appy_on_worker_opening_fixture =
  518. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
  519. .with_application_stake(100);
  520. appy_on_worker_opening_fixture.call_and_assert(Err(
  521. crate::errors::MSG_ADD_WORKER_OPENING_STAKE_PROVIDED_WHEN_REDUNDANT,
  522. ));
  523. });
  524. }
  525. #[test]
  526. fn apply_on_worker_opening_fails_with_invalid_application_stake() {
  527. build_test_externalities().execute_with(|| {
  528. let lead_account_id = 1;
  529. SetLeadFixture::set_lead(lead_account_id);
  530. setup_members(2);
  531. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  532. add_worker_opening_fixture.call_and_assert(Ok(()));
  533. let opening_id = 0; // newly created opening
  534. let appy_on_worker_opening_fixture =
  535. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
  536. .with_application_stake(100);
  537. appy_on_worker_opening_fixture
  538. .call_and_assert(Err(crate::MSG_INSUFFICIENT_BALANCE_TO_APPLY));
  539. });
  540. }
  541. #[test]
  542. fn apply_on_worker_opening_fails_with_invalid_role_stake() {
  543. build_test_externalities().execute_with(|| {
  544. let lead_account_id = 1;
  545. SetLeadFixture::set_lead(lead_account_id);
  546. setup_members(2);
  547. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  548. add_worker_opening_fixture.call_and_assert(Ok(()));
  549. let opening_id = 0; // newly created opening
  550. let appy_on_worker_opening_fixture =
  551. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id).with_role_stake(100);
  552. appy_on_worker_opening_fixture
  553. .call_and_assert(Err(crate::MSG_INSUFFICIENT_BALANCE_TO_APPLY));
  554. });
  555. }
  556. #[test]
  557. fn apply_on_worker_opening_fails_with_invalid_text() {
  558. build_test_externalities().execute_with(|| {
  559. let lead_account_id = 1;
  560. SetLeadFixture::set_lead(lead_account_id);
  561. setup_members(2);
  562. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  563. add_worker_opening_fixture.call_and_assert(Ok(()));
  564. let opening_id = 0; // newly created opening
  565. <crate::WorkerApplicationHumanReadableText<Instance1>>::put(
  566. InputValidationLengthConstraint {
  567. min: 1,
  568. max_min_diff: 5,
  569. },
  570. );
  571. let appy_on_worker_opening_fixture =
  572. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id).with_text(Vec::new());
  573. appy_on_worker_opening_fixture
  574. .call_and_assert(Err(crate::MSG_WORKER_APPLICATION_TEXT_TOO_SHORT));
  575. let appy_on_worker_opening_fixture =
  576. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id)
  577. .with_text(b"Long text".to_vec());
  578. appy_on_worker_opening_fixture
  579. .call_and_assert(Err(crate::MSG_WORKER_APPLICATION_TEXT_TOO_LONG));
  580. });
  581. }
  582. #[test]
  583. fn apply_on_worker_opening_fails_with_already_active_application() {
  584. build_test_externalities().execute_with(|| {
  585. let lead_account_id = 1;
  586. SetLeadFixture::set_lead(lead_account_id);
  587. setup_members(2);
  588. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  589. add_worker_opening_fixture.call_and_assert(Ok(()));
  590. let opening_id = 0; // newly created opening
  591. let appy_on_worker_opening_fixture =
  592. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  593. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  594. appy_on_worker_opening_fixture
  595. .call_and_assert(Err(crate::MSG_MEMBER_HAS_ACTIVE_APPLICATION_ON_OPENING));
  596. });
  597. }
  598. #[test]
  599. fn withdraw_worker_application_succeeds() {
  600. build_test_externalities().execute_with(|| {
  601. let lead_account_id = 1;
  602. SetLeadFixture::set_lead(lead_account_id);
  603. setup_members(2);
  604. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  605. add_worker_opening_fixture.call_and_assert(Ok(()));
  606. let opening_id = 0; // newly created opening
  607. let appy_on_worker_opening_fixture =
  608. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  609. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  610. let application_id = 0; // newly created application
  611. let withdraw_application_fixture =
  612. WithdrawApplicationFixture::default_for_application_id(application_id);
  613. withdraw_application_fixture.call_and_assert(Ok(()));
  614. EventFixture::assert_global_events(vec![
  615. TestEvent::bureaucracy_Instance1(RawEvent::LeaderSet(1, lead_account_id)),
  616. TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
  617. TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
  618. TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningAdded(opening_id)),
  619. TestEvent::bureaucracy_Instance1(RawEvent::AppliedOnWorkerOpening(
  620. opening_id,
  621. application_id,
  622. )),
  623. TestEvent::bureaucracy_Instance1(RawEvent::WorkerApplicationWithdrawn(application_id)),
  624. ]);
  625. });
  626. }
  627. #[test]
  628. fn withdraw_worker_application_fails_invalid_application_id() {
  629. build_test_externalities().execute_with(|| {
  630. let invalid_application_id = 6;
  631. let withdraw_application_fixture =
  632. WithdrawApplicationFixture::default_for_application_id(invalid_application_id);
  633. withdraw_application_fixture
  634. .call_and_assert(Err(crate::MSG_WORKER_APPLICATION_DOES_NOT_EXIST));
  635. });
  636. }
  637. #[test]
  638. fn withdraw_worker_application_fails_invalid_origin() {
  639. build_test_externalities().execute_with(|| {
  640. let lead_account_id = 1;
  641. SetLeadFixture::set_lead(lead_account_id);
  642. setup_members(2);
  643. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  644. add_worker_opening_fixture.call_and_assert(Ok(()));
  645. let opening_id = 0; // newly created opening
  646. let appy_on_worker_opening_fixture =
  647. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  648. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  649. let application_id = 0; // newly created application
  650. let withdraw_application_fixture =
  651. WithdrawApplicationFixture::default_for_application_id(application_id)
  652. .with_origin(RawOrigin::None);
  653. withdraw_application_fixture.call_and_assert(Err("RequireSignedOrigin"));
  654. });
  655. }
  656. #[test]
  657. fn withdraw_worker_application_fails_with_invalid_application_author() {
  658. build_test_externalities().execute_with(|| {
  659. let lead_account_id = 1;
  660. SetLeadFixture::set_lead(lead_account_id);
  661. setup_members(2);
  662. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  663. add_worker_opening_fixture.call_and_assert(Ok(()));
  664. let opening_id = 0; // newly created opening
  665. let appy_on_worker_opening_fixture =
  666. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  667. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  668. let application_id = 0; // newly created application
  669. let invalid_author_account_id = 55;
  670. let withdraw_application_fixture =
  671. WithdrawApplicationFixture::default_for_application_id(application_id)
  672. .with_signer(invalid_author_account_id);
  673. withdraw_application_fixture.call_and_assert(Err(crate::MSG_ORIGIN_IS_NOT_APPLICANT));
  674. });
  675. }
  676. #[test]
  677. fn withdraw_worker_application_fails_with_hiring_error() {
  678. build_test_externalities().execute_with(|| {
  679. let lead_account_id = 1;
  680. SetLeadFixture::set_lead(lead_account_id);
  681. setup_members(2);
  682. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  683. add_worker_opening_fixture.call_and_assert(Ok(()));
  684. let opening_id = 0; // newly created opening
  685. let appy_on_worker_opening_fixture =
  686. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  687. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  688. let application_id = 0; // newly created application
  689. let withdraw_application_fixture =
  690. WithdrawApplicationFixture::default_for_application_id(application_id);
  691. withdraw_application_fixture.call_and_assert(Ok(()));
  692. withdraw_application_fixture.call_and_assert(Err(
  693. crate::errors::MSG_WITHDRAW_WORKER_APPLICATION_APPLICATION_NOT_ACTIVE,
  694. ));
  695. });
  696. }
  697. #[test]
  698. fn terminate_worker_application_succeeds() {
  699. build_test_externalities().execute_with(|| {
  700. let lead_account_id = 1;
  701. SetLeadFixture::set_lead(lead_account_id);
  702. setup_members(2);
  703. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  704. add_worker_opening_fixture.call_and_assert(Ok(()));
  705. let opening_id = 0; // newly created opening
  706. let appy_on_worker_opening_fixture =
  707. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  708. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  709. let application_id = 0; // newly created application
  710. let terminate_application_fixture =
  711. TerminateApplicationFixture::default_for_application_id(application_id);
  712. terminate_application_fixture.call_and_assert(Ok(()));
  713. EventFixture::assert_global_events(vec![
  714. TestEvent::bureaucracy_Instance1(RawEvent::LeaderSet(1, lead_account_id)),
  715. TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
  716. TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
  717. TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningAdded(opening_id)),
  718. TestEvent::bureaucracy_Instance1(RawEvent::AppliedOnWorkerOpening(
  719. opening_id,
  720. application_id,
  721. )),
  722. TestEvent::bureaucracy_Instance1(RawEvent::WorkerApplicationTerminated(application_id)),
  723. ]);
  724. });
  725. }
  726. #[test]
  727. fn terminate_worker_application_fails_with_invalid_application_author() {
  728. build_test_externalities().execute_with(|| {
  729. let lead_account_id = 1;
  730. SetLeadFixture::set_lead(lead_account_id);
  731. setup_members(2);
  732. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  733. add_worker_opening_fixture.call_and_assert(Ok(()));
  734. let opening_id = 0; // newly created opening
  735. let appy_on_worker_opening_fixture =
  736. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  737. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  738. let application_id = 0; // newly created application
  739. let invalid_author_account_id = 55;
  740. let terminate_application_fixture =
  741. TerminateApplicationFixture::default_for_application_id(application_id)
  742. .with_signer(invalid_author_account_id);
  743. terminate_application_fixture.call_and_assert(Err(crate::MSG_IS_NOT_LEAD_ACCOUNT));
  744. });
  745. }
  746. #[test]
  747. fn terminate_worker_application_fails_invalid_origin() {
  748. build_test_externalities().execute_with(|| {
  749. let lead_account_id = 1;
  750. SetLeadFixture::set_lead(lead_account_id);
  751. setup_members(2);
  752. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  753. add_worker_opening_fixture.call_and_assert(Ok(()));
  754. let opening_id = 0; // newly created opening
  755. let appy_on_worker_opening_fixture =
  756. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  757. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  758. let application_id = 0; // newly created application
  759. let terminate_application_fixture =
  760. TerminateApplicationFixture::default_for_application_id(application_id)
  761. .with_origin(RawOrigin::None);
  762. terminate_application_fixture.call_and_assert(Err("RequireSignedOrigin"));
  763. });
  764. }
  765. #[test]
  766. fn terminate_worker_application_fails_invalid_application_id() {
  767. build_test_externalities().execute_with(|| {
  768. let lead_account_id = 1;
  769. SetLeadFixture::set_lead(lead_account_id);
  770. let invalid_application_id = 6;
  771. let terminate_application_fixture =
  772. TerminateApplicationFixture::default_for_application_id(invalid_application_id);
  773. terminate_application_fixture
  774. .call_and_assert(Err(crate::MSG_WORKER_APPLICATION_DOES_NOT_EXIST));
  775. });
  776. }
  777. #[test]
  778. fn terminate_worker_application_fails_with_hiring_error() {
  779. build_test_externalities().execute_with(|| {
  780. let lead_account_id = 1;
  781. SetLeadFixture::set_lead(lead_account_id);
  782. setup_members(2);
  783. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  784. add_worker_opening_fixture.call_and_assert(Ok(()));
  785. let opening_id = 0; // newly created opening
  786. let appy_on_worker_opening_fixture =
  787. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  788. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  789. let application_id = 0; // newly created application
  790. let terminate_application_fixture =
  791. TerminateApplicationFixture::default_for_application_id(application_id);
  792. terminate_application_fixture.call_and_assert(Ok(()));
  793. terminate_application_fixture.call_and_assert(Err(
  794. crate::errors::MSG_WITHDRAW_WORKER_APPLICATION_APPLICATION_NOT_ACTIVE,
  795. ));
  796. });
  797. }
  798. #[test]
  799. fn begin_review_worker_applications_succeeds() {
  800. build_test_externalities().execute_with(|| {
  801. let lead_account_id = 1;
  802. SetLeadFixture::set_lead(lead_account_id);
  803. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  804. add_worker_opening_fixture.call_and_assert(Ok(()));
  805. let opening_id = 0; // newly created opening
  806. let begin_review_worker_applications_fixture =
  807. BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
  808. begin_review_worker_applications_fixture.call_and_assert(Ok(()));
  809. EventFixture::assert_crate_events(vec![
  810. RawEvent::LeaderSet(1, lead_account_id),
  811. RawEvent::WorkerOpeningAdded(opening_id),
  812. RawEvent::BeganWorkerApplicationReview(opening_id),
  813. ]);
  814. });
  815. }
  816. #[test]
  817. fn begin_review_worker_applications_fails_with_not_a_lead() {
  818. build_test_externalities().execute_with(|| {
  819. let lead_account_id = 1;
  820. SetLeadFixture::set_lead(lead_account_id);
  821. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  822. add_worker_opening_fixture.call_and_assert(Ok(()));
  823. let new_lead_account_id = 33;
  824. SetLeadFixture::set_lead(new_lead_account_id);
  825. let opening_id = 0; // newly created opening
  826. let begin_review_worker_applications_fixture =
  827. BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
  828. begin_review_worker_applications_fixture
  829. .call_and_assert(Err(crate::MSG_IS_NOT_LEAD_ACCOUNT));
  830. });
  831. }
  832. #[test]
  833. fn begin_review_worker_applications_fails_with_invalid_opening() {
  834. build_test_externalities().execute_with(|| {
  835. let lead_account_id = 1;
  836. SetLeadFixture::set_lead(lead_account_id);
  837. let invalid_opening_id = 6; // newly created opening
  838. let begin_review_worker_applications_fixture =
  839. BeginReviewWorkerApplicationsFixture::default_for_opening_id(invalid_opening_id);
  840. begin_review_worker_applications_fixture
  841. .call_and_assert(Err(crate::MSG_WORKER_OPENING_DOES_NOT_EXIST));
  842. });
  843. }
  844. #[test]
  845. fn begin_review_worker_applications_with_hiring_error() {
  846. build_test_externalities().execute_with(|| {
  847. let lead_account_id = 1;
  848. SetLeadFixture::set_lead(lead_account_id);
  849. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  850. add_worker_opening_fixture.call_and_assert(Ok(()));
  851. let opening_id = 0; // newly created opening
  852. let begin_review_worker_applications_fixture =
  853. BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
  854. begin_review_worker_applications_fixture.call_and_assert(Ok(()));
  855. begin_review_worker_applications_fixture.call_and_assert(Err(
  856. crate::errors::MSG_BEGIN_WORKER_APPLICANT_REVIEW_OPENING_OPENING_IS_NOT_WAITING_TO_BEGIN,
  857. ));
  858. });
  859. }
  860. #[test]
  861. fn begin_review_worker_applications_fails_with_invalid_origin() {
  862. build_test_externalities().execute_with(|| {
  863. let lead_account_id = 1;
  864. SetLeadFixture::set_lead(lead_account_id);
  865. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  866. add_worker_opening_fixture.call_and_assert(Ok(()));
  867. let opening_id = 0; // newly created opening
  868. let begin_review_worker_applications_fixture =
  869. BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id)
  870. .with_origin(RawOrigin::None);
  871. begin_review_worker_applications_fixture.call_and_assert(Err("RequireSignedOrigin"));
  872. });
  873. }
  874. #[test]
  875. fn fill_worker_opening_succeeds() {
  876. build_test_externalities().execute_with(|| {
  877. let lead_account_id = 1;
  878. SetLeadFixture::set_lead(lead_account_id);
  879. setup_members(2);
  880. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  881. add_worker_opening_fixture.call_and_assert(Ok(()));
  882. let opening_id = 0; // newly created opening
  883. let appy_on_worker_opening_fixture =
  884. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  885. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  886. let application_id = 0; // newly created application
  887. let begin_review_worker_applications_fixture =
  888. BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
  889. begin_review_worker_applications_fixture.call_and_assert(Ok(()));
  890. let fill_worker_opening_fixture =
  891. FillWorkerOpeningFixture::default_for_ids(opening_id, vec![application_id]);
  892. fill_worker_opening_fixture.call_and_assert(Ok(()));
  893. let worker_id = 0; // newly created worker
  894. let mut worker_application_dictionary = BTreeMap::new();
  895. worker_application_dictionary.insert(application_id, worker_id);
  896. EventFixture::assert_global_events(vec![
  897. TestEvent::bureaucracy_Instance1(RawEvent::LeaderSet(1, lead_account_id)),
  898. TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(0, 0)),
  899. TestEvent::membership_mod(membership::members::RawEvent::MemberRegistered(1, 1)),
  900. TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningAdded(opening_id)),
  901. TestEvent::bureaucracy_Instance1(RawEvent::AppliedOnWorkerOpening(
  902. opening_id,
  903. application_id,
  904. )),
  905. TestEvent::bureaucracy_Instance1(RawEvent::BeganWorkerApplicationReview(opening_id)),
  906. TestEvent::bureaucracy_Instance1(RawEvent::WorkerOpeningFilled(
  907. opening_id,
  908. worker_application_dictionary,
  909. )),
  910. ]);
  911. });
  912. }
  913. #[test]
  914. fn fill_worker_opening_fails_with_invalid_origin() {
  915. build_test_externalities().execute_with(|| {
  916. let lead_account_id = 1;
  917. SetLeadFixture::set_lead(lead_account_id);
  918. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  919. add_worker_opening_fixture.call_and_assert(Ok(()));
  920. let opening_id = 0; // newly created opening
  921. let fill_worker_opening_fixture =
  922. FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new())
  923. .with_origin(RawOrigin::None);
  924. fill_worker_opening_fixture.call_and_assert(Err("RequireSignedOrigin"));
  925. });
  926. }
  927. #[test]
  928. fn fill_worker_opening_fails_with_not_a_lead() {
  929. build_test_externalities().execute_with(|| {
  930. let lead_account_id = 1;
  931. SetLeadFixture::set_lead(lead_account_id);
  932. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  933. add_worker_opening_fixture.call_and_assert(Ok(()));
  934. let new_lead_account_id = 33;
  935. SetLeadFixture::set_lead(new_lead_account_id);
  936. let opening_id = 0; // newly created opening
  937. let fill_worker_opening_fixture =
  938. FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new());
  939. fill_worker_opening_fixture.call_and_assert(Err(crate::MSG_IS_NOT_LEAD_ACCOUNT));
  940. });
  941. }
  942. #[test]
  943. fn fill_worker_opening_fails_with_invalid_opening() {
  944. build_test_externalities().execute_with(|| {
  945. let lead_account_id = 1;
  946. SetLeadFixture::set_lead(lead_account_id);
  947. let invalid_opening_id = 6; // newly created opening
  948. let fill_worker_opening_fixture =
  949. FillWorkerOpeningFixture::default_for_ids(invalid_opening_id, Vec::new());
  950. fill_worker_opening_fixture.call_and_assert(Err(crate::MSG_WORKER_OPENING_DOES_NOT_EXIST));
  951. });
  952. }
  953. #[test]
  954. fn fill_worker_opening_fails_with_invalid_application_list() {
  955. build_test_externalities().execute_with(|| {
  956. let lead_account_id = 1;
  957. SetLeadFixture::set_lead(lead_account_id);
  958. setup_members(2);
  959. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  960. add_worker_opening_fixture.call_and_assert(Ok(()));
  961. let opening_id = 0; // newly created opening
  962. let appy_on_worker_opening_fixture =
  963. ApplyOnWorkerOpeningFixture::default_for_opening_id(opening_id);
  964. appy_on_worker_opening_fixture.call_and_assert(Ok(()));
  965. let application_id = 0; // newly created application
  966. let begin_review_worker_applications_fixture =
  967. BeginReviewWorkerApplicationsFixture::default_for_opening_id(opening_id);
  968. begin_review_worker_applications_fixture.call_and_assert(Ok(()));
  969. let invalid_application_id = 66;
  970. let fill_worker_opening_fixture = FillWorkerOpeningFixture::default_for_ids(
  971. opening_id,
  972. vec![application_id, invalid_application_id],
  973. );
  974. fill_worker_opening_fixture
  975. .call_and_assert(Err(crate::MSG_SUCCESSFUL_WORKER_APPLICATION_DOES_NOT_EXIST));
  976. });
  977. }
  978. #[test]
  979. fn fill_worker_opening_fails_with_invalid_application_with_hiring_error() {
  980. build_test_externalities().execute_with(|| {
  981. let lead_account_id = 1;
  982. SetLeadFixture::set_lead(lead_account_id);
  983. setup_members(2);
  984. let add_worker_opening_fixture = AddWorkerOpeningFixture::default();
  985. add_worker_opening_fixture.call_and_assert(Ok(()));
  986. let opening_id = 0; // newly created opening
  987. let fill_worker_opening_fixture =
  988. FillWorkerOpeningFixture::default_for_ids(opening_id, Vec::new());
  989. fill_worker_opening_fixture.call_and_assert(Err(
  990. crate::errors::MSG_FULL_WORKER_OPENING_OPENING_NOT_IN_REVIEW_PERIOD_STAGE,
  991. ));
  992. });
  993. }