@@ -17,68 +17,70 @@ import XCTest
17
17
18
18
class APIGatewayV2Tests : XCTestCase {
19
19
static let exampleGetEventBody = """
20
- {
21
- " routeKey " : " GET /hello " ,
22
- " version " : " 2.0 " ,
23
- " rawPath " : " /hello " ,
24
- " stageVariables " :{
25
- " foo " : " bar "
26
- },
27
- " requestContext " :{
28
- " timeEpoch " :1587750461466,
29
- " domainPrefix " : " hello " ,
30
- " authorizer " :{
31
- " jwt " :{
32
- " scopes " :[
33
- " hello "
34
- ],
35
- " claims " :{
36
- " aud " : " customers " ,
37
- " iss " : " https://hello.test.com/ " ,
38
- " iat " : " 1587749276 " ,
39
- " exp " : " 1587756476 "
40
- }
41
- }
42
- },
43
- " accountId " : " 0123456789 " ,
44
- " stage " : " $default " ,
45
- " domainName " : " hello.test.com " ,
46
- " apiId " : " pb5dg6g3rg " ,
47
- " requestId " : " LgLpnibOFiAEPCA= " ,
48
- " http " :{
49
- " path " : " /hello " ,
50
- " userAgent " : " Paw/3.1.10 (Macintosh; OS X/10.15.4) GCDHTTPRequest " ,
51
- " method " : " GET " ,
52
- " protocol " : " HTTP/1.1 " ,
53
- " sourceIp " : " 91.64.117.86 "
54
- },
55
- " time " : " 24/Apr/2020:17:47:41 +0000 "
56
- },
57
- " isBase64Encoded " :false,
58
- " rawQueryString " : " foo=bar " ,
59
- " queryStringParameters " :{
60
- " foo " : " bar "
61
- },
62
- " headers " :{
63
- " x-forwarded-proto " : " https " ,
64
- " x-forwarded-for " : " 91.64.117.86 " ,
65
- " x-forwarded-port " : " 443 " ,
66
- " authorization " : " Bearer abc123 " ,
67
- " host " : " hello.test.com " ,
68
- " x-amzn-trace-id " : " Root=1-5ea3263d-07c5d5ddfd0788bed7dad831 " ,
69
- " user-agent " : " Paw/3.1.10 (Macintosh; OS X/10.15.4) GCDHTTPRequest " ,
70
- " content-length " : " 0 "
71
- }
72
- }
73
- """
74
-
20
+ {
21
+ " routeKey " : " GET /hello " ,
22
+ " version " : " 2.0 " ,
23
+ " rawPath " : " /hello " ,
24
+ " stageVariables " :{
25
+ " foo " : " bar "
26
+ },
27
+ " requestContext " :{
28
+ " timeEpoch " :1587750461466,
29
+ " domainPrefix " : " hello " ,
30
+ " authorizer " :{
31
+ " jwt " :{
32
+ " scopes " :[
33
+ " hello "
34
+ ],
35
+ " claims " :{
36
+ " aud " : " customers " ,
37
+ " iss " : " https://hello.test.com/ " ,
38
+ " iat " : " 1587749276 " ,
39
+ " exp " : " 1587756476 "
40
+ }
41
+ }
42
+ },
43
+ " accountId " : " 0123456789 " ,
44
+ " stage " : " $default " ,
45
+ " domainName " : " hello.test.com " ,
46
+ " apiId " : " pb5dg6g3rg " ,
47
+ " requestId " : " LgLpnibOFiAEPCA= " ,
48
+ " http " :{
49
+ " path " : " /hello " ,
50
+ " userAgent " : " Paw/3.1.10 (Macintosh; OS X/10.15.4) GCDHTTPRequest " ,
51
+ " method " : " GET " ,
52
+ " protocol " : " HTTP/1.1 " ,
53
+ " sourceIp " : " 91.64.117.86 "
54
+ },
55
+ " time " : " 24/Apr/2020:17:47:41 +0000 "
56
+ },
57
+ " isBase64Encoded " :false,
58
+ " rawQueryString " : " foo=bar " ,
59
+ " queryStringParameters " :{
60
+ " foo " : " bar "
61
+ },
62
+ " headers " :{
63
+ " x-forwarded-proto " : " https " ,
64
+ " x-forwarded-for " : " 91.64.117.86 " ,
65
+ " x-forwarded-port " : " 443 " ,
66
+ " authorization " : " Bearer abc123 " ,
67
+ " host " : " hello.test.com " ,
68
+ " x-amzn-trace-id " : " Root=1-5ea3263d-07c5d5ddfd0788bed7dad831 " ,
69
+ " user-agent " : " Paw/3.1.10 (Macintosh; OS X/10.15.4) GCDHTTPRequest " ,
70
+ " content-length " : " 0 "
71
+ }
72
+ }
73
+ """
74
+
75
75
// MARK: - Request -
76
+
76
77
// MARK: Decoding
78
+
77
79
func testRequestDecodingExampleGetRequest( ) {
78
80
let data = APIGatewayV2Tests . exampleGetEventBody. data ( using: . utf8) !
79
81
var req : APIGatewayV2Request ?
80
82
XCTAssertNoThrow ( req = try JSONDecoder ( ) . decode ( APIGatewayV2Request . self, from: data) )
81
-
83
+
82
84
XCTAssertEqual ( req? . rawPath, " /hello " )
83
85
XCTAssertEqual ( req? . context. http. method, . GET)
84
86
XCTAssertEqual ( req? . queryStringParameters? . count, 1 )
0 commit comments