@@ -100,13 +100,13 @@ describe('Events client', () => {
100
100
} ) ;
101
101
} ) ;
102
102
103
- const authModes : GraphQLAuthMode [ ] = [
104
- 'apiKey' ,
105
- 'userPool' ,
106
- 'oidc' ,
107
- 'iam' ,
108
- 'lambda' ,
109
- 'none' ,
103
+ const authModeConfigs : { authMode : GraphQLAuthMode , apiKey ?: string , authToken ?: string } [ ] = [
104
+ { authMode : 'apiKey' , apiKey : 'testAPIKey' } ,
105
+ { authMode : 'userPool' , authToken : 'userPoolToken' } ,
106
+ { authMode : 'oidc' , authToken : 'oidcToken' } ,
107
+ { authMode : 'iam' , authToken : 'iamToken' } ,
108
+ { authMode : 'lambda' , authToken : 'lambdaToken' } ,
109
+ { authMode : 'none' } ,
110
110
] ;
111
111
112
112
describe ( 'channel' , ( ) => {
@@ -124,12 +124,16 @@ describe('Events client', () => {
124
124
mockProvider = AppSyncEventProvider ;
125
125
} ) ;
126
126
127
- for ( const authMode of authModes ) {
128
- test ( `auth override: ${ authMode } ` , async ( ) => {
129
- await events . connect ( '/' , { authMode } ) ;
127
+ for ( const authConfig of authModeConfigs ) {
128
+ const { authMode : authenticationType , ...config } = authConfig
129
+ test ( `connect auth override: ${ authConfig . authMode } ` , async ( ) => {
130
+ const channel = await events . connect ( '/' , authConfig ) ;
130
131
131
132
expect ( mockProvider . connect ) . toHaveBeenCalledWith (
132
- expect . objectContaining ( { authenticationType : authMode } ) ,
133
+ expect . objectContaining ( {
134
+ authenticationType,
135
+ ...config
136
+ } ) ,
133
137
) ;
134
138
} ) ;
135
139
}
@@ -153,20 +157,24 @@ describe('Events client', () => {
153
157
mockProvider = AppSyncEventProvider ;
154
158
} ) ;
155
159
156
- for ( const authMode of authModes ) {
157
- test ( `auth override: ${ authMode } ` , async ( ) => {
158
- const channel = await events . connect ( '/' ) ;
160
+ for ( const authConfig of authModeConfigs ) {
161
+ const { authMode : authenticationType , ...config } = authConfig
159
162
160
- channel . subscribe (
163
+ test ( `subscription auth override: ${ authConfig . authMode } ` , async ( ) => {
164
+ const channel = await events . connect ( '/' ) ;
165
+ channel . subscribe (
161
166
{
162
167
next : data => void data ,
163
168
error : error => void error ,
164
169
} ,
165
- { authMode } ,
166
- ) ;
167
-
168
- expect ( mockSubscribeObservable ) . toHaveBeenCalledWith (
169
- expect . objectContaining ( { authenticationType : authMode } ) ,
170
+ authConfig
171
+ )
172
+
173
+ expect ( mockProvider . subscribe ) . toHaveBeenCalledWith (
174
+ expect . objectContaining ( {
175
+ authenticationType,
176
+ ...config
177
+ } ) ,
170
178
) ;
171
179
} ) ;
172
180
}
@@ -195,14 +203,21 @@ describe('Events client', () => {
195
203
mockProvider = AppSyncEventProvider ;
196
204
} ) ;
197
205
198
- for ( const authMode of authModes ) {
199
- test ( `auth override: ${ authMode } ` , async ( ) => {
200
- const channel = await events . connect ( '/' ) ;
206
+ for ( const authConfig of authModeConfigs ) {
207
+ const { authMode : authenticationType , ...config } = authConfig
201
208
202
- channel . publish ( { some : 'data' } , { authMode } ) ;
209
+ test ( `publish auth override: ${ authConfig . authMode } ` , async ( ) => {
210
+ const channel = await events . connect ( '/' ) ;
211
+ channel . publish (
212
+ "Test message" ,
213
+ authConfig
214
+ )
203
215
204
216
expect ( mockProvider . publish ) . toHaveBeenCalledWith (
205
- expect . objectContaining ( { authenticationType : authMode } ) ,
217
+ expect . objectContaining ( {
218
+ authenticationType,
219
+ ...config
220
+ } ) ,
206
221
) ;
207
222
} ) ;
208
223
}
@@ -230,16 +245,19 @@ describe('Events client', () => {
230
245
) ;
231
246
} ) ;
232
247
233
- for ( const authMode of authModes ) {
234
- test ( `auth override: ${ authMode } ` , async ( ) => {
235
- await events . post ( '/' , { test : 'data' } , { authMode } ) ;
248
+ for ( const authConfig of authModeConfigs ) {
249
+ const { authMode : authenticationType , ...config } = authConfig
250
+
251
+ test ( `auth override: ${ authenticationType } ` , async ( ) => {
252
+ await events . post ( '/' , { test : 'data' } , authConfig ) ;
236
253
237
254
expect ( mockReq ) . toHaveBeenCalledWith (
238
255
Amplify ,
239
256
expect . objectContaining ( {
240
257
query : '/' ,
241
258
variables : [ '{"test":"data"}' ] ,
242
- authenticationType : authMode ,
259
+ authenticationType,
260
+ ...config
243
261
} ) ,
244
262
{ } ,
245
263
abortController ,
0 commit comments