Fix update account, db tests
This commit is contained in:
parent
d445eb17b2
commit
93c66d33bf
@ -1,6 +1,6 @@
|
||||
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 {
|
||||
#[error("Can't load account addresses")]
|
||||
AccountAddresses,
|
||||
|
@ -5,7 +5,7 @@ use sqlx::PgPool;
|
||||
|
||||
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")]
|
||||
pub enum Error {
|
||||
#[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")]
|
||||
pub enum Error {
|
||||
#[error("{0}")]
|
||||
|
@ -1,6 +1,6 @@
|
||||
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 {
|
||||
#[error("Can't load account addresses")]
|
||||
OrderAddress,
|
||||
|
@ -6,7 +6,7 @@ use sqlx::PgPool;
|
||||
use super::Result;
|
||||
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 {
|
||||
#[error("Can't create order item")]
|
||||
CantCreate,
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
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")]
|
||||
pub enum Error {
|
||||
#[error("Can't create account order")]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{MultiLoad, Result};
|
||||
|
||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("Failed to create photo")]
|
||||
Create,
|
||||
|
@ -1,6 +1,6 @@
|
||||
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 {
|
||||
#[error("Failed to attach photo to product")]
|
||||
Create,
|
||||
|
@ -9,7 +9,7 @@ use model::{
|
||||
use super::Result;
|
||||
use crate::MultiLoad;
|
||||
|
||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("Unable to load all products")]
|
||||
All,
|
||||
@ -22,7 +22,7 @@ pub enum Error {
|
||||
#[error("Unable to find products for shopping cart")]
|
||||
ShoppingCartProducts,
|
||||
#[error("Product with id {0} can't be found")]
|
||||
Single(model::ProductId),
|
||||
Single(ProductId),
|
||||
#[error("Failed to load products for given ids")]
|
||||
FindProducts,
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use sqlx::PgPool;
|
||||
use super::Result;
|
||||
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 {
|
||||
#[error("Can't create shopping cart item")]
|
||||
CantCreate,
|
||||
|
@ -4,7 +4,7 @@ use sqlx::PgPool;
|
||||
use super::Result;
|
||||
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 {
|
||||
#[error("Can't create shopping cart")]
|
||||
CantCreate,
|
||||
|
@ -4,7 +4,7 @@ use sqlx::PgPool;
|
||||
|
||||
use crate::{MultiLoad, Result};
|
||||
|
||||
#[derive(Debug, Copy, Clone, serde::Serialize, thiserror::Error)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("Unable to load all stocks")]
|
||||
All,
|
||||
|
@ -4,7 +4,7 @@ use sqlx::PgPool;
|
||||
|
||||
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 {
|
||||
#[error("Failed to save new token")]
|
||||
Create,
|
||||
@ -220,4 +220,57 @@ mod tests {
|
||||
|
||||
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 = "db", derive(sqlx::Type))]
|
||||
#[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)]
|
||||
pub struct ShoppingCartId(pub RecordId);
|
||||
|
||||
@ -979,7 +979,7 @@ pub struct ShoppingCart {
|
||||
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
||||
#[cfg_attr(feature = "db", derive(sqlx::Type))]
|
||||
#[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)]
|
||||
pub struct ShoppingCartItemId(RecordId);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user