helper methods on enums we'll need

This commit is contained in:
Brandon Thomas committed 2026-03-22 17:32:22 -04:00
1 parent 83a8852cef
commit 204ff6cef8
4 files changed
+130

No files matched your search

@@ -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::*;