mirror of
https://github.com/storytold/artcraft.git
synced 2026-10-20 17:02:53 -04:00
enums helper methods, cleanup (#1190)
This commit is contained in:
Generated
-1
@@ -3833,7 +3833,6 @@ dependencies = [
|
||||
"sqlx-mysql",
|
||||
"strum",
|
||||
"toml 1.0.7+spec-1.1.0",
|
||||
"utoipa",
|
||||
"workspace-build-acceleration",
|
||||
]
|
||||
|
||||
|
||||
@@ -21,6 +21,19 @@ pub enum ArtcraftCreditsPackSlug {
|
||||
Artcraft50000,
|
||||
}
|
||||
|
||||
impl ArtcraftCreditsPackSlug {
|
||||
pub const fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Artcraft1000 => "artcraft_1000",
|
||||
Self::Artcraft2500 => "artcraft_2500",
|
||||
Self::Artcraft5000 => "artcraft_5000",
|
||||
Self::Artcraft10000 => "artcraft_10000",
|
||||
Self::Artcraft25000 => "artcraft_25000",
|
||||
Self::Artcraft50000 => "artcraft_50000",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ArtcraftCreditsPackSlug;
|
||||
@@ -56,6 +69,28 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
mod to_str_checks {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn to_str() {
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft1000.to_str(), "artcraft_1000");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft2500.to_str(), "artcraft_2500");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft5000.to_str(), "artcraft_5000");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft10000.to_str(), "artcraft_10000");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft25000.to_str(), "artcraft_25000");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft50000.to_str(), "artcraft_50000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_str_matches_serde() {
|
||||
for variant in ArtcraftCreditsPackSlug::iter() {
|
||||
let serde_str = serde_json::to_string(&variant).unwrap().replace('"', "");
|
||||
assert_eq!(variant.to_str(), serde_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -12,6 +12,16 @@ pub enum ArtcraftSubscriptionSlug {
|
||||
ArtcraftMax,
|
||||
}
|
||||
|
||||
impl ArtcraftSubscriptionSlug {
|
||||
pub const fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::ArtcraftBasic => "artcraft_basic",
|
||||
Self::ArtcraftPro => "artcraft_pro",
|
||||
Self::ArtcraftMax => "artcraft_max",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ArtcraftSubscriptionSlug;
|
||||
@@ -41,6 +51,25 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
mod to_str_checks {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn to_str() {
|
||||
assert_eq!(ArtcraftSubscriptionSlug::ArtcraftBasic.to_str(), "artcraft_basic");
|
||||
assert_eq!(ArtcraftSubscriptionSlug::ArtcraftPro.to_str(), "artcraft_pro");
|
||||
assert_eq!(ArtcraftSubscriptionSlug::ArtcraftMax.to_str(), "artcraft_max");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_str_matches_serde() {
|
||||
for variant in ArtcraftSubscriptionSlug::iter() {
|
||||
let serde_str = serde_json::to_string(&variant).unwrap().replace('"', "");
|
||||
assert_eq!(variant.to_str(), serde_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -24,6 +24,21 @@ pub enum JobStatusPlus {
|
||||
CancelledBySystem,
|
||||
}
|
||||
|
||||
impl JobStatusPlus {
|
||||
pub const fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Pending => "pending",
|
||||
Self::Started => "started",
|
||||
Self::CompleteSuccess => "complete_success",
|
||||
Self::CompleteFailure => "complete_failure",
|
||||
Self::AttemptFailed => "attempt_failed",
|
||||
Self::Dead => "dead",
|
||||
Self::CancelledByUser => "cancelled_by_user",
|
||||
Self::CancelledBySystem => "cancelled_by_system",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::JobStatusPlus;
|
||||
@@ -63,6 +78,30 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
mod to_str_checks {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn to_str() {
|
||||
assert_eq!(JobStatusPlus::Pending.to_str(), "pending");
|
||||
assert_eq!(JobStatusPlus::Started.to_str(), "started");
|
||||
assert_eq!(JobStatusPlus::CompleteSuccess.to_str(), "complete_success");
|
||||
assert_eq!(JobStatusPlus::CompleteFailure.to_str(), "complete_failure");
|
||||
assert_eq!(JobStatusPlus::AttemptFailed.to_str(), "attempt_failed");
|
||||
assert_eq!(JobStatusPlus::Dead.to_str(), "dead");
|
||||
assert_eq!(JobStatusPlus::CancelledByUser.to_str(), "cancelled_by_user");
|
||||
assert_eq!(JobStatusPlus::CancelledBySystem.to_str(), "cancelled_by_system");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_str_matches_serde() {
|
||||
for variant in JobStatusPlus::iter() {
|
||||
let serde_str = serde_json::to_string(&variant).unwrap().replace('"', "");
|
||||
assert_eq!(variant.to_str(), serde_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -13,6 +13,15 @@ pub enum PaymentsNamespace {
|
||||
FakeYou,
|
||||
}
|
||||
|
||||
impl PaymentsNamespace {
|
||||
pub const fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Artcraft => "artcraft",
|
||||
Self::FakeYou => "fakeyou",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::PaymentsNamespace;
|
||||
@@ -40,6 +49,24 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
mod to_str_checks {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn to_str() {
|
||||
assert_eq!(PaymentsNamespace::Artcraft.to_str(), "artcraft");
|
||||
assert_eq!(PaymentsNamespace::FakeYou.to_str(), "fakeyou");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_str_matches_serde() {
|
||||
for variant in PaymentsNamespace::iter() {
|
||||
let serde_str = serde_json::to_string(&variant).unwrap().replace('"', "");
|
||||
assert_eq!(variant.to_str(), serde_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -15,10 +15,6 @@ normal = ["workspace-build-acceleration"]
|
||||
name = "enums_db"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
utoipa = ["dep:utoipa"]
|
||||
|
||||
[dependencies]
|
||||
# Workspace hack (faster compile times)
|
||||
workspace-build-acceleration.workspace = true
|
||||
@@ -35,9 +31,6 @@ sqlx = { version = "0.7.4", features = [ "mysql", "runtime-tokio-rustls", "chron
|
||||
sqlx-core = { version = "0.7.4" }
|
||||
sqlx-mysql = { version = "0.7.4" }
|
||||
|
||||
# API Documentation (optional — enabled by crates that need ToSchema on DB enums)
|
||||
utoipa = { workspace = true, optional = true }
|
||||
|
||||
# Enum utilities (EnumIter, EnumCount)
|
||||
strum.workspace = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user