@@ -24,6 +24,7 @@ import { AccessToken } from '../accessToken/model'
24
24
import { Interaction , InteractionState } from '../interaction/model'
25
25
import { Pagination , SortOrder } from '../shared/baseModel'
26
26
import { getPageTests } from '../shared/baseModel.test'
27
+ import { WebhookEvent } from '../webhook/model'
27
28
28
29
describe ( 'Grant Service' , ( ) : void => {
29
30
let deps : IocContract < AppServices >
@@ -366,11 +367,51 @@ describe('Grant Service', (): void => {
366
367
updatedAt : expect . any ( Date )
367
368
}
368
369
] )
370
+ expect (
371
+ WebhookEvent . query ( ) . where ( { grantId : grant . id } )
372
+ ) . resolves . toHaveLength ( 1 )
369
373
} )
370
374
371
375
test ( 'Can "revoke" unknown grant' , async ( ) : Promise < void > => {
372
376
await expect ( grantService . revokeGrant ( v4 ( ) ) ) . resolves . toEqual ( false )
373
377
} )
378
+
379
+ describe ( 'revoke with webhook disabled' , ( ) : void => {
380
+ beforeAll ( async ( ) : Promise < void > => {
381
+ Config . webhookEnabled = false
382
+ } )
383
+
384
+ afterAll ( async ( ) : Promise < void > => {
385
+ Config . webhookEnabled = true
386
+ } )
387
+
388
+ test ( 'Can revoke a grant and not save webhook event' , async ( ) : Promise < void > => {
389
+ await expect ( grantService . revokeGrant ( grant . id ) ) . resolves . toEqual (
390
+ true
391
+ )
392
+
393
+ const revokedGrant = await Grant . query ( knex ) . findById ( grant . id )
394
+ expect ( revokedGrant ?. state ) . toEqual ( GrantState . Finalized )
395
+ expect ( revokedGrant ?. finalizationReason ) . toEqual (
396
+ GrantFinalization . Revoked
397
+ )
398
+ expect ( Access . query ( ) . where ( { grantId : grant . id } ) ) . resolves . toEqual ( [
399
+ { ...access , limits : null }
400
+ ] )
401
+ expect (
402
+ AccessToken . query ( ) . where ( { grantId : grant . id } )
403
+ ) . resolves . toEqual ( [
404
+ {
405
+ ...accessToken ,
406
+ revokedAt : expect . any ( Date ) ,
407
+ updatedAt : expect . any ( Date )
408
+ }
409
+ ] )
410
+ expect (
411
+ WebhookEvent . query ( ) . where ( { grantId : grant . id } )
412
+ ) . resolves . toHaveLength ( 0 )
413
+ } )
414
+ } )
374
415
} )
375
416
376
417
describe ( 'lock' , ( ) : void => {
0 commit comments