1515package api
1616
1717import (
18- "context"
1918 "testing"
2019
2120 "github.com/slackapi/slack-cli/internal/shared/types"
21+ "github.com/slackapi/slack-cli/internal/slackcontext"
2222 "github.com/slackapi/slack-cli/internal/slackerror"
2323 "github.com/stretchr/testify/require"
2424)
@@ -28,39 +28,42 @@ var fakeResult = `{"ok":true,
2828}`
2929
3030func Test_ApiClient_ActivityErrorsIfAppIdIsEmpty (t * testing.T ) {
31+ ctx := slackcontext .MockContext (t .Context ())
3132 c , teardown := NewFakeClient (t , FakeClientParams {
3233 ExpectedMethod : appActivityMethod ,
3334 })
3435 defer teardown ()
35- _ , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
36+ _ , err := c .Activity (ctx , "token" , types.ActivityRequest {
3637 AppId : "" ,
3738 })
3839 require .Error (t , err )
3940 require .Contains (t , err .Error (), "app is not deployed" )
4041}
4142
4243func Test_ApiClient_ActivityBasicSuccessfulGET (t * testing.T ) {
44+ ctx := slackcontext .MockContext (t .Context ())
4345 c , teardown := NewFakeClient (t , FakeClientParams {
4446 ExpectedMethod : appActivityMethod ,
4547 ExpectedQuerystring : "app_id=A123" ,
4648 Response : fakeResult ,
4749 })
4850 defer teardown ()
49- result , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
51+ result , err := c .Activity (ctx , "token" , types.ActivityRequest {
5052 AppId : "A123" ,
5153 })
5254 require .NoError (t , err )
5355 require .Equal (t , result .Activities [0 ].TraceId , "12345" )
5456}
5557
5658func Test_ApiClient_ActivityEventType (t * testing.T ) {
59+ ctx := slackcontext .MockContext (t .Context ())
5760 c , teardown := NewFakeClient (t , FakeClientParams {
5861 ExpectedMethod : appActivityMethod ,
5962 ExpectedQuerystring : "app_id=A123&limit=0&log_event_type=silly" ,
6063 Response : fakeResult ,
6164 })
6265 defer teardown ()
63- result , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
66+ result , err := c .Activity (ctx , "token" , types.ActivityRequest {
6467 AppId : "A123" ,
6568 EventType : "silly" ,
6669 })
@@ -69,13 +72,14 @@ func Test_ApiClient_ActivityEventType(t *testing.T) {
6972}
7073
7174func Test_ApiClient_ActivityLogLevel (t * testing.T ) {
75+ ctx := slackcontext .MockContext (t .Context ())
7276 c , teardown := NewFakeClient (t , FakeClientParams {
7377 ExpectedMethod : appActivityMethod ,
7478 ExpectedQuerystring : "app_id=A123&limit=0&min_log_level=silly" ,
7579 Response : fakeResult ,
7680 })
7781 defer teardown ()
78- result , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
82+ result , err := c .Activity (ctx , "token" , types.ActivityRequest {
7983 AppId : "A123" ,
8084 MinimumLogLevel : "silly" ,
8185 })
@@ -84,13 +88,14 @@ func Test_ApiClient_ActivityLogLevel(t *testing.T) {
8488}
8589
8690func Test_ApiClient_ActivityMinDateCreated (t * testing.T ) {
91+ ctx := slackcontext .MockContext (t .Context ())
8792 c , teardown := NewFakeClient (t , FakeClientParams {
8893 ExpectedMethod : appActivityMethod ,
8994 ExpectedQuerystring : "app_id=A123&limit=0&min_date_created=1337" ,
9095 Response : fakeResult ,
9196 })
9297 defer teardown ()
93- result , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
98+ result , err := c .Activity (ctx , "token" , types.ActivityRequest {
9499 AppId : "A123" ,
95100 MinimumDateCreated : 1337 ,
96101 })
@@ -99,13 +104,14 @@ func Test_ApiClient_ActivityMinDateCreated(t *testing.T) {
99104}
100105
101106func Test_ApiClient_ActivityComponentType (t * testing.T ) {
107+ ctx := slackcontext .MockContext (t .Context ())
102108 c , teardown := NewFakeClient (t , FakeClientParams {
103109 ExpectedMethod : appActivityMethod ,
104110 ExpectedQuerystring : "app_id=A123&limit=0&component_type=defirbulator" ,
105111 Response : fakeResult ,
106112 })
107113 defer teardown ()
108- result , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
114+ result , err := c .Activity (ctx , "token" , types.ActivityRequest {
109115 AppId : "A123" ,
110116 ComponentType : "defirbulator" ,
111117 })
@@ -114,13 +120,14 @@ func Test_ApiClient_ActivityComponentType(t *testing.T) {
114120}
115121
116122func Test_ApiClient_ActivityComponentId (t * testing.T ) {
123+ ctx := slackcontext .MockContext (t .Context ())
117124 c , teardown := NewFakeClient (t , FakeClientParams {
118125 ExpectedMethod : appActivityMethod ,
119126 ExpectedQuerystring : "app_id=A123&limit=0&component_id=raspberry" ,
120127 Response : fakeResult ,
121128 })
122129 defer teardown ()
123- result , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
130+ result , err := c .Activity (ctx , "token" , types.ActivityRequest {
124131 AppId : "A123" ,
125132 ComponentId : "raspberry" ,
126133 })
@@ -129,13 +136,14 @@ func Test_ApiClient_ActivityComponentId(t *testing.T) {
129136}
130137
131138func Test_ApiClient_ActivitySource (t * testing.T ) {
139+ ctx := slackcontext .MockContext (t .Context ())
132140 c , teardown := NewFakeClient (t , FakeClientParams {
133141 ExpectedMethod : appActivityMethod ,
134142 ExpectedQuerystring : "app_id=A123&limit=0&source=beer" ,
135143 Response : fakeResult ,
136144 })
137145 defer teardown ()
138- result , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
146+ result , err := c .Activity (ctx , "token" , types.ActivityRequest {
139147 AppId : "A123" ,
140148 Source : "beer" ,
141149 })
@@ -144,13 +152,14 @@ func Test_ApiClient_ActivitySource(t *testing.T) {
144152}
145153
146154func Test_ApiClient_ActivityTraceId (t * testing.T ) {
155+ ctx := slackcontext .MockContext (t .Context ())
147156 c , teardown := NewFakeClient (t , FakeClientParams {
148157 ExpectedMethod : appActivityMethod ,
149158 ExpectedQuerystring : "app_id=A123&limit=0&trace_id=stealth" ,
150159 Response : fakeResult ,
151160 })
152161 defer teardown ()
153- result , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
162+ result , err := c .Activity (ctx , "token" , types.ActivityRequest {
154163 AppId : "A123" ,
155164 TraceId : "stealth" ,
156165 })
@@ -159,41 +168,44 @@ func Test_ApiClient_ActivityTraceId(t *testing.T) {
159168}
160169
161170func Test_ApiClient_ActivityResponseNotOK (t * testing.T ) {
171+ ctx := slackcontext .MockContext (t .Context ())
162172 c , teardown := NewFakeClient (t , FakeClientParams {
163173 ExpectedMethod : appActivityMethod ,
164174 ExpectedQuerystring : "app_id=A123" ,
165175 Response : `{"ok":false, "error": "internal_error"}` ,
166176 })
167177 defer teardown ()
168- _ , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
178+ _ , err := c .Activity (ctx , "token" , types.ActivityRequest {
169179 AppId : "A123" ,
170180 })
171181 require .Error (t , err )
172182 require .Contains (t , err .Error (), "internal_error" )
173183}
174184
175185func Test_ApiClient_ActivityInvalidResponse (t * testing.T ) {
186+ ctx := slackcontext .MockContext (t .Context ())
176187 c , teardown := NewFakeClient (t , FakeClientParams {
177188 ExpectedMethod : appActivityMethod ,
178189 ExpectedQuerystring : "app_id=A123" ,
179190 Response : `badjson` ,
180191 })
181192 defer teardown ()
182- _ , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
193+ _ , err := c .Activity (ctx , "token" , types.ActivityRequest {
183194 AppId : "A123" ,
184195 })
185196 require .Error (t , err )
186197 require .Contains (t , err .Error (), slackerror .ErrHttpResponseInvalid )
187198}
188199
189200func Test_ApiClient_ActivityInvalidJSON (t * testing.T ) {
201+ ctx := slackcontext .MockContext (t .Context ())
190202 c , teardown := NewFakeClient (t , FakeClientParams {
191203 ExpectedMethod : appActivityMethod ,
192204 ExpectedQuerystring : "app_id=A123" ,
193205 Response : `badtime` ,
194206 })
195207 defer teardown ()
196- _ , err := c .Activity (context . Background () , "token" , types.ActivityRequest {
208+ _ , err := c .Activity (ctx , "token" , types.ActivityRequest {
197209 AppId : "A123" ,
198210 })
199211 require .Error (t , err )
0 commit comments