@@ -248,6 +248,64 @@ defmodule Astarte.Client.Housekeeping.RealmsTest do
248248 assert :ok = Realms . create ( client , @ realm_name , @ realm_public_key , replication_factor: 1 )
249249 end
250250
251+ test "specifies integer datastream maximum storage retention" , % { client: client } do
252+ opts = [ datastream_maximum_storage_retention: 1 ]
253+
254+ Tesla.Mock . mock ( fn % { body: body } ->
255+ assert % {
256+ "data" => % {
257+ "datastream_maximum_storage_retention" => 1
258+ }
259+ } = Jason . decode! ( body )
260+
261+ Tesla.Mock . json ( realm_response ( ) , status: 201 )
262+ end )
263+
264+ assert :ok =
265+ Realms . create (
266+ client ,
267+ @ realm_name ,
268+ @ realm_public_key ,
269+ [ replication_factor: 1 ] ++ opts
270+ )
271+ end
272+
273+ test "specifies nil datastream maximum storage retention" , % { client: client } do
274+ opts = [ datastream_maximum_storage_retention: nil ]
275+
276+ Tesla.Mock . mock ( fn % { body: body } ->
277+ assert % {
278+ "data" => % {
279+ "datastream_maximum_storage_retention" => nil
280+ }
281+ } = Jason . decode! ( body )
282+
283+ Tesla.Mock . json ( realm_response ( ) , status: 201 )
284+ end )
285+
286+ assert :ok =
287+ Realms . create (
288+ client ,
289+ @ realm_name ,
290+ @ realm_public_key ,
291+ [ replication_factor: 1 ] ++ opts
292+ )
293+ end
294+
295+ test "specifies nil without a defined datastream maximum storage retention" , % { client: client } do
296+ Tesla.Mock . mock ( fn % { body: body } ->
297+ assert % {
298+ "data" => % {
299+ "datastream_maximum_storage_retention" => nil
300+ }
301+ } = Jason . decode! ( body )
302+
303+ Tesla.Mock . json ( realm_response ( ) , status: 201 )
304+ end )
305+
306+ assert :ok = Realms . create ( client , @ realm_name , @ realm_public_key , replication_factor: 1 )
307+ end
308+
251309 test "specifies replication with simple strategy" , % { client: client } do
252310 opts = [ replication_factor: 1 ]
253311
@@ -380,6 +438,55 @@ defmodule Astarte.Client.Housekeeping.RealmsTest do
380438 assert :ok = Realms . update ( client , @ realm_name , [ ] )
381439 end
382440
441+ test "specifies integer datastream maximum storage retention" , % { client: client } do
442+ datastream_maximum_storage_retention = 1
443+
444+ Tesla.Mock . mock ( fn % { body: body } ->
445+ assert % {
446+ "data" => % {
447+ "datastream_maximum_storage_retention" => ^ datastream_maximum_storage_retention
448+ }
449+ } = Jason . decode! ( body )
450+
451+ Tesla.Mock . json ( realm_response ( ) , status: 200 )
452+ end )
453+
454+ assert :ok =
455+ Realms . update ( client , @ realm_name ,
456+ datastream_maximum_storage_retention: datastream_maximum_storage_retention
457+ )
458+ end
459+
460+ test "specifies nil datastream maximum storage retention" , % { client: client } do
461+ datastream_maximum_storage_retention = nil
462+
463+ Tesla.Mock . mock ( fn % { body: body } ->
464+ assert % {
465+ "data" => % {
466+ "datastream_maximum_storage_retention" => ^ datastream_maximum_storage_retention
467+ }
468+ } = Jason . decode! ( body )
469+
470+ Tesla.Mock . json ( realm_response ( ) , status: 200 )
471+ end )
472+
473+ assert :ok =
474+ Realms . update ( client , @ realm_name ,
475+ datastream_maximum_storage_retention: datastream_maximum_storage_retention
476+ )
477+ end
478+
479+ test "does not specify datastream maximum storage retention if undefined" , % { client: client } do
480+ Tesla.Mock . mock ( fn % { body: body } ->
481+ assert % { "data" => data } = Jason . decode! ( body )
482+ refute Map . has_key? ( data , "datastream_maximum_storage_retention" )
483+
484+ Tesla.Mock . json ( realm_response ( ) , status: 200 )
485+ end )
486+
487+ assert :ok = Realms . update ( client , @ realm_name , [ ] )
488+ end
489+
383490 test "retuns APIError on error" , % { client: client } do
384491 error_data = % { "errors" => % { "detail" => "Forbidden" } }
385492 error_status = 403
@@ -500,7 +607,7 @@ defmodule Astarte.Client.Housekeeping.RealmsTest do
500607 % {
501608 "data" =>
502609 % {
503- "datastream_maximum_storage_retention" => nil ,
610+ "datastream_maximum_storage_retention" => opts [ :datastream_maximum_storage_retention ] ,
504611 "device_registration_limit" => opts [ :device_registration_limit ] ,
505612 "jwt_public_key_pem" => opts [ :jwt_public_key_pem ] || @ realm_public_key ,
506613 "realm_name" => opts [ :realm_name ] || @ realm_name
0 commit comments