All files / src/profiles/services facebook.ts

90.91% Statements 20/22
66.67% Branches 4/6
75% Functions 3/4
90.91% Lines 20/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x         4x       10x 10x   10x   10x 5x 5x 5x 5x 5x 5x 5x 5x 5x         10x       4x 4x 4x               1x  
import { Service, CheerioModuleType } from './service'
import { AccountProofInfo } from '../profileProofs'
 
class Facebook extends Service {
  getProofUrl(proof: AccountProofInfo) {
    return this.normalizeUrl(proof)
  }
 
  normalizeUrl(proof: AccountProofInfo) {
    let proofUrl = proof.proof_url.toLowerCase()
    const urlRegex = /(?:http[s]*:\/\/){0,1}(?:[a-zA-Z0-9-]+\.)+facebook\.com/
 
    proofUrl = super.prefixScheme(proofUrl)
 
    if (proofUrl.startsWith('https://facebook.com')) {
      let tokens = proofUrl.split('https://facebook.com')
      proofUrl = `https://www.facebook.com${tokens[1]}`
      tokens = proofUrl.split('https://www.facebook.com/')[1].split('/posts/')
      const postId = tokens[1]
      proofUrl = `https://www.facebook.com/${proof.identifier}/posts/${postId}`
    } else Eif (proofUrl.match(urlRegex)) {
      const tokens = proofUrl.split('facebook.com/')[1].split('/posts/')
      const postId = tokens[1]
      proofUrl = `https://www.facebook.com/${proof.identifier}/posts/${postId}`
    } else {
      throw new Error(`Proof url ${proof.proof_url} is not valid for service ${proof.service}`)
    }
 
    return proofUrl
  }
 
  getProofStatement(searchText: string, cheerio: CheerioModuleType) {
    const $ = cheerio.load(searchText)
    const statement = $('meta[name="description"]').attr('content')
    return (statement !== undefined) ? statement.trim() : ''
  }
 
  getBaseUrls(): string[] {
    return []
  }
}
 
export { Facebook }