-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added update user last_activity_at (#1013)
Co-authored-by: Ellen <lionqueen94@gmail.com>
- Loading branch information
1 parent
0477efe
commit a3d10d7
Showing
6 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
backend/.sqlx/query-d497354da4f500c7e45a0a26469d552e624b12b61ed0f31fb03f84460413f24d.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#![cfg(test)] | ||
|
||
use abacus::authentication::UserListResponse; | ||
use hyper::{header::CONTENT_TYPE, StatusCode}; | ||
use reqwest::Body; | ||
use serde_json::json; | ||
use sqlx::SqlitePool; | ||
use test_log::test; | ||
use utils::serve_api; | ||
|
||
pub mod shared; | ||
pub mod utils; | ||
#[test(sqlx::test(fixtures(path = "../fixtures", scripts("election_2", "users"))))] | ||
async fn test_user_last_activity_at_updating(pool: SqlitePool) { | ||
// Assert the user has no last activity timestamp yet | ||
let addr = serve_api(pool).await; | ||
let url = format!("http://{addr}/api/user"); | ||
let response = reqwest::Client::new().get(&url).send().await.unwrap(); | ||
assert_eq!(response.status(), StatusCode::OK); | ||
let body: UserListResponse = response.json().await.unwrap(); | ||
let user = body.users.first().unwrap(); | ||
assert!(user.last_activity_at().is_none()); | ||
|
||
// Login, so we can call the whoami endpoint | ||
let url = format!("http://{addr}/api/user/login"); | ||
let response = reqwest::Client::new() | ||
.post(&url) | ||
.header(CONTENT_TYPE, "application/json") | ||
.body(Body::from( | ||
json!({ | ||
"username": "user", | ||
"password": "password", | ||
}) | ||
.to_string(), | ||
)) | ||
.send() | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
|
||
let cookie = shared::login(&addr).await.unwrap(); | ||
|
||
// Call an endpoint using the `FromRequestParts` for `User` | ||
let url = format!("http://{addr}/api/user/whoami"); | ||
let response = reqwest::Client::new() | ||
.get(&url) | ||
.header("cookie", &cookie) | ||
.send() | ||
.await | ||
.unwrap(); | ||
assert_eq!(response.status(), StatusCode::OK); | ||
|
||
// Test that a timestamp is present | ||
let url = format!("http://{addr}/api/user"); | ||
let response = reqwest::Client::new().get(&url).send().await.unwrap(); | ||
assert_eq!(response.status(), StatusCode::OK); | ||
let body: UserListResponse = response.json().await.unwrap(); | ||
let user = body.users.first().unwrap(); | ||
assert!(user.last_activity_at().is_some()); | ||
} |