12
12
//
13
13
//===----------------------------------------------------------------------===//
14
14
15
+ import Foundation
15
16
import Testing
17
+
16
18
@testable import AWSLambdaRuntime
17
- import Foundation
18
19
19
20
@Suite ( " LambdaContext ClientContext Tests " )
20
21
struct LambdaContextTests {
21
-
22
+
22
23
@Test ( " ClientContext with full data resolves correctly " )
23
24
func clientContextWithFullDataResolves( ) throws {
24
25
let custom = [ " key " : " value " ]
@@ -34,17 +35,17 @@ struct LambdaContextTests {
34
35
custom: custom,
35
36
environment: environment
36
37
)
37
-
38
+
38
39
let encoder = JSONEncoder ( )
39
40
let clientContextData = try encoder. encode ( clientContext)
40
-
41
+
41
42
// Verify JSON encoding/decoding works correctly
42
43
let decoder = JSONDecoder ( )
43
44
let decodedClientContext = try decoder. decode ( ClientContext . self, from: clientContextData)
44
-
45
+
45
46
let decodedClient = try #require( decodedClientContext. client)
46
47
let originalClient = try #require( clientContext. client)
47
-
48
+
48
49
#expect( decodedClient. installationId == originalClient. installationId)
49
50
#expect( decodedClient. appTitle == originalClient. appTitle)
50
51
#expect( decodedClient. appVersionName == originalClient. appVersionName)
@@ -53,61 +54,61 @@ struct LambdaContextTests {
53
54
#expect( decodedClientContext. custom == clientContext. custom)
54
55
#expect( decodedClientContext. environment == clientContext. environment)
55
56
}
56
-
57
+
57
58
@Test ( " ClientContext with empty data resolves correctly " )
58
59
func clientContextWithEmptyDataResolves( ) throws {
59
60
let emptyClientContextJSON = " {} "
60
61
let emptyClientContextData = emptyClientContextJSON. data ( using: . utf8) !
61
-
62
+
62
63
let decoder = JSONDecoder ( )
63
64
let decodedClientContext = try decoder. decode ( ClientContext . self, from: emptyClientContextData)
64
-
65
+
65
66
// With empty JSON, we expect nil values for optional fields
66
67
#expect( decodedClientContext. client == nil )
67
68
#expect( decodedClientContext. custom == nil )
68
69
#expect( decodedClientContext. environment == nil )
69
70
}
70
-
71
+
71
72
@Test ( " ClientContext with AWS Lambda JSON payload decodes correctly " )
72
73
func clientContextWithAWSLambdaJSONPayload( ) throws {
73
74
let jsonPayload = """
74
- {
75
- " client " : {
76
- " installation_id " : " example-id " ,
77
- " app_title " : " Example App " ,
78
- " app_version_name " : " 1.0 " ,
79
- " app_version_code " : " 1 " ,
80
- " app_package_name " : " com.example.app "
81
- },
82
- " custom " : {
83
- " customKey " : " customValue "
84
- },
85
- " env " : {
86
- " platform " : " Android " ,
87
- " platform_version " : " 10 "
88
- }
89
- }
90
- """
91
-
75
+ {
76
+ " client " : {
77
+ " installation_id " : " example-id " ,
78
+ " app_title " : " Example App " ,
79
+ " app_version_name " : " 1.0 " ,
80
+ " app_version_code " : " 1 " ,
81
+ " app_package_name " : " com.example.app "
82
+ },
83
+ " custom " : {
84
+ " customKey " : " customValue "
85
+ },
86
+ " env " : {
87
+ " platform " : " Android " ,
88
+ " platform_version " : " 10 "
89
+ }
90
+ }
91
+ """
92
+
92
93
let jsonData = jsonPayload. data ( using: . utf8) !
93
94
let decoder = JSONDecoder ( )
94
95
let decodedClientContext = try decoder. decode ( ClientContext . self, from: jsonData)
95
-
96
+
96
97
// Verify client application data
97
98
let client = try #require( decodedClientContext. client)
98
99
#expect( client. installationId == " example-id " )
99
100
#expect( client. appTitle == " Example App " )
100
101
#expect( client. appVersionName == " 1.0 " )
101
102
#expect( client. appVersionCode == " 1 " )
102
103
#expect( client. appPackageName == " com.example.app " )
103
-
104
+
104
105
// Verify custom properties
105
106
let custom = try #require( decodedClientContext. custom)
106
107
#expect( custom [ " customKey " ] == " customValue " )
107
-
108
+
108
109
// Verify environment settings
109
110
let environment = try #require( decodedClientContext. environment)
110
111
#expect( environment [ " platform " ] == " Android " )
111
112
#expect( environment [ " platform_version " ] == " 10 " )
112
113
}
113
- }
114
+ }
0 commit comments