all files / src/ index.js

100% Statements 10/10
100% Branches 4/4
100% Functions 0/0
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                             
'use strict';
 
const cheerio = require('cheerio');
const rp = require('request-promise');
 
module.exports = data => {
  const qs = {
    RUN: data.rut,
    type: data.type ? data.type.toUpperCase() : 'CEDULA',
    serial: data.serial
  };
  const options = {
    url: 'https://portal.sidiv.registrocivil.cl/usuarios-portal/pages/DocumentRequestStatus.xhtml',
    qs: qs,
    rejectUnauthorized: false,
    transform: cheerio.load
  };
  return rp(options).then($ => {
    const status = $('#tableResult .setWidthOfSecondColumn').text();
    if (status === '') throw new Error('Not found');
    return status;
  });
};