Page MenuHomePhabricator

[Tunnelbroker] implement setting device token
ClosedPublic

Authored by kamil on Jun 20 2024, 2:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 8, 10:36 PM
Unknown Object (File)
Fri, Nov 8, 1:30 PM
Unknown Object (File)
Fri, Nov 8, 12:24 PM
Unknown Object (File)
Fri, Nov 8, 12:23 PM
Unknown Object (File)
Fri, Nov 8, 12:23 PM
Unknown Object (File)
Oct 6 2024, 8:05 PM
Unknown Object (File)
Sep 25 2024, 9:33 PM
Unknown Object (File)
Sep 25 2024, 9:33 PM
Subscribers

Details

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);
}

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kamil held this revision as a draft.
kamil published this revision for review.Jun 20 2024, 4:09 PM
services/tunnelbroker/src/database/mod.rs
192–196 ↗(On Diff #41577)

I guess we have some leftovers in existing code, but the preferred way is to use expression_attribute_names

207–212 ↗(On Diff #41577)
  • I find the whole code more readable when renamed items -> existing_tokens.
  • Optional proposal of logging. Not sure if you find it useful in any way. Just be careful not to expose token value over debug
services/tunnelbroker/src/database/mod.rs
209–210 ↗(On Diff #41577)

One more note - put_item() replaces item with given primary key device_id so we can optimize it not to remove it here unnecessarily.

This revision is now accepted and ready to land.Jun 24 2024, 11:59 PM