Fix some iso timestamps being strings, not DateTime<Utc> (#499)

* fix: some iso timestamps being strings

* fix: register uses dates, not datetimes
This commit is contained in:
kozabrada123 2024-06-03 07:32:11 +02:00 committed by GitHub
parent d4377c5280
commit eb087938ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 28 additions and 16 deletions

View File

@ -160,10 +160,10 @@ pub struct PermissionOverwrite {
pub struct ThreadMetadata {
pub archived: bool,
pub auto_archive_duration: i32,
pub archive_timestamp: String,
pub archive_timestamp: DateTime<Utc>,
pub locked: bool,
pub invitable: Option<bool>,
pub create_timestamp: Option<String>,
pub create_timestamp: Option<DateTime<Utc>>,
}
#[derive(Default, Debug, Deserialize, Serialize, Clone)]
@ -172,7 +172,7 @@ pub struct ThreadMetadata {
pub struct ThreadMember {
pub id: Option<Snowflake>,
pub user_id: Option<Snowflake>,
pub join_timestamp: Option<String>,
pub join_timestamp: Option<DateTime<Utc>>,
pub flags: Option<u64>,
pub member: Option<Shared<GuildMember>>,
}

View File

@ -67,7 +67,7 @@ pub struct Guild {
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub invites: Option<Vec<GuildInvite>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub joined_at: Option<String>,
pub joined_at: Option<DateTime<Utc>>,
pub large: Option<bool>,
pub max_members: Option<i32>,
pub max_presences: Option<i32>,

View File

@ -2,6 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::Shared;
@ -17,12 +18,12 @@ pub struct GuildMember {
pub nick: Option<String>,
pub avatar: Option<String>,
pub roles: Vec<Snowflake>,
pub joined_at: String,
pub premium_since: Option<String>,
pub joined_at: DateTime<Utc>,
pub premium_since: Option<DateTime<Utc>>,
pub deaf: bool,
pub mute: bool,
pub flags: Option<i32>,
pub pending: Option<bool>,
pub permissions: Option<String>,
pub communication_disabled_until: Option<String>,
pub communication_disabled_until: Option<DateTime<Utc>>,
}

View File

@ -2,6 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::{
@ -25,8 +26,8 @@ pub struct Message {
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub author: Option<PublicUser>,
pub content: Option<String>,
pub timestamp: String,
pub edited_timestamp: Option<String>,
pub timestamp: DateTime<Utc>,
pub edited_timestamp: Option<DateTime<Utc>>,
pub tts: Option<bool>,
pub mention_everyone: bool,
#[cfg_attr(feature = "sqlx", sqlx(skip))]

View File

@ -96,7 +96,7 @@ pub struct ChannelUnreadUpdate {
pub struct ChannelUnreadUpdateObject {
pub id: Snowflake,
pub last_message_id: Snowflake,
pub last_pin_timestamp: Option<String>,
pub last_pin_timestamp: Option<DateTime<Utc>>,
}
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField, WebSocketEvent)]

View File

@ -2,6 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
@ -13,7 +14,8 @@ pub struct RegisterSchema {
pub email: Option<String>,
pub fingerprint: Option<String>,
pub invite: Option<String>,
pub date_of_birth: Option<String>,
/// The user's date of birth, serialized as an ISO8601 date
pub date_of_birth: Option<NaiveDate>,
pub gift_code_sku_id: Option<String>,
pub captcha_key: Option<String>,
pub promotional_email_opt_in: Option<bool>,

View File

@ -2,12 +2,16 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::str::FromStr;
use chorus::types::{LoginSchema, RegisterSchema};
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);
use chrono::NaiveDate;
mod common;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@ -16,7 +20,7 @@ async fn test_registration() {
let mut bundle = common::setup().await;
let reg = RegisterSchema {
username: "Hiiii".into(),
date_of_birth: Some("2000-01-01".to_string()),
date_of_birth: Some(NaiveDate::from_str("2000-01-01").unwrap()),
consent: true,
..Default::default()
};
@ -32,7 +36,7 @@ async fn test_login() {
username: "Hiiii".into(),
email: Some("testuser1@integrationtesting.xyz".into()),
password: Some("Correct-Horse-Battery-Staple1".into()),
date_of_birth: Some("2000-01-01".to_string()),
date_of_birth: Some(NaiveDate::from_str("2000-01-01").unwrap()),
consent: true,
..Default::default()
};
@ -54,7 +58,7 @@ async fn test_wrong_login() {
username: "Hiiii".into(),
email: Some("testuser2@integrationtesting.xyz".into()),
password: Some("Correct-Horse-Battery-Staple1".into()),
date_of_birth: Some("2000-01-01".to_string()),
date_of_birth: Some(NaiveDate::from_str("2000-01-01").unwrap()),
consent: true,
..Default::default()
};

View File

@ -2,6 +2,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::str::FromStr;
use chorus::gateway::Gateway;
use chorus::types::IntoShared;
use chorus::{
@ -13,6 +15,8 @@ use chorus::{
UrlBundle,
};
use chrono::NaiveDate;
#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct TestBundle {
@ -30,7 +34,7 @@ impl TestBundle {
let register_schema = RegisterSchema {
username: username.to_string(),
consent: true,
date_of_birth: Some("2000-01-01".to_string()),
date_of_birth: Some(NaiveDate::from_str("2000-01-01").unwrap()),
..Default::default()
};
self.instance
@ -60,7 +64,7 @@ pub(crate) async fn setup() -> TestBundle {
let reg = RegisterSchema {
username: "integrationtestuser".into(),
consent: true,
date_of_birth: Some("2000-01-01".to_string()),
date_of_birth: Some(NaiveDate::from_str("2000-01-01").unwrap()),
..Default::default()
};
let guild_create_schema = GuildCreateSchema {