diff --git a/contracts/examples/push/expense_created.json b/contracts/examples/push/expense_created.json index b49fbf8..3db7d3d 100644 --- a/contracts/examples/push/expense_created.json +++ b/contracts/examples/push/expense_created.json @@ -1,6 +1,6 @@ { "message": { - "token": "dGhpcyBpcyBhbiBleGFtcGxlIGZjbSB0b2tlbg", + "fid": "dExampleFid0Kvitt12345", "android": { "priority": "high", "ttl": "86400s" diff --git a/contracts/examples/push/expense_deleted.json b/contracts/examples/push/expense_deleted.json index ca68795..aeb0b09 100644 --- a/contracts/examples/push/expense_deleted.json +++ b/contracts/examples/push/expense_deleted.json @@ -1,6 +1,6 @@ { "message": { - "token": "dGhpcyBpcyBhbiBleGFtcGxlIGZjbSB0b2tlbg", + "fid": "dExampleFid0Kvitt12345", "android": { "priority": "high", "ttl": "86400s" diff --git a/contracts/examples/push/expense_updated.json b/contracts/examples/push/expense_updated.json index abe04a0..58685d9 100644 --- a/contracts/examples/push/expense_updated.json +++ b/contracts/examples/push/expense_updated.json @@ -1,6 +1,6 @@ { "message": { - "token": "dGhpcyBpcyBhbiBleGFtcGxlIGZjbSB0b2tlbg", + "fid": "dExampleFid0Kvitt12345", "android": { "priority": "high", "ttl": "86400s" diff --git a/contracts/examples/push/recurring_expense_created.json b/contracts/examples/push/recurring_expense_created.json index b747989..8a0fd88 100644 --- a/contracts/examples/push/recurring_expense_created.json +++ b/contracts/examples/push/recurring_expense_created.json @@ -1,6 +1,6 @@ { "message": { - "token": "dGhpcyBpcyBhbiBleGFtcGxlIGZjbSB0b2tlbg", + "fid": "dExampleFid0Kvitt12345", "android": { "priority": "high", "ttl": "86400s" diff --git a/contracts/examples/push/settlement_created.json b/contracts/examples/push/settlement_created.json index 3e587aa..3a1a331 100644 --- a/contracts/examples/push/settlement_created.json +++ b/contracts/examples/push/settlement_created.json @@ -1,6 +1,6 @@ { "message": { - "token": "dGhpcyBpcyBhbiBleGFtcGxlIGZjbSB0b2tlbg", + "fid": "dExampleFid0Kvitt12345", "android": { "priority": "high", "ttl": "86400s" diff --git a/contracts/examples/push/settlement_deleted.json b/contracts/examples/push/settlement_deleted.json index b5dee36..2cd1b7d 100644 --- a/contracts/examples/push/settlement_deleted.json +++ b/contracts/examples/push/settlement_deleted.json @@ -1,6 +1,6 @@ { "message": { - "token": "dGhpcyBpcyBhbiBleGFtcGxlIGZjbSB0b2tlbg", + "fid": "dExampleFid0Kvitt12345", "android": { "priority": "high", "ttl": "86400s" diff --git a/contracts/examples/push/settlement_updated.json b/contracts/examples/push/settlement_updated.json index ec98ebb..41d3ff8 100644 --- a/contracts/examples/push/settlement_updated.json +++ b/contracts/examples/push/settlement_updated.json @@ -1,6 +1,6 @@ { "message": { - "token": "dGhpcyBpcyBhbiBleGFtcGxlIGZjbSB0b2tlbg", + "fid": "dExampleFid0Kvitt12345", "android": { "priority": "high", "ttl": "86400s" diff --git a/contracts/examples/push/sync_batch.json b/contracts/examples/push/sync_batch.json index 9a3918e..0f77003 100644 --- a/contracts/examples/push/sync_batch.json +++ b/contracts/examples/push/sync_batch.json @@ -1,6 +1,6 @@ { "message": { - "token": "dGhpcyBpcyBhbiBleGFtcGxlIGZjbSB0b2tlbg", + "fid": "dExampleFid0Kvitt12345", "android": { "priority": "high", "ttl": "86400s" diff --git a/server/crates/kvitt-server/src/push/fcm.rs b/server/crates/kvitt-server/src/push/fcm.rs index 631d202..d804002 100644 --- a/server/crates/kvitt-server/src/push/fcm.rs +++ b/server/crates/kvitt-server/src/push/fcm.rs @@ -113,10 +113,12 @@ pub fn entity_type_of(push_type: PushType) -> &'static str { } /// The HTTP v1 request body for one device (SPEC §14.6): data only, every value a string, ids only (AC-13.8). +/// The target is `fid`: the stored `fcm_token` is the Firebase Installation ID the phone registered (D-083), and +/// HTTP v1 deprecates `token` in favour of `fid` (D-096). pub fn message_body(fcm_token: &str, message: &PushMessage) -> Value { json!({ "message": { - "token": fcm_token, + "fid": fcm_token, "android": { "priority": "high", "ttl": MESSAGE_TTL }, "data": { "v": PAYLOAD_VERSION, diff --git a/server/crates/kvitt-server/tests/push_fcm/fcm.rs b/server/crates/kvitt-server/tests/push_fcm/fcm.rs index 00a5a60..b5803cd 100644 --- a/server/crates/kvitt-server/tests/push_fcm/fcm.rs +++ b/server/crates/kvitt-server/tests/push_fcm/fcm.rs @@ -117,7 +117,7 @@ fn payload_of_every_type_equals_the_contract_example() { actor_user_id: data["actor_user_id"].as_str().unwrap().parse().unwrap(), count: data["count"].as_str().unwrap().parse().unwrap(), }; - let body = message_body(expected["message"]["token"].as_str().unwrap(), &msg); + let body = message_body(expected["message"]["fid"].as_str().unwrap(), &msg); assert_eq!(body, expected, "{}", push_type.as_str()); // Data only, every value a string (SPEC §14.6), ids only (AC-13.8). assert!(body["message"].get("notification").is_none()); @@ -178,7 +178,7 @@ async fn oauth_jwt_and_send_request_follow_the_http_v1_flow() { sends[0].authorization.as_deref(), Some("Bearer ya29.stub-1") ); - let expected = json!({"message": {"token": "tok-member", "android": {"priority": "high", "ttl": "86400s"}, + let expected = json!({"message": {"fid": "tok-member", "android": {"priority": "high", "ttl": "86400s"}, "data": {"v": "1", "type": "expense_created", "entity_type": "expense", "entity_id": EXPENSE, "actor_user_id": ADMIN_ID, "count": "1"}}}); assert_eq!(sends[0].json(), expected); @@ -460,7 +460,8 @@ async fn sync_push_reaches_fcm_through_the_queue_and_the_sender_task() { let sends = s.stub.sends(); assert_eq!(sends.len(), 1); let body = sends[0].json(); - assert_eq!(body["message"]["token"], "tok-admin"); + assert_eq!(body["message"]["fid"], "tok-admin"); + assert!(body["message"].get("token").is_none()); assert_eq!(body["message"]["data"]["entity_id"], id); assert_eq!(body["message"]["data"]["actor_user_id"], MEMBER_ID); }