Skip to content

Commit

Permalink
Fix some iso timestamps being strings, not DateTime<Utc> (#499)
Browse files Browse the repository at this point in the history
* fix: some iso timestamps being strings

* fix: register uses dates, not datetimes
  • Loading branch information
kozabrada123 authored Jun 3, 2024
1 parent d4377c5 commit eb08793
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/types/entities/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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>>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/entities/guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
7 changes: 4 additions & 3 deletions src/types/entities/guild_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>>,
}
5 changes: 3 additions & 2 deletions src/types/entities/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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))]
Expand Down
2 changes: 1 addition & 1 deletion src/types/events/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 3 additions & 1 deletion src/types/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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>,
Expand Down
10 changes: 7 additions & 3 deletions tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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()
};
Expand All @@ -32,7 +36,7 @@ async fn test_login() {
username: "Hiiii".into(),
email: Some("[email protected]".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()
};
Expand All @@ -54,7 +58,7 @@ async fn test_wrong_login() {
username: "Hiiii".into(),
email: Some("[email protected]".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()
};
Expand Down
8 changes: 6 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -13,6 +15,8 @@ use chorus::{
UrlBundle,
};

use chrono::NaiveDate;

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct TestBundle {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit eb08793

Please sign in to comment.