2020-02-05 08:24:16 +00:00
|
|
|
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 => {
|
2020-04-13 15:46:23 +00:00
|
|
|
{
|
|
|
|
const result = extractSharedData("")
|
|
|
|
childTest.equal(result.status, constants.symbols.extractor_results.NO_SHARED_DATA, "not found in blank")
|
|
|
|
}
|
2020-02-05 08:24:16 +00:00
|
|
|
{
|
|
|
|
const page = await fs.readFile("test/files/page-user-instagram.html", "utf8")
|
2020-04-13 15:46:23 +00:00
|
|
|
const result = extractSharedData(page)
|
|
|
|
childTest.equal(result.status, constants.symbols.extractor_results.SUCCESS, "extractor status success")
|
|
|
|
childTest.equal(result.value.entry_data.ProfilePage[0].graphql.user.username, "instagram", "can extract user page")
|
2020-02-05 08:24:16 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
const page = await fs.readFile("test/files/page-login.html", "utf8")
|
2020-04-13 15:46:23 +00:00
|
|
|
const result = extractSharedData(page)
|
|
|
|
childTest.equal(result.status, constants.symbols.extractor_results.SUCCESS, "extractor status success")
|
|
|
|
childTest.true(result.value.entry_data.LoginAndSignupPage[0], "can extract login page")
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const page = await fs.readFile("test/files/page-age-gated.html", "utf8")
|
|
|
|
const result = extractSharedData(page)
|
|
|
|
childTest.equal(result.status, constants.symbols.extractor_results.AGE_RESTRICTED, "extractor detects age restricted")
|
|
|
|
childTest.equal(result.value, 21, "correct age is extracted")
|
2020-02-05 08:24:16 +00:00
|
|
|
}
|
|
|
|
childTest.end()
|
|
|
|
})
|