ZIm/crates/collab/src/db/tests/contributor_tests.rs
Marshall Bowers 98516b5527
collab: Restrict usage of the LLM service to accounts older than 30 days (#16133)
This PR restricts usage of the LLM service to accounts older than 30
days.

We now store the GitHub user's `created_at` timestamp to check the
GitHub account age. If this is not set—which it won't be for existing
users—then we use the `created_at` timestamp in the Zed database.

Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
2024-08-12 17:27:21 -04:00

44 lines
1.1 KiB
Rust

use chrono::Utc;
use super::Database;
use crate::{db::NewUserParams, test_both_dbs};
use std::sync::Arc;
test_both_dbs!(
test_contributors,
test_contributors_postgres,
test_contributors_sqlite
);
async fn test_contributors(db: &Arc<Database>) {
db.create_user(
"user1@example.com",
false,
NewUserParams {
github_login: "user1".to_string(),
github_user_id: 1,
},
)
.await
.unwrap();
assert_eq!(db.get_contributors().await.unwrap(), Vec::<String>::new());
let user1_created_at = Utc::now();
db.add_contributor("user1", Some(1), None, Some(user1_created_at), None)
.await
.unwrap();
assert_eq!(
db.get_contributors().await.unwrap(),
vec!["user1".to_string()]
);
let user2_created_at = Utc::now();
db.add_contributor("user2", Some(2), None, Some(user2_created_at), None)
.await
.unwrap();
assert_eq!(
db.get_contributors().await.unwrap(),
vec!["user1".to_string(), "user2".to_string()]
);
}