Cleaned up errors a bit.
This commit is contained in:
@@ -37,7 +37,7 @@ impl RecurringTransactionRequest {
|
||||
pub fn into_domain(
|
||||
self,
|
||||
id: Uuid,
|
||||
) -> Result<domain::RecurringTransaction, domain::ValidationError> {
|
||||
) -> Result<domain::RecurringTransaction, domain::DomainError> {
|
||||
let recurrence = domain::Recurrence {
|
||||
every: domain::RecurrenceInterval::try_from(self.schedule.recurrence.every)?,
|
||||
unit: self.schedule.recurrence.unit.into(),
|
||||
@@ -189,7 +189,10 @@ mod tests {
|
||||
ScheduleRequest, ScheduledTransactionRequest, ScheduledTransactionResponse,
|
||||
WeekendAdjustment,
|
||||
};
|
||||
use crate::{domain, routes::dtos::direction::Direction};
|
||||
use crate::{
|
||||
domain::{self, ScheduleError},
|
||||
routes::dtos::direction::Direction,
|
||||
};
|
||||
|
||||
fn request(amount_cents: u64) -> RecurringTransactionRequest {
|
||||
RecurringTransactionRequest {
|
||||
@@ -256,21 +259,23 @@ mod tests {
|
||||
fn rejects_invalid_requests() {
|
||||
assert!(matches!(
|
||||
request(i64::MAX as u64 + 1).into_domain(Uuid::nil()),
|
||||
Err(domain::ValidationError::Amount(_))
|
||||
Err(domain::DomainError::Amount(_))
|
||||
));
|
||||
|
||||
let mut every = request(100);
|
||||
every.schedule.recurrence.every = 0;
|
||||
assert!(matches!(
|
||||
every.into_domain(Uuid::nil()),
|
||||
Err(domain::ValidationError::RecurrenceInterval(_))
|
||||
Err(domain::DomainError::Schedule(
|
||||
ScheduleError::RecurrenceInterval(_)
|
||||
))
|
||||
));
|
||||
|
||||
let mut end = request(100);
|
||||
end.schedule.end = Some(end.schedule.start - TimeDelta::seconds(1));
|
||||
assert!(matches!(
|
||||
end.into_domain(Uuid::nil()),
|
||||
Err(domain::ValidationError::EndBeforeStart)
|
||||
Err(domain::DomainError::Schedule(ScheduleError::EndBeforeStart))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct TransactionRequest {
|
||||
}
|
||||
|
||||
impl TransactionRequest {
|
||||
pub fn into_domain(self, id: Uuid) -> Result<domain::Transaction, domain::ValidationError> {
|
||||
pub fn into_domain(self, id: Uuid) -> Result<domain::Transaction, domain::DomainError> {
|
||||
Ok(domain::Transaction {
|
||||
id,
|
||||
description: self.description,
|
||||
@@ -80,7 +80,7 @@ mod tests {
|
||||
.unwrap_err();
|
||||
assert!(matches!(
|
||||
error,
|
||||
domain::ValidationError::Amount(domain::CentsConversionError(value))
|
||||
domain::DomainError::Amount(domain::CentsError(value))
|
||||
if value == i64::MAX as i128 + 1
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user