Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adding client_create_same_id_and_token test #234

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

geekbrother marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading