@@ -2,61 +2,63 @@ import { locationConstraintMiddleware } from "./";
2
2
3
3
describe ( "locationConstrainMiddleware" , ( ) => {
4
4
const next = jest . fn ( ) ;
5
+ const basicInput = {
6
+ foo : "bar"
7
+ } ;
5
8
6
9
beforeEach ( ( ) => {
7
10
jest . clearAllMocks ( ) ;
8
11
} ) ;
9
12
10
- it ( "should remove any CreateBucketConfiguration from requests directed at us-east-1", async ( ) => {
13
+ describe ( "for region us-east-1", ( ) => {
11
14
const handler = locationConstraintMiddleware ( {
12
15
region : ( ) => Promise . resolve ( "us-east-1" )
13
16
} ) ( next , { } as any ) ;
14
- const input = {
15
- CreateBucketConfiguration : { LocationConstraint : "us-east-1" } ,
16
- foo : "bar"
17
- } ;
18
- await handler ( { input } ) ;
19
-
20
- expect ( next . mock . calls . length ) . toBe ( 1 ) ;
21
- expect ( next . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
22
- input : {
23
- ...input ,
24
- CreateBucketConfiguration : undefined
25
- }
17
+
18
+ it ( "should not update LocationConstraint if it's already set" , async ( ) => {
19
+ const input = {
20
+ ...basicInput ,
21
+ CreateBucketConfiguration : { LocationConstraint : "us-east-1" }
22
+ } ;
23
+ await handler ( { input } ) ;
24
+ expect ( next . mock . calls . length ) . toBe ( 1 ) ;
25
+ expect ( next . mock . calls [ 0 ] [ 0 ] ) . toEqual ( { input } ) ;
26
26
} ) ;
27
- } ) ;
28
27
29
- it ( "should apply a CreateBucketConfiguration with a LocationConstraint of the target region for requests directed outside of us-east-1" , async ( ) => {
30
- const handler = locationConstraintMiddleware ( {
31
- region : ( ) => Promise . resolve ( "us-east-2" )
32
- } ) ( next , { } as any ) ;
33
- const input = {
34
- foo : "bar"
35
- } ;
36
-
37
- await handler ( { input } ) ;
38
-
39
- expect ( next . mock . calls . length ) . toBe ( 1 ) ;
40
- expect ( next . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
41
- input : {
42
- ...input ,
43
- CreateBucketConfiguration : { LocationConstraint : "us-east-2" }
44
- }
28
+ it ( "should not add LocationConstraint if it's not set" , async ( ) => {
29
+ const input = basicInput ;
30
+ await handler ( { input } ) ;
31
+ expect ( next . mock . calls . length ) . toBe ( 1 ) ;
32
+ expect ( next . mock . calls [ 0 ] [ 0 ] ) . toEqual ( { input } ) ;
45
33
} ) ;
46
34
} ) ;
47
35
48
- it ( "should do nothing if a LocationConstraint had already been set on a request directed outside of us-east-1" , async ( ) => {
36
+ describe ( "for region not us-east-1" , ( ) => {
37
+ const region = "us-east-2" ;
49
38
const handler = locationConstraintMiddleware ( {
50
- region : ( ) => Promise . resolve ( "us-east-2" )
39
+ region : ( ) => Promise . resolve ( region )
51
40
} ) ( next , { } as any ) ;
52
- const input = {
53
- CreateBucketConfiguration : { LocationConstraint : "us-east-1" } ,
54
- foo : "bar"
55
- } ;
56
41
57
- await handler ( { input } ) ;
42
+ it ( "should not update LocationConstraint if it's already set" , async ( ) => {
43
+ const input = {
44
+ ...basicInput ,
45
+ CreateBucketConfiguration : { LocationConstraint : "us-east-1" }
46
+ } ;
47
+ await handler ( { input } ) ;
48
+ expect ( next . mock . calls . length ) . toBe ( 1 ) ;
49
+ expect ( next . mock . calls [ 0 ] [ 0 ] ) . toEqual ( { input } ) ;
50
+ } ) ;
58
51
59
- expect ( next . mock . calls . length ) . toBe ( 1 ) ;
60
- expect ( next . mock . calls [ 0 ] [ 0 ] ) . toEqual ( { input } ) ;
52
+ it ( "should add region as LocationConstraint if it's not set" , async ( ) => {
53
+ const input = basicInput ;
54
+ await handler ( { input } ) ;
55
+ expect ( next . mock . calls . length ) . toBe ( 1 ) ;
56
+ expect ( next . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
57
+ input : {
58
+ ...input ,
59
+ CreateBucketConfiguration : { LocationConstraint : region }
60
+ }
61
+ } ) ;
62
+ } ) ;
61
63
} ) ;
62
64
} ) ;
0 commit comments