Skip to content

Commit

Permalink
test: adding client_create_same_id_and_token test (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbrother committed Oct 5, 2023
1 parent 3dde225 commit c7b14ff
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/functional/stores/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,70 @@ async fn client_upsert_id(ctx: &mut StoreContext) {
.unwrap();
}

#[test_context(StoreContext)]
#[tokio::test]
async fn client_create_same_id_and_token(ctx: &mut StoreContext) {
let client_id = format!("id-{}", gen_id());
let token = format!("token-{}", gen_id());

// Initial Client creation
ctx.clients
.create_client(TENANT_ID, &client_id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Fcm,
token: token.clone(),
})
.await
.unwrap();
let insert_result = ctx.clients.get_client(TENANT_ID, &client_id).await.unwrap();
assert_eq!(insert_result.token, token.clone());

// Insert notification for the client to test the clients->notifications
// constraint works properly
let notification_id = format!("id-{}", gen_id());
let notification_payload = format!("payload-{}", gen_id());

ctx.notifications
.create_or_update_notification(
&notification_id,
TENANT_ID,
&client_id,
&echo_server::handlers::push_message::MessagePayload {
topic: String::new(),
flags: 0,
blob: notification_payload,
},
)
.await
.unwrap();
let get_notification_result = ctx
.notifications
.get_notification(&notification_id, TENANT_ID)
.await
.unwrap();
assert_eq!(get_notification_result.client_id, client_id);

// Create a Client with the same id and same device token
// changing only the push_type to check if it was upserted
ctx.clients
.create_client(TENANT_ID, &client_id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Noop,
token: token.clone(),
})
.await
.unwrap();
let double_insert_result = ctx.clients.get_client(TENANT_ID, &client_id).await.unwrap();
assert_eq!(double_insert_result.token, token);
assert_eq!(double_insert_result.push_type, ProviderKind::Noop);

// Cleaning up records
ctx.clients
.delete_client(TENANT_ID, &client_id)
.await
.unwrap();
}

#[test_context(StoreContext)]
#[tokio::test]
async fn client_deletion(ctx: &mut StoreContext) {
Expand Down

0 comments on commit c7b14ff

Please sign in to comment.