This commit is contained in:
+40
-30
@@ -130,15 +130,13 @@ async fn seed_default_meal_categories(pool: &SqlitePool) -> DomainResult<()> {
|
||||
return Ok(());
|
||||
}
|
||||
for (position, category_name) in DEFAULT_MEAL_CATEGORIES.iter().enumerate() {
|
||||
sqlx::query(
|
||||
"INSERT INTO meal_categories (name, position, created_at) VALUES (?1, ?2, ?3)",
|
||||
)
|
||||
.bind(category_name)
|
||||
.bind(position as i64)
|
||||
.bind(now())
|
||||
.execute(pool)
|
||||
.await
|
||||
.map_err(db_error)?;
|
||||
sqlx::query("INSERT INTO meal_categories (name, position, created_at) VALUES (?1, ?2, ?3)")
|
||||
.bind(category_name)
|
||||
.bind(position as i64)
|
||||
.bind(now())
|
||||
.execute(pool)
|
||||
.await
|
||||
.map_err(db_error)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -833,11 +831,12 @@ impl MealCategoryRepository for SqliteMealCategoryRepository {
|
||||
txn: &mut SqliteConnection,
|
||||
name: String,
|
||||
) -> DomainResult<i64> {
|
||||
let position: i64 = sqlx::query("SELECT COALESCE(MAX(position), -1) + 1 FROM meal_categories")
|
||||
.fetch_one(&mut *txn)
|
||||
.await
|
||||
.map_err(db_error)?
|
||||
.get(0);
|
||||
let position: i64 =
|
||||
sqlx::query("SELECT COALESCE(MAX(position), -1) + 1 FROM meal_categories")
|
||||
.fetch_one(&mut *txn)
|
||||
.await
|
||||
.map_err(db_error)?
|
||||
.get(0);
|
||||
let result = sqlx::query(
|
||||
"INSERT INTO meal_categories (name, position, created_at)
|
||||
VALUES (?1, ?2, ?3)",
|
||||
@@ -1181,14 +1180,8 @@ const DEFAULT_CATEGORIES: &[&str] = &[
|
||||
"Household",
|
||||
];
|
||||
|
||||
const DEFAULT_MEAL_CATEGORIES: &[&str] = &[
|
||||
"Beef",
|
||||
"Chicken",
|
||||
"Pasta",
|
||||
"Sandwiches",
|
||||
"Salads",
|
||||
"Soups",
|
||||
];
|
||||
const DEFAULT_MEAL_CATEGORIES: &[&str] =
|
||||
&["Beef", "Chicken", "Pasta", "Sandwiches", "Salads", "Soups"];
|
||||
|
||||
fn hash_secret(secret: &str) -> Vec<u8> {
|
||||
let mut hasher = Sha256::new();
|
||||
@@ -1609,7 +1602,10 @@ mod tests {
|
||||
async fn meal_categories_are_seeded_with_defaults() {
|
||||
let db = setup().await;
|
||||
let categories = get_meal_categories(&db).await;
|
||||
let names = categories.iter().map(|c| c.name.as_str()).collect::<Vec<_>>();
|
||||
let names = categories
|
||||
.iter()
|
||||
.map(|c| c.name.as_str())
|
||||
.collect::<Vec<_>>();
|
||||
assert!(names.contains(&"Beef"));
|
||||
assert!(names.contains(&"Chicken"));
|
||||
assert!(names.contains(&"Pasta"));
|
||||
@@ -1626,7 +1622,9 @@ mod tests {
|
||||
.run(move |txn| {
|
||||
let categories = categories.clone();
|
||||
Box::pin(async move {
|
||||
categories.create_meal_category(txn, "Breakfast".into()).await
|
||||
categories
|
||||
.create_meal_category(txn, "Breakfast".into())
|
||||
.await
|
||||
})
|
||||
})
|
||||
.await
|
||||
@@ -1643,9 +1641,7 @@ mod tests {
|
||||
let result = db
|
||||
.run(move |txn| {
|
||||
let categories = categories.clone();
|
||||
Box::pin(async move {
|
||||
categories.create_meal_category(txn, "Beef".into()).await
|
||||
})
|
||||
Box::pin(async move { categories.create_meal_category(txn, "Beef".into()).await })
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Conflict)));
|
||||
@@ -1659,7 +1655,9 @@ mod tests {
|
||||
.run(move |txn| {
|
||||
let categories = categories.clone();
|
||||
Box::pin(async move {
|
||||
categories.create_meal_category(txn, "Breakfast".into()).await
|
||||
categories
|
||||
.create_meal_category(txn, "Breakfast".into())
|
||||
.await
|
||||
})
|
||||
})
|
||||
.await
|
||||
@@ -1670,7 +1668,13 @@ mod tests {
|
||||
let meals = meals.clone();
|
||||
Box::pin(async move {
|
||||
meals
|
||||
.update_meal(txn, meal.id, "Pancakes".into(), String::new(), Some(category_id))
|
||||
.update_meal(
|
||||
txn,
|
||||
meal.id,
|
||||
"Pancakes".into(),
|
||||
String::new(),
|
||||
Some(category_id),
|
||||
)
|
||||
.await
|
||||
})
|
||||
})
|
||||
@@ -2162,7 +2166,13 @@ mod tests {
|
||||
let meals = meals.clone();
|
||||
Box::pin(async move {
|
||||
meals
|
||||
.update_meal(txn, meal.id, "Pasta al pomodoro".into(), "desc".into(), None)
|
||||
.update_meal(
|
||||
txn,
|
||||
meal.id,
|
||||
"Pasta al pomodoro".into(),
|
||||
"desc".into(),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user