@@ -6,6 +6,7 @@ defmodule Diffo.Provider.Extension.AssignerTest do
66 @ moduledoc false
77 use ExUnit.Case , async: true
88 @ moduletag :domain_extended
9+ alias Diffo.Provider.Assigner
910 alias Diffo.Provider.Specification
1011 alias Diffo.Provider.Characteristic
1112 alias Diffo.Provider.Assignment
@@ -19,6 +20,52 @@ defmodule Diffo.Provider.Extension.AssignerTest do
1920 on_exit ( & AshNeo4j.Sandbox . rollback / 0 )
2021 end
2122
23+ # Issue #168 — broadened lifecycle policy. Service-side now covers the full
24+ # committed lifecycle (excludes :initial, :cancelled, :terminated); resource
25+ # side now allows :installing in addition to :operating.
26+ describe "assignable_state?/1 (#168)" do
27+ test "resource: :operating is permitted" do
28+ assert :ok = Assigner . assignable_state? ( % { type: :resource , resource_state: :operating } )
29+ end
30+
31+ test "resource: :installing is permitted" do
32+ assert :ok = Assigner . assignable_state? ( % { type: :resource , resource_state: :installing } )
33+ end
34+
35+ test "resource: :planning is rejected" do
36+ assert { :error , msg } =
37+ Assigner . assignable_state? ( % { type: :resource , resource_state: :planning } )
38+
39+ assert msg =~ ":planning"
40+ end
41+
42+ test "resource: :retiring is rejected" do
43+ assert { :error , _ } =
44+ Assigner . assignable_state? ( % { type: :resource , resource_state: :retiring } )
45+ end
46+
47+ test "service: committed lifecycle states are permitted" do
48+ for state <- [ :feasibilityChecked , :reserved , :inactive , :active , :suspended ] do
49+ assert :ok = Assigner . assignable_state? ( % { type: :service , service_state: state } ) ,
50+ "expected service_state #{ inspect ( state ) } to be assignable"
51+ end
52+ end
53+
54+ test "service: :initial is rejected" do
55+ assert { :error , msg } =
56+ Assigner . assignable_state? ( % { type: :service , service_state: :initial } )
57+
58+ assert msg =~ ":initial"
59+ end
60+
61+ test "service: terminal states are rejected" do
62+ for state <- [ :cancelled , :terminated ] do
63+ assert { :error , _ } = Assigner . assignable_state? ( % { type: :service , service_state: state } ) ,
64+ "expected service_state #{ inspect ( state ) } to be rejected"
65+ end
66+ end
67+ end
68+
2269 describe "build card" do
2370 @ tag :card
2471 test "create a card" do
@@ -213,5 +260,45 @@ defmodule Diffo.Provider.Extension.AssignerTest do
213260 assert encoding ==
214261 ~s( {\" id\" :\" #{ card . id } ",\" href\" :\" resourceInventoryManagement/v4/resource/#{ card . id } ",\" category\" :\" Network Resource\" ,\" description\" :\" A Card Resource Instance\" ,\" resourceSpecification\" :{\" id\" :\" cd29956f-6c68-44cc-bf54-705eb8d2f754\" ,\" href\" :\" resourceCatalogManagement/v4/resourceSpecification/cd29956f-6c68-44cc-bf54-705eb8d2f754\" ,\" name\" :\" card\" ,\" version\" :\" v1.0.0\" },\" lifecycleState\" :\" operating\" })
215262 end
263+
264+ test "auto assign port to resource in :installing state (#168)" do
265+ { :ok , assignee } = Parties . build_shelf_with_installer ( )
266+
267+ { :ok , card } = Servo . build_card ( % { } )
268+
269+ updates = [
270+ card: [ family: :ISAM , model: "EBLT48" , technology: :adsl2Plus ] ,
271+ ports: [ first: 1 , last: 48 , assignable_type: "ADSL2+" ]
272+ ]
273+
274+ { :ok , card } = Servo . define_card ( card , % { characteristic_value_updates: updates } )
275+ { :ok , card } = Servo . lifecycle_card ( card , % { resource_state: :installing } )
276+
277+ { :ok , card } =
278+ Servo . assign_port ( card , % {
279+ assignment: % Assignment { assignee_id: assignee . id , operation: :auto_assign }
280+ } )
281+
282+ assert length ( card . assignments ) == 1
283+ end
284+
285+ test "assign rejected while resource is in :planning state (#168)" do
286+ { :ok , assignee } = Parties . build_shelf_with_installer ( )
287+
288+ { :ok , card } = Servo . build_card ( % { } )
289+
290+ updates = [
291+ card: [ family: :ISAM , model: "EBLT48" , technology: :adsl2Plus ] ,
292+ ports: [ first: 1 , last: 48 , assignable_type: "ADSL2+" ]
293+ ]
294+
295+ { :ok , card } = Servo . define_card ( card , % { characteristic_value_updates: updates } )
296+ { :ok , card } = Servo . lifecycle_card ( card , % { resource_state: :planning } )
297+
298+ assert { :error , _ } =
299+ Servo . assign_port ( card , % {
300+ assignment: % Assignment { assignee_id: assignee . id , operation: :auto_assign }
301+ } )
302+ end
216303 end
217304end
0 commit comments