VIARequisitionPresenter extends BaseRequisitionPresenter { @Override protected Observable<Void> createOrUpdateRnrForm() { return Observable.create((Observable.OnSubscribe<Void>) subscriber -> { try { rnrFormRepository.createOrUpdateWithItems(rnRForm); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "VIARequisitionPresenter.createOrUpdateRnrForm").reportToFabric(); subscriber.onError(e); } finally { stockService.monthlyUpdateAvgMonthlyConsumption(); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } VIARequisitionPresenter(); @Override void loadData(long formId, Date periodEndDate); void loadEmergencyData(final List<StockCard> stockCards, final Date periodEndDate); @Override void attachView(BaseView baseView); void populateAdditionalDrugsViewModels(List<RnrFormItem> addedDrugInVIAs, Date periodBegin); void deleteRnRItemFromViewModel(final RnrFormItem rnrFormItem); @Override void updateUIAfterSubmit(); @Override void updateFormUI(); @Override void submitRequisition(); boolean processRequisition(String consultationNumbers); Observable<RnRForm> getSaveFormObservable(final String consultationNumbers); String getConsultationNumbers(); void setConsultationNumbers(String consultationNumbers); void createStockCardsOrUnarchiveAndAddToFormForAdditionalRnrItems(); Observable<Void> removeRnrItem(final RnrFormItem rnrFormItem);  }
@Test public void shouldCreateAndUpdateRnrFormWhenAuthoriseEmergencyViaForm() throws Exception { RnRForm rnRForm = new RnRForm(); rnRForm.setEmergency(true); presenter.rnRForm = rnRForm; TestSubscriber<Void> testSubscriber = new TestSubscriber<>(); presenter.createOrUpdateRnrForm().subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); testSubscriber.assertNoErrors(); verify(mockRnrFormRepository).createOrUpdateWithItems(rnRForm); }
@Test public void shouldNotCreateAndUpdateRnrFormWhenAuthoriseNormalViaForm() throws Exception { RnRForm rnRForm = new RnRForm(); presenter.rnRForm = rnRForm; rnRForm.setEmergency(false); TestSubscriber<Void> testSubscriber = new TestSubscriber<>(); presenter.createOrUpdateRnrForm().subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); testSubscriber.assertNoErrors(); verify(mockRnrFormRepository, never()).createAndRefresh(rnRForm); verify(mockRnrFormRepository).createOrUpdateWithItems(rnRForm); }