# All files / src/profiles/services hackerNews.ts

91.67% Statements 22/24
62.5% Branches 5/8
83.33% Functions 5/6
91.3% Lines 21/23

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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    631x

    2x

    2x

    2x

    2x

    2x
    2x
    2x

    2x
    2x
    2x

    2x
    2x
    4x

    4x
    4x
    16x

    16x
    2x

    2x

    1x
     import { Service, CheerioModuleType } from './service'
    import { AccountProofInfo } from '../profileProofs'

    class HackerNews extends Service {
      getBaseUrls() {
        const baseUrls = [
          'https://news.ycombinator.com/user?id=',
          'http://news.ycombinator.com/user?id=',
          'news.ycombinator.com/user?id='
        ]
        return baseUrls
      }

      getProofUrl(proof: AccountProofInfo) {
        const baseUrls = this.getBaseUrls()

        const proofUrl = super.prefixScheme(proof.proof_url)

        for (let i = 0; i < baseUrls.length; i++) {
          Eif (proofUrl === `${baseUrls[i]}${proof.identifier}`) {
            return proofUrl
          }
        }
        throw new Error(`Proof url ${proof.proof_url} is not valid for service ${proof.service}`)
      }

      normalizeUrl(_proof: AccountProofInfo) {
        return ''
      }

      getProofStatement(searchText: string, cheerio: CheerioModuleType) {
        const $ = cheerio.load(searchText)
        const tables = $('#hnmain').children().find('table')
        let statement = ''

        Eif (tables.length > 0) {
          tables.each((tableIndex, table) => {
            const rows = $(table).find('tr')

            Eif (rows.length > 0) {
              rows.each((idx, row) => {
                const heading = $(row).find('td')
                  .first()
                  .text()
                  .trim()

                if (heading === 'about:') {
                  statement = $(row).find('td')
                    .last()
                    .text()
                    .trim()
                }
              })
            }
          })
        }

        return statement
      }
    }

    export { HackerNews }