@@ -2,6 +2,7 @@ package didww
22
33import (
44 "context"
5+ "io"
56 "net/http"
67 "testing"
78)
@@ -122,3 +123,111 @@ func TestDIDsUpdateRequiresID(t *testing.T) {
122123 t .Fatal ("expected error when updating without ID" )
123124 }
124125}
126+
127+ func TestDIDsUpdateAssignTrunk (t * testing.T ) {
128+ var capturedBody []byte
129+ server := newTestServerWithInspector (t , map [string ]testRoute {
130+ "PATCH /v3/dids/9df99644-f1a5-4a3c-99a4-559d758eb96b" : {status : http .StatusOK , fixture : "dids/show_with_trunk.json" },
131+ }, func (r * http.Request ) {
132+ capturedBody , _ = io .ReadAll (r .Body )
133+ })
134+
135+ did , err := server .client .DIDs ().Update (context .Background (), & DID {
136+ ID : "9df99644-f1a5-4a3c-99a4-559d758eb96b" ,
137+ VoiceInTrunkID : "41b94706-325e-4704-a433-d65105758836" ,
138+ })
139+ if err != nil {
140+ t .Fatalf ("unexpected error: %v" , err )
141+ }
142+
143+ assertRequestJSON (t , capturedBody , "dids/update_assign_trunk_request.json" )
144+
145+ if did .VoiceInTrunk == nil {
146+ t .Fatal ("expected non-nil VoiceInTrunk" )
147+ }
148+ if did .VoiceInTrunk .ID != "41b94706-325e-4704-a433-d65105758836" {
149+ t .Errorf ("expected VoiceInTrunk ID '41b94706-325e-4704-a433-d65105758836', got %q" , did .VoiceInTrunk .ID )
150+ }
151+ if did .VoiceInTrunk .Name != "hello, test pstn trunk" {
152+ t .Errorf ("expected VoiceInTrunk Name 'hello, test pstn trunk', got %q" , did .VoiceInTrunk .Name )
153+ }
154+ }
155+
156+ func TestDIDsUpdateAssignTrunkGroup (t * testing.T ) {
157+ var capturedBody []byte
158+ server := newTestServerWithInspector (t , map [string ]testRoute {
159+ "PATCH /v3/dids/9df99644-f1a5-4a3c-99a4-559d758eb96b" : {status : http .StatusOK , fixture : "dids/show_with_trunk_group.json" },
160+ }, func (r * http.Request ) {
161+ capturedBody , _ = io .ReadAll (r .Body )
162+ })
163+
164+ did , err := server .client .DIDs ().Update (context .Background (), & DID {
165+ ID : "9df99644-f1a5-4a3c-99a4-559d758eb96b" ,
166+ VoiceInTrunkGroupID : "b2319703-ce6c-480d-bb53-614e7abcfc96" ,
167+ })
168+ if err != nil {
169+ t .Fatalf ("unexpected error: %v" , err )
170+ }
171+
172+ assertRequestJSON (t , capturedBody , "dids/update_assign_trunk_group_request.json" )
173+
174+ if did .VoiceInTrunkGroup == nil {
175+ t .Fatal ("expected non-nil VoiceInTrunkGroup" )
176+ }
177+ if did .VoiceInTrunkGroup .ID != "b2319703-ce6c-480d-bb53-614e7abcfc96" {
178+ t .Errorf ("expected VoiceInTrunkGroup ID 'b2319703-ce6c-480d-bb53-614e7abcfc96', got %q" , did .VoiceInTrunkGroup .ID )
179+ }
180+ if did .VoiceInTrunkGroup .Name != "trunk group sample with 2 trunks" {
181+ t .Errorf ("expected VoiceInTrunkGroup Name 'trunk group sample with 2 trunks', got %q" , did .VoiceInTrunkGroup .Name )
182+ }
183+ }
184+
185+ func TestDIDsFindWithTrunkResolved (t * testing.T ) {
186+ _ , client := newTestServer (t , map [string ]testRoute {
187+ "GET /v3/dids/9df99644-f1a5-4a3c-99a4-559d758eb96b" : {status : http .StatusOK , fixture : "dids/show_with_trunk.json" },
188+ })
189+
190+ params := NewQueryParams ().Include ("voice_in_trunk" )
191+ did , err := client .DIDs ().Find (context .Background (), "9df99644-f1a5-4a3c-99a4-559d758eb96b" , params )
192+ if err != nil {
193+ t .Fatalf ("unexpected error: %v" , err )
194+ }
195+
196+ if did .VoiceInTrunk == nil {
197+ t .Fatal ("expected non-nil VoiceInTrunk" )
198+ }
199+ if did .VoiceInTrunk .ID != "41b94706-325e-4704-a433-d65105758836" {
200+ t .Errorf ("expected VoiceInTrunk ID '41b94706-325e-4704-a433-d65105758836', got %q" , did .VoiceInTrunk .ID )
201+ }
202+ if did .VoiceInTrunk .Name != "hello, test pstn trunk" {
203+ t .Errorf ("expected VoiceInTrunk Name 'hello, test pstn trunk', got %q" , did .VoiceInTrunk .Name )
204+ }
205+ if did .VoiceInTrunkGroup != nil {
206+ t .Error ("expected nil VoiceInTrunkGroup (mutual exclusivity)" )
207+ }
208+ }
209+
210+ func TestDIDsFindWithTrunkGroupResolved (t * testing.T ) {
211+ _ , client := newTestServer (t , map [string ]testRoute {
212+ "GET /v3/dids/9df99644-f1a5-4a3c-99a4-559d758eb96b" : {status : http .StatusOK , fixture : "dids/show_with_trunk_group.json" },
213+ })
214+
215+ params := NewQueryParams ().Include ("voice_in_trunk_group" )
216+ did , err := client .DIDs ().Find (context .Background (), "9df99644-f1a5-4a3c-99a4-559d758eb96b" , params )
217+ if err != nil {
218+ t .Fatalf ("unexpected error: %v" , err )
219+ }
220+
221+ if did .VoiceInTrunkGroup == nil {
222+ t .Fatal ("expected non-nil VoiceInTrunkGroup" )
223+ }
224+ if did .VoiceInTrunkGroup .ID != "b2319703-ce6c-480d-bb53-614e7abcfc96" {
225+ t .Errorf ("expected VoiceInTrunkGroup ID 'b2319703-ce6c-480d-bb53-614e7abcfc96', got %q" , did .VoiceInTrunkGroup .ID )
226+ }
227+ if did .VoiceInTrunkGroup .Name != "trunk group sample with 2 trunks" {
228+ t .Errorf ("expected VoiceInTrunkGroup Name 'trunk group sample with 2 trunks', got %q" , did .VoiceInTrunkGroup .Name )
229+ }
230+ if did .VoiceInTrunk != nil {
231+ t .Error ("expected nil VoiceInTrunk (mutual exclusivity)" )
232+ }
233+ }
0 commit comments