fix unit test

This commit is contained in:
Namekuji 2023-06-02 07:08:58 -04:00
parent e51deb3794
commit 403e95b673
No known key found for this signature in database
GPG Key ID: B541BD6E646CABC7
9 changed files with 35 additions and 21 deletions

View File

@ -5,7 +5,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
default = ["napi"]
noarray = []
napi = ["dep:napi", "dep:napi-derive"]
@ -30,3 +30,6 @@ utoipa = "3.3.0"
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.12.0", default-features = false, features = ["napi4"], optional = true }
napi-derive = { version = "2.12.0", optional = true }
[dev-dependencies]
pretty_assertions = "1.3.0"

View File

@ -8,11 +8,13 @@ use schemars::{schema_for, JsonSchema};
cfg_if! {
if #[cfg(feature = "napi")] {
mod napi;
pub use napi::antenna::Antenna;
pub use napi::antenna::AntennaSrc;
pub use self::napi::antenna::Antenna;
pub use self::napi::antenna::AntennaSrc;
} else {
pub use antenna::Antenna;
pub use antenna::AntennaSrc;
pub use app::App;
pub use app::AppPermission;
}
}

View File

@ -46,7 +46,7 @@ pub enum AntennaSrc {
Instances,
}
impl TryFrom<AntennaSrcEnum> for AntennaSrc {
impl TryFrom<AntennaSrcEnum> for super::AntennaSrc {
type Error = crate::error::Error;
fn try_from(value: AntennaSrcEnum) -> Result<Self, Self::Error> {
@ -55,12 +55,13 @@ impl TryFrom<AntennaSrcEnum> for AntennaSrc {
}
// ---- TODO: could be macro
impl Schema<Self> for Antenna {}
pub static VALIDATOR: Lazy<JSONSchema> = Lazy::new(|| Antenna::validator());
impl Schema<Self> for super::Antenna {}
pub static VALIDATOR: Lazy<JSONSchema> = Lazy::new(|| super::Antenna::validator());
// ----
#[cfg(test)]
mod unit_test {
use pretty_assertions::assert_eq;
use serde_json::json;
use crate::{entity::sea_orm_active_enums::AntennaSrcEnum, schema::AntennaSrc};
@ -128,20 +129,23 @@ mod unit_test {
let result = VALIDATOR
.validate(&instance)
.expect_err("validation must fail");
let mut paths: Vec<String> = result.map(|e| e.schema_path.to_string()).collect();
let mut paths: Vec<String> = result
.map(|e| e.instance_path.to_string())
.filter(|e| !e.is_empty())
.collect();
paths.sort();
assert_eq!(
paths,
vec![
"/properties/caseSensitive/type",
"/properties/createdAt/format",
"/properties/excludeKeywords/type",
"/properties/id/type",
"/properties/keywords/type",
"/properties/src/enum",
"/properties/userListId/type",
"/properties/users/items/type",
"/required"
"/caseSensitive",
#[cfg(not(feature = "napi"))]
"/createdAt",
"/excludeKeywords",
"/id",
"/keywords",
"/src",
"/userListId",
"/users/0"
]
);
}

View File

@ -13,14 +13,14 @@ pub struct App {
#[schemars(url)]
pub callback_url: Option<String>,
#[schema(inline)]
pub permission: Vec<Permission>,
pub permission: Vec<AppPermission>,
pub secret: Option<String>,
pub is_authorized: Option<bool>,
}
/// This represents `permissions` in `packages/calckey-js/src/consts.ts`.
#[derive(Clone, Debug, PartialEq, Eq, JsonSchema, ToSchema)]
pub enum Permission {
pub enum AppPermission {
#[serde(rename = "read:account")]
ReadAccount,
#[serde(rename = "write:account")]

View File

@ -1,10 +1,9 @@
use napi::bindgen_prelude::{FromNapiValue, ToNapiValue};
use napi_derive::napi;
use parse_display::FromStr;
use schemars::JsonSchema;
use utoipa::ToSchema;
use napi::bindgen_prelude::{FromNapiValue, ToNapiValue};
use napi_derive::napi;
#[napi]
#[derive(Clone, Debug, PartialEq, Eq, JsonSchema, ToSchema)]
#[serde(rename_all = "camelCase")]

View File

@ -4,6 +4,7 @@ mod int_test {
repository::Repository,
schema,
};
use pretty_assertions::assert_eq;
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
use crate::{cleanup, prepare};

View File

@ -10,3 +10,6 @@ cuid2 = "0.1.0"
once_cell = "1.17.1"
rand = "0.8.5"
thiserror = "1.0.40"
[dev-dependencies]
pretty_assertions = "1.3.0"

View File

@ -22,6 +22,7 @@ pub fn create_id() -> Result<String, ErrorUninitialized> {
#[cfg(test)]
mod unit_test {
use pretty_assertions::{assert_eq, assert_ne};
use std::thread;
use crate::id;

View File

@ -10,6 +10,7 @@ pub fn gen_string(length: u16) -> String {
#[cfg(test)]
mod unit_test {
use pretty_assertions::{assert_eq, assert_ne};
use std::thread;
use super::gen_string;