1
- /// <reference types="mocha " />
1
+ /// <reference types="jest " />
2
2
import { HttpRequest } from "@aws-sdk/protocol-http" ;
3
3
import { BuildMiddleware , SerializeMiddleware } from "@aws-sdk/types" ;
4
- import chai from "chai" ;
5
- import chaiAsPromised from "chai-as-promised" ;
6
4
import { PassThrough } from "stream" ;
7
5
8
6
import { S3 } from "./S3" ;
9
7
10
- chai . use ( chaiAsPromised ) ;
11
- const { expect } = chai ;
12
-
13
8
describe ( "endpoint" , ( ) => {
14
9
it ( "users can override endpoint from client." , async ( ) => {
15
10
//use s3 here but all the clients are generated similarly
16
11
const endpointValidator : SerializeMiddleware < any , any > = ( next ) => ( args ) => {
17
12
// middleware intercept the request and return it early
18
13
const request = args . request as HttpRequest ;
19
- expect ( request . protocol ) . to . equal ( "http:" ) ;
20
- expect ( request . hostname ) . to . equal ( "localhost" ) ;
21
- expect ( request . port ) . to . equal ( 8080 ) ;
14
+ expect ( request . protocol ) . toEqual ( "http:" ) ;
15
+ expect ( request . hostname ) . toEqual ( "localhost" ) ;
16
+ expect ( request . port ) . toEqual ( 8080 ) ;
22
17
//query and path should not be overwritten
23
- expect ( request . query ) . not . to . contain ( { foo : "bar" } ) ;
24
- expect ( request . path ) . not . to . equal ( "/path" ) ;
18
+ expect ( request . query ) . not . toContainEqual ( { foo : "bar" } ) ;
19
+ expect ( request . path ) . not . toEqual ( "/path" ) ;
25
20
return Promise . resolve ( { output : { } as any , response : { } as any } ) ;
26
21
} ;
27
22
const client = new S3 ( { endpoint : "http://localhost:8080/path?foo=bar" } ) ;
@@ -60,7 +55,7 @@ describe("Accesspoint ARN", async () => {
60
55
Key : "key" ,
61
56
Body : "body" ,
62
57
} ) ;
63
- expect ( result . request . hostname ) . to . eql ( "myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com" ) ;
58
+ expect ( result . request . hostname ) . toEqual ( "myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com" ) ;
64
59
} ) ;
65
60
66
61
it ( "should sign request with region from ARN is useArnRegion is set" , async ( ) => {
@@ -75,9 +70,9 @@ describe("Accesspoint ARN", async () => {
75
70
Key : "key" ,
76
71
Body : "body" ,
77
72
} ) ;
78
- expect ( result . request . hostname ) . to . eql ( "myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com" ) ;
73
+ expect ( result . request . hostname ) . toEqual ( "myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com" ) ;
79
74
// Sign request with us-west-2 region from bucket access point ARN
80
- expect ( result . request . headers . authorization ) . to . contain ( "/us-west-2/s3/aws4_request, SignedHeaders=" ) ;
75
+ expect ( result . request . headers . authorization ) . toContain ( "/us-west-2/s3/aws4_request, SignedHeaders=" ) ;
81
76
} ) ;
82
77
83
78
it ( "should succeed with outposts ARN" , async ( ) => {
@@ -92,9 +87,9 @@ describe("Accesspoint ARN", async () => {
92
87
Key : "key" ,
93
88
Body : "body" ,
94
89
} ) ;
95
- expect ( result . request . hostname ) . to . eql ( `abc-111-${ AccountId } .${ OutpostId } .s3-outposts.us-west-2.amazonaws.com` ) ;
90
+ expect ( result . request . hostname ) . toEqual ( `abc-111-${ AccountId } .${ OutpostId } .s3-outposts.us-west-2.amazonaws.com` ) ;
96
91
const date = new Date ( ) . toISOString ( ) . substr ( 0 , 10 ) . replace ( / - / g, "" ) ; //20201029
97
- expect ( result . request . headers [ "authorization" ] ) . contains (
92
+ expect ( result . request . headers [ "authorization" ] ) . toContain (
98
93
`Credential=${ credentials . accessKeyId } /${ date } /${ region } /s3-outposts/aws4_request`
99
94
) ;
100
95
} ) ;
@@ -133,40 +128,36 @@ describe("Throw 200 response", () => {
133
128
134
129
it ( "should throw if CopyObject() return with 200 and empty payload" , async ( ) => {
135
130
response . body . end ( "" ) ;
136
- return expect ( client . copyObject ( params ) ) . to . eventually . be . rejectedWith ( "S3 aborted request" ) ;
131
+ return expect ( client . copyObject ( params ) ) . rejects . toThrow ( "S3 aborted request" ) ;
137
132
} ) ;
138
133
139
134
it ( "should throw if CopyObject() return with 200 and error preamble" , async ( ) => {
140
135
response . body . end ( errorBody ) ;
141
- return expect ( client . copyObject ( params ) ) . to . eventually . be . rejectedWith (
142
- "We encountered an internal error. Please try again."
143
- ) ;
136
+ return expect ( client . copyObject ( params ) ) . rejects . toThrow ( "We encountered an internal error. Please try again." ) ;
144
137
} ) ;
145
138
146
139
it ( "should throw if UploadPartCopy() return with 200 and empty payload" , async ( ) => {
147
140
response . body . end ( "" ) ;
148
- return expect ( client . uploadPartCopy ( { ...params , UploadId : "id" , PartNumber : 1 } ) ) . to . eventually . be . rejectedWith (
141
+ return expect ( client . uploadPartCopy ( { ...params , UploadId : "id" , PartNumber : 1 } ) ) . rejects . toThrow (
149
142
"S3 aborted request"
150
143
) ;
151
144
} ) ;
152
145
153
146
it ( "should throw if UploadPartCopy() return with 200 and error preamble" , async ( ) => {
154
147
response . body . end ( errorBody ) ;
155
- return expect ( client . uploadPartCopy ( { ...params , UploadId : "id" , PartNumber : 1 } ) ) . to . eventually . be . rejectedWith (
148
+ return expect ( client . uploadPartCopy ( { ...params , UploadId : "id" , PartNumber : 1 } ) ) . rejects . toThrow (
156
149
"We encountered an internal error. Please try again."
157
150
) ;
158
151
} ) ;
159
152
160
153
it ( "should throw if CompleteMultipartUpload() return with 200 and empty payload" , async ( ) => {
161
154
response . body . end ( "" ) ;
162
- return expect ( client . completeMultipartUpload ( { ...params , UploadId : "id" } ) ) . to . eventually . be . rejectedWith (
163
- "S3 aborted request"
164
- ) ;
155
+ return expect ( client . completeMultipartUpload ( { ...params , UploadId : "id" } ) ) . rejects . toThrow ( "S3 aborted request" ) ;
165
156
} ) ;
166
157
167
158
it ( "should throw if CompleteMultipartUpload() return with 200 and error preamble" , async ( ) => {
168
159
response . body . end ( errorBody ) ;
169
- return expect ( client . completeMultipartUpload ( { ...params , UploadId : "id" } ) ) . to . eventually . be . rejectedWith (
160
+ return expect ( client . completeMultipartUpload ( { ...params , UploadId : "id" } ) ) . rejects . toThrow (
170
161
"We encountered an internal error. Please try again."
171
162
) ;
172
163
} ) ;
0 commit comments