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

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

WwwGraphQlBodyTest.kt36 lines · 1.2 KiBRaw
1package com.vayunmathur.communicate.whatsapp
2
3import com.vayunmathur.communicate.data.whatsapp.mex.MexEnvelope
4import kotlin.test.Test
5import kotlin.test.assertEquals
6
7/**
8 * Asserts the WWW GraphQL HTTP body shape (w2.md §4.1 / §5.3): `access_token` string, `doc_id` as a
9 * JSON **number**, `lang`, the literal `Content-Type` JSON key, and raw `variables`.
10 */
11class WwwGraphQlBodyTest {
12
13 @Test
14 fun buildWwwBody_matchesDocumentedEnvelope() {
15 val out = MexEnvelope.buildWwwBody(TOKEN, "27056625294008854", """{"input":{"key":"1@newsletter"}}""")
16 assertEquals(
17 """{"access_token":"$TOKEN","doc_id":27056625294008854,"lang":"en_US",""" +
18 """"Content-Type":"application/json","variables":{"input":{"key":"1@newsletter"}}}""",
19 out,
20 )
21 }
22
23 @Test
24 fun buildWwwBody_nonNumericDocIdStaysString() {
25 val out = MexEnvelope.buildWwwBody(TOKEN, "abc", "{}")
26 assertEquals(
27 """{"access_token":"$TOKEN","doc_id":"abc","lang":"en_US",""" +
28 """"Content-Type":"application/json","variables":{}}""",
29 out,
30 )
31 }
32
33 private companion object {
34 const val TOKEN = "WA|1015890928915437|3201f239340c1c8ec6262a6dad04200e"
35 }
36}