1
+ import { Login } from "../src/actions/Login" ;
2
+ import { Logoff } from "../src/actions/Logoff" ;
3
+ import { Ping } from "../src/actions/Ping" ;
4
+ import { Hangup } from "../src/actions/Hangup" ;
5
+ import { Status } from "../src/actions/Status" ;
6
+ import { CoreShowChannels } from "../src/actions/CoreShowChannels" ;
7
+ import { CustomAction } from "../src/actions/CustomAction" ;
8
+
9
+ describe ( "AMI Actions" , ( ) => {
10
+ describe ( "Login" , ( ) => {
11
+ test ( "should create a Login action with username and password" , ( ) => {
12
+ const username = "admin" ;
13
+ const password = "secret" ;
14
+ const login = new Login ( username , password ) ;
15
+
16
+ expect ( login ) . toBeInstanceOf ( Login ) ;
17
+ const marshalled = login . marshall ( ) ;
18
+
19
+ expect ( marshalled ) . toContain ( "Action: Login" ) ;
20
+ expect ( marshalled ) . toContain ( "Username: admin" ) ;
21
+ expect ( marshalled ) . toContain ( "Secret: secret" ) ;
22
+ } ) ;
23
+ } ) ;
24
+
25
+ describe ( "Logoff" , ( ) => {
26
+ test ( "should create a Logoff action" , ( ) => {
27
+ const logoff = new Logoff ( ) ;
28
+
29
+ expect ( logoff ) . toBeInstanceOf ( Logoff ) ;
30
+ const marshalled = logoff . marshall ( ) ;
31
+
32
+ expect ( marshalled ) . toContain ( "Action: Logoff" ) ;
33
+ } ) ;
34
+ } ) ;
35
+
36
+ describe ( "Ping" , ( ) => {
37
+ test ( "should create a Ping action" , ( ) => {
38
+ const ping = new Ping ( ) ;
39
+
40
+ expect ( ping ) . toBeInstanceOf ( Ping ) ;
41
+ const marshalled = ping . marshall ( ) ;
42
+
43
+ expect ( marshalled ) . toContain ( "Action: Ping" ) ;
44
+ } ) ;
45
+ } ) ;
46
+
47
+ describe ( "Hangup" , ( ) => {
48
+ test ( "should create a Hangup action with channel name" , ( ) => {
49
+ const channel = "SIP/1234-00000123" ;
50
+ const hangup = new Hangup ( channel ) ;
51
+
52
+ expect ( hangup ) . toBeInstanceOf ( Hangup ) ;
53
+ const marshalled = hangup . marshall ( ) ;
54
+
55
+ expect ( marshalled ) . toContain ( "Action: Hangup" ) ;
56
+ expect ( marshalled ) . toContain ( `Channel: ${ channel } ` ) ;
57
+ } ) ;
58
+
59
+ test ( "should create a Hangup action with channel name and cause" , ( ) => {
60
+ const channel = "SIP/1234-00000123" ;
61
+ const cause = "16" ;
62
+ const hangup = new Hangup ( channel , cause ) ;
63
+
64
+ expect ( hangup ) . toBeInstanceOf ( Hangup ) ;
65
+ const marshalled = hangup . marshall ( ) ;
66
+
67
+ expect ( marshalled ) . toContain ( "Action: Hangup" ) ;
68
+ expect ( marshalled ) . toContain ( `Channel: ${ channel } ` ) ;
69
+ expect ( marshalled ) . toContain ( `Cause: ${ cause } ` ) ;
70
+ } ) ;
71
+ } ) ;
72
+
73
+ describe ( "Status" , ( ) => {
74
+ test ( "should create a Status action without channel" , ( ) => {
75
+ const status = new Status ( ) ;
76
+
77
+ expect ( status ) . toBeInstanceOf ( Status ) ;
78
+ const marshalled = status . marshall ( ) ;
79
+
80
+ expect ( marshalled ) . toContain ( "Action: Status" ) ;
81
+ expect ( marshalled ) . not . toContain ( "Channel:" ) ;
82
+ } ) ;
83
+
84
+ test ( "should create a Status action with channel name" , ( ) => {
85
+ const channel = "SIP/1234-00000123" ;
86
+ const status = new Status ( channel ) ;
87
+
88
+ expect ( status ) . toBeInstanceOf ( Status ) ;
89
+ const marshalled = status . marshall ( ) ;
90
+
91
+ expect ( marshalled ) . toContain ( "Action: Status" ) ;
92
+ expect ( marshalled ) . toContain ( `Channel: ${ channel } ` ) ;
93
+ } ) ;
94
+ } ) ;
95
+
96
+ describe ( "CoreShowChannels" , ( ) => {
97
+ test ( "should create a CoreShowChannels action" , ( ) => {
98
+ const coreShowChannels = new CoreShowChannels ( ) ;
99
+
100
+ expect ( coreShowChannels ) . toBeInstanceOf ( CoreShowChannels ) ;
101
+ const marshalled = coreShowChannels . marshall ( ) ;
102
+
103
+ expect ( marshalled ) . toContain ( "Action: CoreShowChannels" ) ;
104
+ } ) ;
105
+ } ) ;
106
+
107
+ describe ( "CustomAction" , ( ) => {
108
+ test ( "should create a custom action with specified name" , ( ) => {
109
+ const actionName = "CustomActionName" ;
110
+ const customAction = new CustomAction ( { name : actionName } ) ;
111
+
112
+ expect ( customAction ) . toBeInstanceOf ( CustomAction ) ;
113
+ const marshalled = customAction . marshall ( ) ;
114
+
115
+ expect ( marshalled ) . toContain ( `Action: ${ actionName } ` ) ;
116
+ } ) ;
117
+
118
+ test ( "should add parameters to custom action" , ( ) => {
119
+ const actionName = "CustomActionName" ;
120
+ const customAction = new CustomAction ( {
121
+ name : actionName ,
122
+ params : {
123
+ Param1 : "Value1" ,
124
+ Param2 : "Value2"
125
+ }
126
+ } ) ;
127
+
128
+ const marshalled = customAction . marshall ( ) ;
129
+
130
+ expect ( marshalled ) . toContain ( `Action: ${ actionName } ` ) ;
131
+ expect ( marshalled ) . toContain ( "Param1: Value1" ) ;
132
+ expect ( marshalled ) . toContain ( "Param2: Value2" ) ;
133
+ } ) ;
134
+ } ) ;
135
+ } ) ;
0 commit comments