@@ -10,7 +10,7 @@ import { RestService } from '../../schemaregistry/rest-service';
1010import { AxiosResponse } from 'axios' ;
1111import stringify from "json-stringify-deterministic" ;
1212import { beforeEach , afterEach , describe , expect , it , jest } from '@jest/globals' ;
13- import { mockClientConfig } from '../../test/schemaregistry/test-constants' ;
13+ import { mockClientConfig , mockTtlClientConfig } from '../../test/schemaregistry/test-constants' ;
1414
1515jest . mock ( '../../schemaregistry/rest-service' ) ;
1616
@@ -76,6 +76,10 @@ const schemaInfoMetadata2 = {
7676const subjects : string [ ] = [ mockSubject , mockSubject2 ] ;
7777const versions : number [ ] = [ 1 , 2 , 3 ] ;
7878
79+ async function sleep ( ms : number ) {
80+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
81+ }
82+
7983describe ( 'SchemaRegistryClient-Register' , ( ) => {
8084
8185 beforeEach ( ( ) => {
@@ -630,3 +634,33 @@ describe('SchemaRegistryClient-Config', () => {
630634 expect ( restService . handleRequest ) . toHaveBeenCalledTimes ( 1 ) ;
631635 } ) ;
632636} ) ;
637+
638+ describe ( 'SchemaRegistryClient-Cache' , ( ) => {
639+ beforeEach ( ( ) => {
640+ restService = new RestService ( mockClientConfig . baseURLs ) as jest . Mocked < RestService > ;
641+ client = new SchemaRegistryClient ( mockTtlClientConfig ) ;
642+ ( client as any ) . restService = restService ;
643+ } ) ;
644+ afterEach ( ( ) => {
645+ jest . clearAllMocks ( ) ;
646+ } ) ;
647+
648+ it ( 'Should delete cached item after expiry' , async ( ) => {
649+ const expectedResponse = {
650+ id : 1 ,
651+ version : 1 ,
652+ schema : schemaString ,
653+ metadata : metadata ,
654+ } ;
655+
656+ restService . handleRequest . mockResolvedValue ( { data : expectedResponse } as AxiosResponse ) ;
657+
658+ await client . register ( mockSubject , schemaInfo ) ;
659+
660+ await sleep ( 2000 ) ;
661+
662+ await client . register ( mockSubject , schemaInfo ) ;
663+
664+ expect ( restService . handleRequest ) . toHaveBeenCalledTimes ( 2 ) ;
665+ } ) ;
666+ } ) ;
0 commit comments