@@ -150,42 +150,58 @@ class EmbeddedCheckoutProtocolTest {
150150
151151 // endregion
152152
153- // region unsupported methods — silently ignored
153+ // region unsupported methods
154154
155155 @Test
156- fun `ec auth is silently ignored and not delegated to client` () {
157- assertIgnoredByBridge(""" {"jsonrpc":"2.0","method":"ec.auth","id":"1","params":{"type":"oauth"}}""" )
156+ fun `ec auth request returns method not found and is not delegated to client` () {
157+ assertMethodNotFoundByBridge(
158+ """ {"jsonrpc":"2.0","method":"ec.auth","id":"1","params":{"type":"oauth"}}""" ,
159+ """ "id":"1"""" ,
160+ )
161+ }
162+
163+ @Test
164+ fun `ec payment instruments change request returns method not found and is not delegated to client` () {
165+ assertMethodNotFoundByBridge(
166+ """ {"jsonrpc":"2.0","method":"ec.payment.instruments_change_request","id":"2","params":{}}""" ,
167+ """ "id":"2"""" ,
168+ )
158169 }
159170
160171 @Test
161- fun `ec payment instruments change request is silently ignored and not delegated to client` () {
162- assertIgnoredByBridge(
163- """ {"jsonrpc":"2.0","method":"ec.payment.instruments_change_request","id":"2","params":{}}"""
172+ fun `ec payment credential request returns method not found and is not delegated to client` () {
173+ assertMethodNotFoundByBridge(
174+ """ {"jsonrpc":"2.0","method":"ec.payment.credential_request","id":"3","params":{}}""" ,
175+ """ "id":"3"""" ,
164176 )
165177 }
166178
167179 @Test
168- fun `ec payment credential request is silently ignored and not delegated to client` () {
169- assertIgnoredByBridge(
170- """ {"jsonrpc":"2.0","method":"ec.payment.credential_request","id":"3","params":{}}"""
180+ fun `ec fulfillment address change request returns method not found and is not delegated to client` () {
181+ assertMethodNotFoundByBridge(
182+ """ {"jsonrpc":"2.0","method":"ec.fulfillment.address_change_request","id":"4","params":{}}""" ,
183+ """ "id":"4"""" ,
171184 )
172185 }
173186
174187 @Test
175- fun `ec fulfillment address change request is silently ignored and not delegated to client` () {
176- assertIgnoredByBridge(
177- """ {"jsonrpc":"2.0","method":"ec.fulfillment.address_change_request","id":"4","params":{}}"""
188+ fun `ep cart request returns method not found and is not delegated to client` () {
189+ assertMethodNotFoundByBridge(
190+ """ {"jsonrpc":"2.0","method":"ep.cart.ready","id":"5","params":{}}""" ,
191+ """ "id":"5"""" ,
178192 )
179193 }
180194
181195 @Test
182- fun `ec buyer change is silently ignored and not delegated to client` () {
196+ fun `ec buyer change notification is ignored and not delegated to client` () {
183197 assertIgnoredByBridge(""" {"jsonrpc":"2.0","method":"ec.buyer.change","params":{"checkout":{}}}""" )
184198 }
185199
186200 @Test
187- fun `ep cart methods fall through as unsupported and are not delegated to client` () {
188- assertIgnoredByBridge(""" {"jsonrpc":"2.0","method":"ep.cart.ready","id":"5","params":{}}""" )
201+ fun `unsupported notifications are ignored and not delegated to client` () {
202+ assertIgnoredByBridge(""" {"jsonrpc":"2.0","method":"ec.auth","params":{"type":"oauth"}}""" )
203+ assertIgnoredByBridge(""" {"jsonrpc":"2.0","method":"ec.buyer.change","params":{"checkout":{}}}""" )
204+ assertIgnoredByBridge(""" {"jsonrpc":"2.0","method":"ep.cart.ready","params":{}}""" )
189205 }
190206
191207 // endregion
@@ -496,9 +512,9 @@ class EmbeddedCheckoutProtocolTest {
496512 // region client delegation — requests
497513
498514 @Test
499- fun `unknown method is silently ignored and not delegated to client` () {
515+ fun `unknown request returns method not found and is not delegated to client` () {
500516 val rawMessage = """ {"jsonrpc":"2.0","method":"customMethod","id":"8","params":{}}"""
501- assertIgnoredByBridge (rawMessage)
517+ assertMethodNotFoundByBridge (rawMessage, """ "id":"8" """ )
502518 }
503519
504520 @Test
@@ -530,11 +546,20 @@ class EmbeddedCheckoutProtocolTest {
530546 }
531547
532548 @Test
533- fun `unknown method with no client sends nothing to checkout` () {
534- ecp.postMessage (""" {"jsonrpc":"2.0","method":"unknownMethod","id":"11 "}""" )
535- shadowOf( Looper .getMainLooper()).runToEndOfTasks()
549+ fun `unknown notification sends nothing to checkout` () {
550+ assertIgnoredByBridge (""" {"jsonrpc":"2.0","method":"unknownMethod"}""" )
551+ }
536552
537- verify(viewSpy, never()).evaluateJavascript(any(), any())
553+ @Test
554+ fun `unknown request with no client returns method not found` () {
555+ val js = captureEvaluatedJs {
556+ ecp.postMessage(""" {"jsonrpc":"2.0","method":"unknownMethod","id":"11"}""" )
557+ }
558+
559+ assertThat(js).contains(" \" error\" " )
560+ assertThat(js).contains(" -32601" )
561+ assertThat(js).contains(" Method not found" )
562+ assertThat(js).contains(""" "id":"11"""" )
538563 }
539564
540565 // endregion
@@ -600,6 +625,21 @@ class EmbeddedCheckoutProtocolTest {
600625 verify(client, never()).process(any())
601626 }
602627
628+ private fun assertMethodNotFoundByBridge (rawMessage : String , expectedId : String ) {
629+ val client = mock<CheckoutCommunicationClient >()
630+ ecp.setClient(client)
631+
632+ val js = captureEvaluatedJs {
633+ ecp.postMessage(rawMessage)
634+ }
635+
636+ assertThat(js).contains(" \" error\" " )
637+ assertThat(js).contains(" -32601" )
638+ assertThat(js).contains(" Method not found" )
639+ assertThat(js).contains(expectedId)
640+ verify(client, never()).process(any())
641+ }
642+
603643 private fun ecErrorMessage (severity : String ): String {
604644 val messages =
605645 """ [{"type":"error","code":"session_failed","content":"Session failed","severity":"$severity "}]"""
0 commit comments