Added Test + Fix builds.rs to handle new stats format
This commit is contained in:
parent
3c47f0c49b
commit
1a4a3c40db
13 changed files with 74 additions and 96 deletions
2
.github/workflows/rust.yml
vendored
2
.github/workflows/rust.yml
vendored
|
@ -18,5 +18,5 @@ jobs:
|
|||
- uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
- name: Run test
|
||||
run: cargo test --verbose
|
||||
|
|
|
@ -11,9 +11,9 @@ license = "MIT"
|
|||
serenity = { version = "0.10.9", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "unstable_discord_api", "collector"] }
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||
reqwest = "0.11.7"
|
||||
serde_derive = "1.0.132"
|
||||
serde = "1.0.132"
|
||||
serde_json = {version = "1.0.73", features = ["indexmap"]}
|
||||
serde_derive = "1.0.140"
|
||||
serde = "1.0.140"
|
||||
serde_json = {version = "1.0.82", features = ["indexmap"]}
|
||||
levenshtein = "1.0.5"
|
||||
regex = "1.5.4"
|
||||
linked-hash-map = "0.5.4"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::fs;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use serenity::builder::CreateEmbed;
|
||||
|
@ -25,12 +26,14 @@ pub struct Artifact {
|
|||
}
|
||||
|
||||
impl Artifact{
|
||||
#[allow(dead_code)]
|
||||
pub async fn get(artifact: &str) -> Artifact {
|
||||
let url = format!("http://localhost:3000/api/artifacts/{}", artifact);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Artifact>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/artifacts");
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
|
@ -81,11 +84,8 @@ impl Artifact{
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn test_artifacts() {
|
||||
for a in Artifact::get_all().await {
|
||||
println!("{}", a);
|
||||
let arti = Artifact::get(&a).await;
|
||||
println!("Name : {}\nCirclet : {}\nBonuses {:?}", arti.name, arti.sets.goblet.unwrap_or(Box::from("")), arti.bonuses);
|
||||
}
|
||||
|
||||
}
|
||||
#[test]
|
||||
fn test_artifact() {
|
||||
let data = fs::read_to_string("test/artifact.json").expect("No Artifact test file");
|
||||
serde_json::from_str::<Artifact>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use std::fs;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -11,15 +12,14 @@ pub struct RoleWeapon {
|
|||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RoleStat {
|
||||
pub sands: Box<str>,
|
||||
pub goblet: Box<str>,
|
||||
pub circlet: Box<str>
|
||||
pub sands: Vec<Box<str>>,
|
||||
pub goblet: Vec<Box<str>>,
|
||||
pub circlet: Vec<Box<str>>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Role{
|
||||
pub name: Box<str>,
|
||||
pub recommended: bool,
|
||||
pub weapons: Vec<RoleWeapon>,
|
||||
pub artifacts: Vec<Vec<Box<str>>>,
|
||||
|
@ -28,6 +28,7 @@ pub struct Role{
|
|||
pub talent: Vec<Box<str>>,
|
||||
pub tip: Box<str>,
|
||||
pub note: Box<str>,
|
||||
pub name: Box<str>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
@ -37,12 +38,14 @@ pub struct Builds {
|
|||
}
|
||||
|
||||
impl Builds {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn get(build: &str) -> Builds {
|
||||
let url = format!("http://localhost:3000/api/builds/{}", build);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Builds>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/builds");
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
|
@ -50,12 +53,8 @@ impl Builds {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub async fn test_builds() {
|
||||
for a in Builds::get_all().await {
|
||||
println!("------------------");
|
||||
let builds = Builds::get(&a).await;
|
||||
println!("Roles for {} : {:?}\n", a, builds.roles.into_iter().map(|x| x.name).collect::<Vec<Box<str>>>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build() {
|
||||
let data = fs::read_to_string("test/build.json").expect("No build test file");
|
||||
serde_json::from_str::<Builds>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use std::fs;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use crate::data::builds::{Role};
|
||||
|
@ -24,13 +25,13 @@ pub struct CharacterMaterials {
|
|||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Character {
|
||||
pub name: Box<str>,
|
||||
pub id: Box<str>,
|
||||
pub name: Box<str>,
|
||||
pub rarity: u8,
|
||||
pub element: Element,
|
||||
pub weapon: WeaponType,
|
||||
pub ascension: Vec<Ascension>,
|
||||
pub stats: CharacterStats,
|
||||
pub ascension: Vec<Ascension>,
|
||||
pub element: Element,
|
||||
pub material: CharacterMaterials,
|
||||
pub builds: Vec<Role>
|
||||
}
|
||||
|
@ -48,6 +49,8 @@ impl Character {
|
|||
pub(crate) async fn get(character: &str) -> Character {
|
||||
let url = format!("http://localhost:3000/api/characters/{}", character);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
let a = reqwest::get(url.clone()).await.expect("Can't access Url");
|
||||
println!("{}",&a.text().await.expect(""));
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Character>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
|
@ -66,11 +69,8 @@ impl Character {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn test_character () {
|
||||
for a in Character::get_all().await {
|
||||
println!("{}", a);
|
||||
let char = Character::get(&a).await;
|
||||
println!("Name : {}", char.name);
|
||||
}
|
||||
#[test]
|
||||
fn test_character() {
|
||||
let data = fs::read_to_string("test/character.json").expect("No character test file");
|
||||
serde_json::from_str::<Character>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use std::fs;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -60,11 +61,8 @@ impl Domain {
|
|||
}
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn test_domains () {
|
||||
for a in Domain::get_all().await {
|
||||
println!("{}", a);
|
||||
let domain = Domain::get(&a).await;
|
||||
println!("Name : {}", domain.name);
|
||||
}
|
||||
#[test]
|
||||
fn test_items() {
|
||||
let data = fs::read_to_string("test/domain.json").expect("No Domain test file");
|
||||
serde_json::from_str::<Domain>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use std::fs;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -11,12 +12,14 @@ pub struct Element {
|
|||
}
|
||||
|
||||
impl Element{
|
||||
#[allow(dead_code)]
|
||||
async fn get(element: &str) -> Element {
|
||||
let url = format!("http://localhost:3000/api/elements/{}", element);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Element>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/elements");
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
|
@ -24,9 +27,8 @@ impl Element{
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn test_elem() {
|
||||
println!("All elems : {:?}", Element::get_all().await);
|
||||
|
||||
let geo = Element::get("geo").await;
|
||||
println!("Name : {}\nColor : #{:x}", geo.name, geo.color);
|
||||
#[test]
|
||||
fn test_element() {
|
||||
let data = fs::read_to_string("test/element.json").expect("No Element test file");
|
||||
serde_json::from_str::<Element>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use std::fs;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -9,8 +10,8 @@ pub struct Event {
|
|||
pub start: Box<str>,
|
||||
pub end: Box<str>,
|
||||
pub url: Option<Box<str>>,
|
||||
pub start_timestamp: u64,
|
||||
pub end_timestamp: u64,
|
||||
pub start_timestamp: Option<u64>,
|
||||
pub end_timestamp: Option<u64>,
|
||||
pub show_on_home: Option<bool>
|
||||
}
|
||||
|
||||
|
@ -46,17 +47,8 @@ impl Event {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn test_events() {
|
||||
let upcoming = Event::get_upcoming().await;
|
||||
println!("UPCOMING EVENTS\n--------");
|
||||
for event in upcoming {
|
||||
println!("Name : {}", event.name);
|
||||
}
|
||||
|
||||
let current = Event::get_current().await;
|
||||
println!("CURRENT EVENTS\n--------");
|
||||
for event in current {
|
||||
println!("Name : {}", event.name);
|
||||
}
|
||||
#[test]
|
||||
fn test_events() {
|
||||
let data = fs::read_to_string("test/events.json").expect("No events test file");
|
||||
serde_json::from_str::<Vec<Event>>(&data).expect("Didn't work");
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use std::fs;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
|
@ -12,12 +13,13 @@ pub struct Item {
|
|||
}
|
||||
|
||||
impl Item{
|
||||
#[allow(dead_code)]
|
||||
async fn get(item: &str) -> Item {
|
||||
let url = format!("http://localhost:3000/api/items/{}", item);
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
return reqwest::get(url).await.expect("Can't access Url").json::<Item>().await.expect("Wrong json format");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn get_all() -> Vec<Box<str>> {
|
||||
let url = format!("http://localhost:3000/api/items");
|
||||
let url = Url::parse(&*url).expect("Can't convert url");
|
||||
|
@ -32,12 +34,8 @@ impl Item{
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn test_items() {
|
||||
println!("List all items : {:?}", Item::get_all().await);
|
||||
|
||||
let item = Item::get("relic_from_guyun").await;
|
||||
println!("Name : {}\nDays : {:?}", item.name, item.day.unwrap_or(vec![]));
|
||||
|
||||
let item = Item::get("mora").await;
|
||||
println!("Name : {}\nDays : {:?}", item.name, item.day.unwrap_or(vec![]));
|
||||
#[test]
|
||||
fn test_item() {
|
||||
let data = fs::read_to_string("test/item.json").expect("No item test file");
|
||||
serde_json::from_str::<Item>(&data).expect("Didn't work");
|
||||
}
|
|
@ -7,14 +7,3 @@ pub mod characters;
|
|||
pub mod events;
|
||||
pub mod shared_structs;
|
||||
pub mod domains;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn test() {
|
||||
elements::test_elem().await;
|
||||
artifacts::test_artifacts().await;
|
||||
items::test_items().await;
|
||||
weapons::test_weapons().await;
|
||||
builds::test_builds().await;
|
||||
characters::test_character().await;
|
||||
events::test_events().await;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use std::fs;
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use serenity::builder::CreateEmbed;
|
||||
|
@ -113,9 +114,8 @@ impl Weapon {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn test_weapons() {
|
||||
for w in Weapon::get_all().await {
|
||||
println!("------------------");
|
||||
println!("{}", w);
|
||||
}
|
||||
#[test]
|
||||
fn test_weapon() {
|
||||
let data = fs::read_to_string("test/weapon.json").expect("No Weapon test file");
|
||||
serde_json::from_str::<Weapon>(&data).expect("Didn't work");
|
||||
}
|
|
@ -221,9 +221,9 @@ pub async fn home_embed(role: &Role, character: Character) -> CreateEmbed {
|
|||
_ => { embed.field("Best Artifacts", "TBD", false); }
|
||||
}
|
||||
|
||||
embed.field("Circlet", &role.main_stats.circlet, true);
|
||||
embed.field("Goblet", &role.main_stats.goblet, true);
|
||||
embed.field("Sands", &role.main_stats.sands, true);
|
||||
embed.field("Circlet", &role.main_stats.circlet[0], true);
|
||||
embed.field("Goblet", &role.main_stats.goblet[0], true);
|
||||
embed.field("Sands", &role.main_stats.sands[0], true);
|
||||
|
||||
embed.footer(|f| {
|
||||
f.text(format!("Data from : https://paimon.moe/characters/{}", character.id))
|
||||
|
@ -301,9 +301,9 @@ async fn artifact_embed(role: &Role, character: Character) -> CreateEmbed {
|
|||
format!("- {}", role.sub_stats.join("\n-"))
|
||||
}, false);
|
||||
|
||||
embed.field("Circlet", &role.main_stats.circlet, true);
|
||||
embed.field("Goblet", &role.main_stats.goblet, true);
|
||||
embed.field("Sands", &role.main_stats.sands, true);
|
||||
embed.field("Circlet", &role.main_stats.circlet[0], true);
|
||||
embed.field("Goblet", &role.main_stats.goblet[0], true);
|
||||
embed.field("Sands", &role.main_stats.sands[0], true);
|
||||
|
||||
embed.footer(|f| {
|
||||
f.text(format!("Data from : https://paimon.moe/characters/{}", character.id))
|
||||
|
|
|
@ -62,7 +62,7 @@ pub async fn create_status_interaction(ctx: Context, command: ApplicationCommand
|
|||
.color(Colour::from(0xff0000))
|
||||
}).flags(InteractionApplicationCommandCallbackDataFlags::EPHEMERAL)
|
||||
})
|
||||
}).await;
|
||||
}).await.expect("Interaction didn't work");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ async fn create_status_embed() -> Vec<CreateEmbed> {
|
|||
_ => {}
|
||||
};
|
||||
|
||||
embed.description(format!("Ends : <t:{}:R>", e.end_timestamp));
|
||||
embed.description(format!("Ends : <t:{}:R>", e.end_timestamp.expect("No End Timestamp")));
|
||||
embeds.push(embed);
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ async fn create_status_embed() -> Vec<CreateEmbed> {
|
|||
other_embed.color(Colour::new(rand::thread_rng().gen_range(0x000000..0xffffff)));
|
||||
|
||||
for e in others {
|
||||
other_embed.field(e.name, format!("Ends : <t:{}:R>", e.end_timestamp), false);
|
||||
other_embed.field(e.name, format!("Ends : <t:{}:R>", e.end_timestamp.expect("No End Timestamp")), false);
|
||||
}
|
||||
embeds.push(other_embed);
|
||||
|
||||
|
@ -168,7 +168,7 @@ async fn create_status_embed() -> Vec<CreateEmbed> {
|
|||
let mut upcoming_embed = CreateEmbed::default();
|
||||
question_marks = format!("{}?", question_marks);
|
||||
upcoming_embed.title(&e.name);
|
||||
upcoming_embed.description(format!("Starts : <t:{}:R>", e.start_timestamp));
|
||||
upcoming_embed.description(format!("Starts : <t:{}:R>", e.start_timestamp.expect("No Start Timestamp")));
|
||||
upcoming_embed.color(Colour::new(rand::thread_rng().gen_range(0x000000..0xffffff)));
|
||||
|
||||
match &e.image {
|
||||
|
|
Loading…
Reference in a new issue