Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / communicate-dev / src / test / java / com / vayunmathur / communicate / whatsapp / WhatsAppMexOpsVariablesTest.kt

WhatsAppMexOpsVariablesTest.kt69 lines · 2.6 KiBRaw
1package com.vayunmathur.communicate.whatsapp
2
3import com.vayunmathur.communicate.data.whatsapp.mex.WhatsAppMexVariables
4import java.util.Base64
5import kotlin.test.Test
6import kotlin.test.assertEquals
7
8/**
9 * Asserts a representative set of `xwa2_*` `variables` builders match the w2.md §8 JSON shapes.
10 * Pure — the builders use java.util.Base64, so no Android runtime is required.
11 */
12class WhatsAppMexOpsVariablesTest {
13
14 @Test
15 fun groupQueryByIdVariables_usesGroupInputArg() {
16 assertEquals(
17 """{"group_input":{"group_jid":"[email protected]","query_context":"INTERACTIVE"}}""",
18 WhatsAppMexVariables.buildGroupQueryByIdVariables("[email protected]", "INTERACTIVE"),
19 )
20 }
21
22 @Test
23 fun usernameSetVariables_omitsNullPinAndSession() {
24 assertEquals(
25 """{"username":"johndoe","source":"USER_INPUT","pin":"ABC123"}""",
26 WhatsAppMexVariables.buildUsernameSetVariables("johndoe", "ABC123", "USER_INPUT", null),
27 )
28 }
29
30 @Test
31 fun contactDiscoveryVariables_matchesSection83Shape() {
32 assertEquals(
33 """{"input":{"contacts":[{"phone":{"raw_pn":"+15551234567"}}],"context":"SEARCH"}}""",
34 WhatsAppMexVariables.buildContactDiscoveryVariables(listOf("+15551234567"), "SEARCH"),
35 )
36 }
37
38 @Test
39 fun setMessagingKeysVariables_matchesSection82Shape() {
40 val identity = ByteArray(32) { 1 }
41 val skeyValue = ByteArray(32) { 2 }
42 val skeySignature = ByteArray(64) { 3 }
43 val prekeyValue = ByteArray(32) { 4 }
44
45 val enc = Base64.getEncoder()
46 val expectedType = enc.encodeToString(byteArrayOf(0x05))
47 val expectedIdentity = enc.encodeToString(identity)
48 val expectedSkeyId = enc.encodeToString(byteArrayOf(0, 0, 1))
49 val expectedSkeyValue = enc.encodeToString(skeyValue)
50 val expectedSkeySig = enc.encodeToString(skeySignature)
51 val expectedPrekeyId = enc.encodeToString(byteArrayOf(0, 0, 7))
52 val expectedPrekeyValue = enc.encodeToString(prekeyValue)
53
54 val out = WhatsAppMexVariables.buildSetMessagingKeysVariables(
55 identity = identity,
56 skeyId = 1,
57 skeyValue = skeyValue,
58 skeySignature = skeySignature,
59 prekeys = listOf(7 to prekeyValue),
60 )
61
62 assertEquals(
63 """{"input":{"type":"$expectedType","identity":"$expectedIdentity",""" +
64 """"skey":{"id":"$expectedSkeyId","value":"$expectedSkeyValue","signature":"$expectedSkeySig"},""" +
65 """"prekeys":[{"id":"$expectedPrekeyId","value":"$expectedPrekeyValue"}]}}""",
66 out,
67 )
68 }
69}