HomePhabricator
Diffusion Comm f7ba3bbe5382

[Tunnelbroker] implement setting device token

Description

[Tunnelbroker] implement setting device token

Summary:
ENG-8346

Depends on D12519

Test Plan:
Execute following tests:

#[tokio::test]
async fn test_setting_device_token() {
  let aws_config = config::load_aws_config().await;
  let db_client = database::DatabaseClient::new(&aws_config);

  let device_token: &str = "token";
  let device_id: &str = "id1";

  db_client
    .set_device_token(device_id, device_token)
    .await
    .unwrap();
  let db_device_token = db_client
    .get_device_token(device_id)
    .await
    .unwrap()
    .unwrap();
  assert_eq!(db_device_token, device_token);

  let updated_device_token: &str = "updated_token";
  let device_id: &str = "id1";

  db_client
    .set_device_token(device_id, updated_device_token)
    .await
    .unwrap();
  let db_device_token = db_client
    .get_device_token(device_id)
    .await
    .unwrap()
    .unwrap();
  assert_eq!(db_device_token, updated_device_token);
}

#[tokio::test]
async fn test_removing_device_token() {
  let aws_config = config::load_aws_config().await;
  let db_client = database::DatabaseClient::new(&aws_config);

  let device_token: &str = "token";
  let device_id: &str = "id1";

  db_client
    .set_device_token(device_id, device_token)
    .await
    .unwrap();
  let db_device_token = db_client
    .get_device_token(device_id)
    .await
    .unwrap()
    .unwrap();
  assert_eq!(db_device_token, device_token);

  db_client.remove_device_token(device_id).await.expect("");

  let db_device_token = db_client.get_device_token(device_id).await.unwrap();
  assert_eq!(db_device_token, None);
}

#[tokio::test]
async fn test_device_token_being_unique() {
  let aws_config = config::load_aws_config().await;
  let db_client = database::DatabaseClient::new(&aws_config);

  let device_token: &str = "token";
  let device_id_1: &str = "id1";
  let device_id_2: &str = "id2";

  db_client
    .set_device_token(device_id_1, device_token)
    .await
    .unwrap();
  db_client
    .set_device_token(device_id_2, device_token)
    .await
    .unwrap();

  let db_device_token_1 =
    db_client.get_device_token(device_id_1).await.unwrap();
  assert_eq!(db_device_token_1, None);

  let db_device_token_2 = db_client
    .get_device_token(device_id_2)
    .await
    .unwrap()
    .unwrap();
  assert_eq!(db_device_token_2, device_token);
}

Reviewers: bartek, marcin

Reviewed By: bartek

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D12520

Details

Provenance
kamilAuthored on Jun 20 2024, 2:15 PM
Reviewer
bartek
Differential Revision
D12520: [Tunnelbroker] implement setting device token
Parents
rCOMM3fe7a0d11cf5: [Tunnelbroker] implement getting device token
Branches
Unknown
Tags
Unknown