Skip to content

Commit 2f25ffd

Browse files
dadachiclaude
andauthored
Test google (FCM) device registration (#75)
The devices controller tests only covered apple. Add coverage for the google/FCM happy path (201) and confirm an unsupported platform value like "android" is rejected with 422, documenting that clients must send the provider name ("google"/"apple"), not the OS name. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7831722 commit 2f25ffd

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

test/controllers/api/v1/shopkeeper/devices_controller_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ class Api::V1::Shopkeeper::DevicesControllerTest < ActionDispatch::IntegrationTe
2525
assert_equal "com.nativeapptemplate.example", attrs["bundle_id"]
2626
end
2727

28+
test "create registers a google (FCM) device and returns 201" do
29+
assert_difference -> { ApplicationPushDevice.count }, 1 do
30+
post api_v1_shopkeeper_devices_url,
31+
params: {device: {token: "fcm-token-123", platform: "google", bundle_id: "com.nativeapptemplate.nativeapptemplate"}},
32+
headers: @shopkeeper.create_new_auth_token
33+
end
34+
assert_response :created
35+
attrs = response.parsed_body["data"]["attributes"]
36+
assert_equal "fcm-token-123", attrs["token"]
37+
assert_equal "google", attrs["platform"]
38+
assert_equal "com.nativeapptemplate.nativeapptemplate", attrs["bundle_id"]
39+
end
40+
41+
test "create returns 422 for an unsupported platform" do
42+
assert_no_difference -> { ApplicationPushDevice.count } do
43+
post api_v1_shopkeeper_devices_url,
44+
params: {device: {token: "abc123", platform: "android"}},
45+
headers: @shopkeeper.create_new_auth_token
46+
end
47+
assert_response :unprocessable_entity
48+
assert_equal 422, response.parsed_body["code"]
49+
end
50+
2851
test "create with same (platform, token) does not duplicate and returns 200" do
2952
ApplicationPushDevice.create!(owner: @shopkeeper, token: "abc123", platform: "apple", last_active_at: 1.day.ago)
3053

0 commit comments

Comments
 (0)