Skip to content

Commit

Permalink
Add name attribute to v2::watchlist::Watchlist
Browse files Browse the repository at this point in the history
  • Loading branch information
d-e-s-o committed Jun 19, 2024
1 parent cbf10e3 commit 956fd04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/api/v2/watchlist.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2021-2023 The apca Developers
// Copyright (C) 2021-2024 The apca Developers
// SPDX-License-Identifier: GPL-3.0-or-later

use std::ops::Deref;
Expand Down Expand Up @@ -42,6 +42,9 @@ pub struct Watchlist {
/// The watchlist's ID.
#[serde(rename = "id")]
pub id: Id,
/// The watchlist's user-defined name.
#[serde(rename = "name")]
pub name: String,
/// The account's ID.
#[serde(rename = "account_id")]
pub account_id: account::Id,
Expand Down Expand Up @@ -171,9 +174,10 @@ mod tests {
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);
let expected_symbols = vec!["AAPL".to_string(), "AMZN".to_string()];
let id = Uuid::new_v4().to_string();
let created = client
.issue::<Post>(&CreateReq {
name: Uuid::new_v4().to_string(),
name: id.clone(),
symbols: expected_symbols.clone(),
})
.await
Expand All @@ -191,6 +195,7 @@ mod tests {

// Also check that the reported account ID matches our account.
let account = client.issue::<account::Get>(&()).await.unwrap();
assert_eq!(watchlist.name, id);
assert_eq!(watchlist.account_id, account.id);
}

Expand Down
18 changes: 13 additions & 5 deletions src/api/v2/watchlists.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2021-2023 The apca Developers
// Copyright (C) 2021-2024 The apca Developers
// SPDX-License-Identifier: GPL-3.0-or-later

use chrono::DateTime;
Expand All @@ -12,11 +12,14 @@ use crate::Str;


/// A watchlist item.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
pub struct WatchlistItem {
/// The watchlist's ID.
#[serde(rename = "id")]
pub id: watchlist::Id,
/// The watchlist's user-defined name.
#[serde(rename = "name")]
pub name: String,
/// The account's ID.
#[serde(rename = "account_id")]
pub account_id: account::Id,
Expand Down Expand Up @@ -63,9 +66,10 @@ mod tests {
async fn list_watchlists() {
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);
let id = Uuid::new_v4().to_string();
let created = client
.issue::<watchlist::Post>(&CreateReq {
name: Uuid::new_v4().to_string(),
name: id.clone(),
symbols: vec!["AAPL".to_string()],
})
.await
Expand All @@ -78,7 +82,11 @@ mod tests {
.unwrap();

let watchlists = result.unwrap();
let mut ids = watchlists.iter().map(|w| w.id);
assert!(ids.any(|x| x == created.id))
assert!(
watchlists
.iter()
.any(|l| l.id == created.id && l.name == id),
"{watchlists:#?} : {id}"
)
}
}

0 comments on commit 956fd04

Please sign in to comment.