@@ -20,37 +20,52 @@ import {
20
20
import { toBase64 } from '@aws-sdk/util-base64-node' ;
21
21
22
22
const encoder = new TextEncoder ( ) ;
23
+ jest . mock ( '@aws-lambda-powertools/commons' , ( ) => ( {
24
+ ...jest . requireActual ( '@aws-lambda-powertools/commons' ) ,
25
+ addUserAgentMiddleware : jest . fn ( ) ,
26
+ } ) ) ;
27
+
28
+ class TestProvider extends BaseProvider {
29
+ public constructor ( ) {
30
+ super ( {
31
+ proto : class {
32
+ #name = 'TestProvider' ;
33
+
34
+ public hello ( ) : string {
35
+ return this . #name;
36
+ }
37
+ } ,
38
+ } ) ;
39
+ }
40
+
41
+ public _add ( key : string , value : ExpirableValue ) : void {
42
+ this . store . set ( key , value ) ;
43
+ }
44
+
45
+ public _get ( _name : string ) : Promise < string > {
46
+ throw Error ( 'Not implemented.' ) ;
47
+ }
48
+
49
+ public _getKeyTest ( key : string ) : ExpirableValue | undefined {
50
+ return this . store . get ( key ) ;
51
+ }
52
+
53
+ public _getMultiple (
54
+ _path : string
55
+ ) : Promise < Record < string , string | undefined > > {
56
+ throw Error ( 'Not implemented.' ) ;
57
+ }
58
+
59
+ public _getStoreSize ( ) : number {
60
+ return this . store . size ;
61
+ }
62
+ }
23
63
24
64
describe ( 'Class: BaseProvider' , ( ) => {
25
65
afterEach ( ( ) => {
26
66
jest . clearAllMocks ( ) ;
27
67
} ) ;
28
68
29
- class TestProvider extends BaseProvider {
30
- public _add ( key : string , value : ExpirableValue ) : void {
31
- this . store . set ( key , value ) ;
32
- }
33
-
34
- public _get ( _name : string , _options : GetOptions ) : Promise < string > {
35
- throw Error ( 'Not implemented.' ) ;
36
- }
37
-
38
- public _getKeyTest ( key : string ) : ExpirableValue | undefined {
39
- return this . store . get ( key ) ;
40
- }
41
-
42
- public _getMultiple (
43
- _path : string ,
44
- _options ?: GetMultipleOptions
45
- ) : Promise < Record < string , string | undefined > > {
46
- throw Error ( 'Not implemented.' ) ;
47
- }
48
-
49
- public _getStoreSize ( ) : number {
50
- return this . store . size ;
51
- }
52
- }
53
-
54
69
describe ( 'Method: addToCache' , ( ) => {
55
70
test ( 'when called with a value and maxAge equal to 0, it skips the cache entirely' , ( ) => {
56
71
// Prepare
@@ -593,18 +608,6 @@ describe('Class: BaseProvider', () => {
593
608
} ) ;
594
609
595
610
describe ( 'Function: clearCaches' , ( ) => {
596
- class TestProvider extends BaseProvider {
597
- public _get ( _name : string ) : Promise < string > {
598
- throw Error ( 'Not implemented.' ) ;
599
- }
600
-
601
- public _getMultiple (
602
- _path : string
603
- ) : Promise < Record < string , string | undefined > > {
604
- throw Error ( 'Not implemented.' ) ;
605
- }
606
- }
607
-
608
611
test ( 'when called, it clears all the caches' , ( ) => {
609
612
// Prepare
610
613
const provider1 = new TestProvider ( ) ;
0 commit comments