1212//
1313//===----------------------------------------------------------------------===//
1414
15+ import Foundation
1516import Testing
17+
1618@testable import AWSLambdaRuntime
17- import Foundation
1819
1920@Suite ( " LambdaContext ClientContext Tests " )
2021struct LambdaContextTests {
21-
22+
2223 @Test ( " ClientContext with full data resolves correctly " )
2324 func clientContextWithFullDataResolves( ) throws {
2425 let custom = [ " key " : " value " ]
@@ -34,17 +35,17 @@ struct LambdaContextTests {
3435 custom: custom,
3536 environment: environment
3637 )
37-
38+
3839 let encoder = JSONEncoder ( )
3940 let clientContextData = try encoder. encode ( clientContext)
40-
41+
4142 // Verify JSON encoding/decoding works correctly
4243 let decoder = JSONDecoder ( )
4344 let decodedClientContext = try decoder. decode ( ClientContext . self, from: clientContextData)
44-
45+
4546 let decodedClient = try #require( decodedClientContext. client)
4647 let originalClient = try #require( clientContext. client)
47-
48+
4849 #expect( decodedClient. installationId == originalClient. installationId)
4950 #expect( decodedClient. appTitle == originalClient. appTitle)
5051 #expect( decodedClient. appVersionName == originalClient. appVersionName)
@@ -53,61 +54,61 @@ struct LambdaContextTests {
5354 #expect( decodedClientContext. custom == clientContext. custom)
5455 #expect( decodedClientContext. environment == clientContext. environment)
5556 }
56-
57+
5758 @Test ( " ClientContext with empty data resolves correctly " )
5859 func clientContextWithEmptyDataResolves( ) throws {
5960 let emptyClientContextJSON = " {} "
6061 let emptyClientContextData = emptyClientContextJSON. data ( using: . utf8) !
61-
62+
6263 let decoder = JSONDecoder ( )
6364 let decodedClientContext = try decoder. decode ( ClientContext . self, from: emptyClientContextData)
64-
65+
6566 // With empty JSON, we expect nil values for optional fields
6667 #expect( decodedClientContext. client == nil )
6768 #expect( decodedClientContext. custom == nil )
6869 #expect( decodedClientContext. environment == nil )
6970 }
70-
71+
7172 @Test ( " ClientContext with AWS Lambda JSON payload decodes correctly " )
7273 func clientContextWithAWSLambdaJSONPayload( ) throws {
7374 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+
9293 let jsonData = jsonPayload. data ( using: . utf8) !
9394 let decoder = JSONDecoder ( )
9495 let decodedClientContext = try decoder. decode ( ClientContext . self, from: jsonData)
95-
96+
9697 // Verify client application data
9798 let client = try #require( decodedClientContext. client)
9899 #expect( client. installationId == " example-id " )
99100 #expect( client. appTitle == " Example App " )
100101 #expect( client. appVersionName == " 1.0 " )
101102 #expect( client. appVersionCode == " 1 " )
102103 #expect( client. appPackageName == " com.example.app " )
103-
104+
104105 // Verify custom properties
105106 let custom = try #require( decodedClientContext. custom)
106107 #expect( custom [ " customKey " ] == " customValue " )
107-
108+
108109 // Verify environment settings
109110 let environment = try #require( decodedClientContext. environment)
110111 #expect( environment [ " platform " ] == " Android " )
111112 #expect( environment [ " platform_version " ] == " 10 " )
112113 }
113- }
114+ }
0 commit comments