1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-22 08:07:30 +00:00

Add tests for extractSharedData and proxyURL

This commit is contained in:
Cadence Fish 2020-02-05 21:24:16 +13:00
parent bcfeb8bd53
commit 4fc7d6aa1e
No known key found for this signature in database
GPG Key ID: 81015DF9AA8607E1
5 changed files with 834 additions and 84 deletions

19
test/body.js Normal file
View File

@ -0,0 +1,19 @@
const tap = require("tap")
const constants = require("../src/lib/constants")
const {extractSharedData} = require("../src/lib/utils/body")
const fs = require("fs").promises
tap.test("extract shared data", async childTest => {
childTest.throws(() => extractSharedData(""), constants.symbols.NO_SHARED_DATA, "not found in blank")
{
const page = await fs.readFile("test/files/page-user-instagram.html", "utf8")
const sharedData = extractSharedData(page)
childTest.equal(sharedData.entry_data.ProfilePage[0].graphql.user.username, "instagram", "can extract user page")
}
{
const page = await fs.readFile("test/files/page-login.html", "utf8")
const sharedData = extractSharedData(page)
childTest.true(sharedData.entry_data.LoginAndSignupPage[0], "can extract login page")
}
childTest.end()
})

330
test/files/page-login.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

42
test/proxyurl.js Normal file
View File

@ -0,0 +1,42 @@
const tap = require("tap")
const {proxyImage, proxyVideo, proxyExtendedOwner} = require("../src/lib/utils/proxyurl")
tap.equal(
proxyImage("https://scontent-syd2-1.cdninstagram.com/v/t51.2885-15/e35/p1080x1080/83429487_106792960779790_3699017977444758529_n.jpg?_nc_ht=scontent-syd2-1.cdninstagram.com&_nc_cat=1&_nc_ohc=YYmv6lkrblAAX_9u9Kt&oh=81a70f2b92e70873b5ebc9253e7df937&oe=5EBC230A"),
"/imageproxy?url=https%3A%2F%2Fscontent-syd2-1.cdninstagram.com%2Fv%2Ft51.2885-15%2Fe35%2Fp1080x1080%2F83429487_106792960779790_3699017977444758529_n.jpg%3F_nc_ht%3Dscontent-syd2-1.cdninstagram.com%26_nc_cat%3D1%26_nc_ohc%3DYYmv6lkrblAAX_9u9Kt%26oh%3D81a70f2b92e70873b5ebc9253e7df937%26oe%3D5EBC230A",
"image is proxied"
)
tap.equal(
proxyVideo("https://scontent-syd2-1.cdninstagram.com/v/t50.2886-16/85299832_745217319218455_3874701039913515731_n.mp4?_nc_ht=scontent-syd2-1.cdninstagram.com&_nc_cat=107&_nc_ohc=_Em8_pb3RUIAX8S8tUh&oe=5E3CB718&oh=61d15c21a279f618bab0c5df335635cc"),
"/videoproxy?url=https%3A%2F%2Fscontent-syd2-1.cdninstagram.com%2Fv%2Ft50.2886-16%2F85299832_745217319218455_3874701039913515731_n.mp4%3F_nc_ht%3Dscontent-syd2-1.cdninstagram.com%26_nc_cat%3D107%26_nc_ohc%3D_Em8_pb3RUIAX8S8tUh%26oe%3D5E3CB718%26oh%3D61d15c21a279f618bab0c5df335635cc",
"video is proxied"
)
tap.test("proxy extended owner", childTest => {
const originalProfilePicURL = "https://scontent-syd2-1.cdninstagram.com/v/t51.2885-19/s150x150/59381178_2348911458724961_5863612957363011584_n.jpg?_nc_ht=scontent-syd2-1.cdninstagram.com&_nc_ohc=TrMM-1zPSA4AX857GJB&oh=15b843b0c1033784492b64b1170cd048&oe=5EC9125D"
const owner = {
id: "25025320",
username: "instagram",
is_verified: true,
full_name: "Instagram",
profile_pic_url: originalProfilePicURL
}
childTest.same(
proxyExtendedOwner(owner),
{
id: "25025320",
username: "instagram",
is_verified: true,
full_name: "Instagram",
profile_pic_url: "/imageproxy?url=https%3A%2F%2Fscontent-syd2-1.cdninstagram.com%2Fv%2Ft51.2885-19%2Fs150x150%2F59381178_2348911458724961_5863612957363011584_n.jpg%3F_nc_ht%3Dscontent-syd2-1.cdninstagram.com%26_nc_ohc%3DTrMM-1zPSA4AX857GJB%26oh%3D15b843b0c1033784492b64b1170cd048%26oe%3D5EC9125D"
},
"owner was proxied"
)
childTest.equal(
owner.profile_pic_url,
originalProfilePicURL,
"original owner was not modified"
)
childTest.end()
})

View File

@ -12,7 +12,8 @@ tap.same(
{type: "text", text: " "},
{type: "hashtag", text: "#epic", hashtag: "epic"},
{type: "text", text: ""}
]
],
"partsHashtag works"
)
// lone test username
@ -26,49 +27,55 @@ tap.same(
{type: "text", text: " with "},
{type: "user", text: "@person", user: "person"},
{type: "text", text: ""}
]
],
"partsUsername works"
)
tap.test("entire structure works", childTest => {
// plain text
tap.same(
childTest.same(
structure("hello world"),
[
{type: "text", text: "hello world"}
]
],
"plain text"
)
// username
tap.same(
childTest.same(
structure("hello @person world"),
[
{type: "text", text: "hello "},
{type: "user", text: "@person", user: "person"},
{type: "text", text: " world"}
]
],
"username"
)
// username at start
tap.same(
childTest.same(
structure("@person hello"),
[
{type: "text", text: ""},
{type: "user", text: "@person", user: "person"},
{type: "text", text: " hello"}
]
],
"username at start"
)
// username at end
tap.same(
childTest.same(
structure("hello @person"),
[
{type: "text", text: "hello "},
{type: "user", text: "@person", user: "person"},
{type: "text", text: ""},
]
],
"username at end"
)
// multiple usernames
tap.same(
childTest.same(
structure("hello @person1 @person2"),
[
{type: "text", text: "hello "},
@ -76,23 +83,25 @@ tap.same(
{type: "text", text: " "},
{type: "user", text: "@person2", user: "person2"},
{type: "text", text: ""}
]
],
"multiple usernames"
)
// hashtag
tap.same(
childTest.same(
structure("what a #beautiful day"),
[
{type: "text", text: "what a "},
{type: "hashtag", text: "#beautiful", hashtag: "beautiful"},
{type: "text", text: " day"}
]
],
"hashtag"
)
// mixed
tap.same(
childTest.same(
structure("@person what a #beautiful #day in @city"),
[
{type: "text", text: ""},
@ -104,11 +113,12 @@ tap.same(
{type: "text", text: " in "},
{type: "user", text: "@city", user: "city"},
{type: "text", text: ""}
]
],
"mixed"
)
// special characters
tap.same(
childTest.same(
structure("#goodmorning! @city.planner, #parks\nare awesome"),
[
{type: "text", text: ""},
@ -118,5 +128,9 @@ tap.same(
{type: "text", text: ", "},
{type: "hashtag", text: "#parks", hashtag: "parks"},
{type: "text", text: "\nare awesome"}
]
],
"special characters"
)
childTest.end()
})