Fix update account, db tests
This commit is contained in:
parent
d445eb17b2
commit
93c66d33bf
@ -1,6 +1,6 @@
|
|||||||
use crate::{db_async_handler, Result};
|
use crate::{db_async_handler, Result};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Can't load account addresses")]
|
#[error("Can't load account addresses")]
|
||||||
AccountAddresses,
|
AccountAddresses,
|
||||||
|
@ -5,7 +5,7 @@ use sqlx::PgPool;
|
|||||||
|
|
||||||
use crate::{db_async_handler, Result};
|
use crate::{db_async_handler, Result};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Can't create account")]
|
#[error("Can't create account")]
|
||||||
|
@ -124,7 +124,7 @@ macro_rules! query_db {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{db_async_handler, Result};
|
use crate::{db_async_handler, Result};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Can't load account addresses")]
|
#[error("Can't load account addresses")]
|
||||||
OrderAddress,
|
OrderAddress,
|
||||||
|
@ -6,7 +6,7 @@ use sqlx::PgPool;
|
|||||||
use super::Result;
|
use super::Result;
|
||||||
use crate::db_async_handler;
|
use crate::db_async_handler;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Can't create order item")]
|
#[error("Can't create order item")]
|
||||||
CantCreate,
|
CantCreate,
|
||||||
|
@ -7,7 +7,7 @@ use crate::{
|
|||||||
ShoppingCartSetState,
|
ShoppingCartSetState,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
#[serde(rename_all = "kebab-case", tag = "account-order")]
|
#[serde(rename_all = "kebab-case", tag = "account-order")]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Can't create account order")]
|
#[error("Can't create account order")]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{MultiLoad, Result};
|
use crate::{MultiLoad, Result};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Failed to create photo")]
|
#[error("Failed to create photo")]
|
||||||
Create,
|
Create,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{db_async_handler, Result};
|
use crate::{db_async_handler, Result};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Failed to attach photo to product")]
|
#[error("Failed to attach photo to product")]
|
||||||
Create,
|
Create,
|
||||||
|
@ -9,7 +9,7 @@ use model::{
|
|||||||
use super::Result;
|
use super::Result;
|
||||||
use crate::MultiLoad;
|
use crate::MultiLoad;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Unable to load all products")]
|
#[error("Unable to load all products")]
|
||||||
All,
|
All,
|
||||||
@ -22,7 +22,7 @@ pub enum Error {
|
|||||||
#[error("Unable to find products for shopping cart")]
|
#[error("Unable to find products for shopping cart")]
|
||||||
ShoppingCartProducts,
|
ShoppingCartProducts,
|
||||||
#[error("Product with id {0} can't be found")]
|
#[error("Product with id {0} can't be found")]
|
||||||
Single(model::ProductId),
|
Single(ProductId),
|
||||||
#[error("Failed to load products for given ids")]
|
#[error("Failed to load products for given ids")]
|
||||||
FindProducts,
|
FindProducts,
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use sqlx::PgPool;
|
|||||||
use super::Result;
|
use super::Result;
|
||||||
use crate::db_async_handler;
|
use crate::db_async_handler;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Can't create shopping cart item")]
|
#[error("Can't create shopping cart item")]
|
||||||
CantCreate,
|
CantCreate,
|
||||||
|
@ -4,7 +4,7 @@ use sqlx::PgPool;
|
|||||||
use super::Result;
|
use super::Result;
|
||||||
use crate::db_async_handler;
|
use crate::db_async_handler;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Can't create shopping cart")]
|
#[error("Can't create shopping cart")]
|
||||||
CantCreate,
|
CantCreate,
|
||||||
|
@ -4,7 +4,7 @@ use sqlx::PgPool;
|
|||||||
|
|
||||||
use crate::{MultiLoad, Result};
|
use crate::{MultiLoad, Result};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Unable to load all stocks")]
|
#[error("Unable to load all stocks")]
|
||||||
All,
|
All,
|
||||||
|
@ -4,7 +4,7 @@ use sqlx::PgPool;
|
|||||||
|
|
||||||
use crate::{db_async_handler, Result};
|
use crate::{db_async_handler, Result};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Failed to save new token")]
|
#[error("Failed to save new token")]
|
||||||
Create,
|
Create,
|
||||||
@ -220,4 +220,57 @@ mod tests {
|
|||||||
|
|
||||||
test_create_account(db).await;
|
test_create_account(db).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix::test]
|
||||||
|
async fn find_by_jti() {
|
||||||
|
let config = config::default_load(&mut NoOpts);
|
||||||
|
config
|
||||||
|
.lock()
|
||||||
|
.database_mut()
|
||||||
|
.set_url("postgres://postgres@localhost/bazzar_test");
|
||||||
|
|
||||||
|
let db = Database::build(config).await.start();
|
||||||
|
|
||||||
|
let original = test_create_token_extended(db.clone(), None, None, None, None, None).await;
|
||||||
|
|
||||||
|
let found = db
|
||||||
|
.send(TokenByJti {
|
||||||
|
jti: original.jwt_id,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(found, original);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix::test]
|
||||||
|
async fn find_by_jti_expired() {
|
||||||
|
let config = config::default_load(&mut NoOpts);
|
||||||
|
config
|
||||||
|
.lock()
|
||||||
|
.database_mut()
|
||||||
|
.set_url("postgres://postgres@localhost/bazzar_test");
|
||||||
|
|
||||||
|
let db = Database::build(config).await.start();
|
||||||
|
|
||||||
|
let original = test_create_token_extended(
|
||||||
|
db.clone(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some((chrono::Utc::now() - chrono::Duration::seconds(1)).naive_utc()),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let found = db
|
||||||
|
.send(TokenByJti {
|
||||||
|
jti: original.jwt_id,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(found, Err(crate::Error::Token(super::Error::Jti)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -961,7 +961,7 @@ pub struct OrderItem {
|
|||||||
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
||||||
#[cfg_attr(feature = "db", derive(sqlx::Type))]
|
#[cfg_attr(feature = "db", derive(sqlx::Type))]
|
||||||
#[cfg_attr(feature = "db", sqlx(transparent))]
|
#[cfg_attr(feature = "db", sqlx(transparent))]
|
||||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Deref, Display)]
|
#[derive(Serialize, Deserialize, PartialEq, Copy, Clone, Debug, Deref, Display)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct ShoppingCartId(pub RecordId);
|
pub struct ShoppingCartId(pub RecordId);
|
||||||
|
|
||||||
@ -979,7 +979,7 @@ pub struct ShoppingCart {
|
|||||||
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
||||||
#[cfg_attr(feature = "db", derive(sqlx::Type))]
|
#[cfg_attr(feature = "db", derive(sqlx::Type))]
|
||||||
#[cfg_attr(feature = "db", sqlx(transparent))]
|
#[cfg_attr(feature = "db", sqlx(transparent))]
|
||||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Deref, Display)]
|
#[derive(Serialize, Deserialize, PartialEq, Copy, Clone, Debug, Deref, Display)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct ShoppingCartItemId(RecordId);
|
pub struct ShoppingCartItemId(RecordId);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user