Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / communicate-dev / src / test / java / com / vayunmathur / communicate / whatsapp / MexEnvelopeTest.kt
MexEnvelopeTest.kt33 lines · 1.1 KiBRaw
| 1 | package com.vayunmathur.communicate.whatsapp |
| 2 | |
| 3 | import com.vayunmathur.communicate.data.whatsapp.mex.MexEnvelope |
| 4 | import kotlin.test.Test |
| 5 | import kotlin.test.assertEquals |
| 6 | |
| 7 | /** |
| 8 | * Asserts the MEX-over-XMPP `<query>` envelope shape (w2.md §5.2): |
| 9 | * `{"queryId":"<docId>","variables":{…}}`. Pure kotlinx — no Android/org.json. |
| 10 | */ |
| 11 | class MexEnvelopeTest { |
| 12 | |
| 13 | @Test |
| 14 | fun buildQueryJson_wrapsVariablesWithStringQueryId() { |
| 15 | val out = MexEnvelope.buildQueryJson("27462649126753603", """{"group_input":{"group_jid":"[email protected]"}}""") |
| 16 | assertEquals( |
| 17 | """{"queryId":"27462649126753603","variables":{"group_input":{"group_jid":"[email protected]"}}}""", |
| 18 | out, |
| 19 | ) |
| 20 | } |
| 21 | |
| 22 | @Test |
| 23 | fun buildQueryJson_blankVariablesBecomesEmptyObject() { |
| 24 | val out = MexEnvelope.buildQueryJson("123", "") |
| 25 | assertEquals("""{"queryId":"123","variables":{}}""", out) |
| 26 | } |
| 27 | |
| 28 | @Test |
| 29 | fun buildQueryJson_malformedVariablesFallsBackToEmptyObject() { |
| 30 | val out = MexEnvelope.buildQueryJson("123", "not json") |
| 31 | assertEquals("""{"queryId":"123","variables":{}}""", out) |
| 32 | } |
| 33 | } |