@@ -222,6 +222,34 @@ defmodule NervesHub.Devices.UpdateStatsTest do
222222 result = UpdateStats . stats_by_deployment ( deployment_group )
223223 assert result == % { }
224224 end
225+
226+ test "scopes by product id" , % {
227+ device: device ,
228+ device2: device2 ,
229+ deployment_group: deployment_group ,
230+ target_firmware: target_firmware ,
231+ source_firmware_metadata: source_firmware_metadata
232+ } do
233+ device = Devices . update_deployment_group ( device , deployment_group )
234+ :ok = UpdateStats . log_update ( device , source_firmware_metadata )
235+
236+ # create firmware from different product with same uuid
237+ user2 = Fixtures . user_fixture ( )
238+ org2 = Fixtures . org_fixture ( user2 , % { name: "foo" } )
239+ org_key2 = Fixtures . org_key_fixture ( org2 , user2 )
240+ product2 = Fixtures . product_fixture ( user2 , org2 )
241+
242+ firmware2 =
243+ Fixtures . firmware_fixture ( org_key2 , product2 , % { version: "2.0.0" } )
244+ |> Ecto.Changeset . change ( % { uuid: target_firmware . uuid } )
245+ |> Repo . update! ( )
246+
247+ { :ok , firmware2_metadata } = Firmwares . metadata_from_firmware ( firmware2 )
248+ :ok = UpdateStats . log_update ( device2 , firmware2_metadata )
249+
250+ stats = UpdateStats . stats_by_deployment ( deployment_group )
251+ assert stats [ target_firmware . uuid ] . total_updates == 1
252+ end
225253 end
226254
227255 describe "total_stats_by_product/1" do
0 commit comments