@@ -248,7 +248,7 @@ defmodule NervesHub.ManagedDeploymentsTest do
248248 end
249249 end
250250
251- describe "device's matching deployments" do
251+ describe "devices matching deployments" do
252252 test "finds all matching deployments" , state do
253253 % { org: org , product: product , firmware: firmware } = state
254254
@@ -277,6 +277,58 @@ defmodule NervesHub.ManagedDeploymentsTest do
277277 ] = ManagedDeployments . matching_deployment_groups ( device )
278278 end
279279
280+ test "finds matching deployment with no tag condition" , state do
281+ % { org: org , product: product , firmware: firmware } = state
282+
283+ % { id: blank_deployment_group_id } =
284+ Fixtures . deployment_group_fixture ( org , firmware , % {
285+ name: "beta" ,
286+ conditions: % { "tags" => [ ] , "version" => "" }
287+ } )
288+
289+ Fixtures . deployment_group_fixture ( org , firmware , % {
290+ name: "rpi" ,
291+ conditions: % { "tags" => [ "rpi" ] , "version" => "" }
292+ } )
293+
294+ Fixtures . deployment_group_fixture ( org , firmware , % {
295+ name: "rpi0" ,
296+ conditions: % { "tags" => [ "rpi0" ] , "version" => "" }
297+ } )
298+
299+ % { tags: [ ] } = device = Fixtures . device_fixture ( org , product , firmware , % { tags: [ ] } )
300+
301+ assert [
302+ % { id: ^ blank_deployment_group_id }
303+ ] = ManagedDeployments . matching_deployment_groups ( device )
304+ end
305+
306+ test "finds matching deployment when device tags is null" , state do
307+ % { org: org , product: product , firmware: firmware } = state
308+
309+ % { id: blank_deployment_group_id } =
310+ Fixtures . deployment_group_fixture ( org , firmware , % {
311+ name: "beta" ,
312+ conditions: % { "tags" => [ ] , "version" => "" }
313+ } )
314+
315+ Fixtures . deployment_group_fixture ( org , firmware , % {
316+ name: "rpi" ,
317+ conditions: % { "tags" => [ "rpi" ] , "version" => "" }
318+ } )
319+
320+ Fixtures . deployment_group_fixture ( org , firmware , % {
321+ name: "rpi0" ,
322+ conditions: % { "tags" => [ "rpi0" ] , "version" => "" }
323+ } )
324+
325+ % { tags: nil } = device = Fixtures . device_fixture ( org , product , firmware , % { tags: nil } )
326+
327+ assert [
328+ % { id: ^ blank_deployment_group_id }
329+ ] = ManagedDeployments . matching_deployment_groups ( device )
330+ end
331+
280332 test "finds matching deployments including the platform" , state do
281333 % { org: org , org_key: org_key , product: product } = state
282334
0 commit comments