@@ -24,6 +24,7 @@ import { AccessToken } from '../accessToken/model'
2424import { Interaction , InteractionState } from '../interaction/model'
2525import { Pagination , SortOrder } from '../shared/baseModel'
2626import { getPageTests } from '../shared/baseModel.test'
27+ import { WebhookEvent } from '../webhook/model'
2728
2829describe ( 'Grant Service' , ( ) : void => {
2930 let deps : IocContract < AppServices >
@@ -366,11 +367,51 @@ describe('Grant Service', (): void => {
366367 updatedAt : expect . any ( Date )
367368 }
368369 ] )
370+ expect (
371+ WebhookEvent . query ( ) . where ( { grantId : grant . id } )
372+ ) . resolves . toHaveLength ( 1 )
369373 } )
370374
371375 test ( 'Can "revoke" unknown grant' , async ( ) : Promise < void > => {
372376 await expect ( grantService . revokeGrant ( v4 ( ) ) ) . resolves . toEqual ( false )
373377 } )
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+ } )
374415 } )
375416
376417 describe ( 'lock' , ( ) : void => {
0 commit comments