Skip to content

Commit

Permalink
Release v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Menighin committed Aug 14, 2021
1 parent c51ee9e commit 5897eb0
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 101 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Crawler para ler dados do Canal Eletrônico do Investidor

## __Importante__
## __Importante__ (Versão sem captcha)
Para versão antiga do CEI que não possui captcha obrigatório (por enquanto), utilize o [cei-crawler v2](https://github.com/Menighin/cei-crawler/tree/v2)

## Descrição
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cei-crawler",
"version": "2.5.0",
"version": "3.0.0",
"description": "Crawler para pegar dados do Canal Eletronico do Investidor",
"main": "src/app.js",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/CeiCrawlerError.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore next */
class CeiCrawlerError extends Error {
constructor(type, message, status = null) {
super(message);
Expand All @@ -7,6 +8,7 @@ class CeiCrawlerError extends Error {
}
}

/* istanbul ignore next */
const CeiErrorTypes = Object.freeze({
INVALID_LOGIN_STRATEGY: 'INVALID_LOGIN_STRATEGY',
BAD_REQUEST: 'BAD_REQUEST',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/CeiLoginService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CeiLoginService {
}
}

/* istanbul ignore next */
async _getTokenByUserResolve() {
const browser = await puppeteer.launch({
headless: false,
Expand Down Expand Up @@ -89,6 +90,7 @@ class CeiLoginService {
* @param {puppeteer.Browser} browser Puppeteer browser running
* @returns {puppeteer.Page} The main page to keep crawling
*/
/* istanbul ignore next */
async _getMainPage(browser) {
while (true) {
for (const p of (await browser.pages())) {
Expand Down
197 changes: 98 additions & 99 deletions test/app.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const test = require('ava')
const CeiCrawler = require('../src/app')
const CeiUtils = require('./../src/lib/CeiUtils');
const { CeiErrorTypes } = require('../src/lib/CeiCrawlerError');

const dotenv = require('dotenv');

Expand All @@ -24,106 +23,106 @@ test.before(t => {
});
});

// test.serial('consolidated-values', async t => {
// const consolidatedValues= await t.context.ceiCrawler.getConsolidatedValues();
// t.true(consolidatedValues.total > 0);
// });

// test.serial('get-position', async t => {
// const positions = await t.context.ceiCrawler.getPosition();
// t.true(positions.paginaAtual === 1);

// const position = {
// category: positions.itens[0].categoriaProduto,
// type: positions.itens[0].tipoProduto,
// id: positions.itens[0].posicoes[0].id
// };
// const positionDetail = await t.context.ceiCrawler.getPositionDetail(position.id, position.category, position.type);
// t.true(positionDetail.quantidade > 0);
// });

// test.serial('account-statement', async t => {
// const statement = await t.context.ceiCrawler.getAccountStatement();
// t.true(statement.paginaAtual === 1);
// });

// test.serial('ipo-and-ipo-detail', async t => {
// const ipo = await t.context.ceiCrawler.getIPOs();
// t.true(ipo.paginaAtual === 1);
test.serial('consolidated-values', async t => {
const consolidatedValues= await t.context.ceiCrawler.getConsolidatedValues();
t.true(consolidatedValues.total > 0);
});

test.serial('get-position', async t => {
const positions = await t.context.ceiCrawler.getPosition();
t.true(positions.paginaAtual === 1);

const position = {
category: positions.itens[0].categoriaProduto,
type: positions.itens[0].tipoProduto,
id: positions.itens[0].posicoes[0].id
};
const positionDetail = await t.context.ceiCrawler.getPositionDetail(position.id, position.category, position.type);
t.true(positionDetail.quantidade > 0);
});

test.serial('account-statement', async t => {
const statement = await t.context.ceiCrawler.getAccountStatement();
t.true(statement.paginaAtual === 1);
});

test.serial('ipo-and-ipo-detail', async t => {
const ipo = await t.context.ceiCrawler.getIPOs();
t.true(ipo.paginaAtual === 1);

// const id = ipo.itens[0].ofertasPublicas[0].id;
// const ipoDetail = await t.context.ceiCrawler.getIPODetail(id);
// t.true(ipoDetail !== undefined);
// });

// test.serial('get-stock-transactions', async t => {
// const stockTransactions = await t.context.ceiCrawler.getStockTransactions();
// t.true(stockTransactions.paginaAtual === 1);
// });

// test.serial('provisioned-events-detail', async t => {
// const provisionedEvents = await t.context.ceiCrawler.getProvisionedEvents();
// t.true(provisionedEvents.paginaAtual === 1);
const id = ipo.itens[0].ofertasPublicas[0].id;
const ipoDetail = await t.context.ceiCrawler.getIPODetail(id);
t.true(ipoDetail !== undefined);
});

test.serial('get-stock-transactions', async t => {
const stockTransactions = await t.context.ceiCrawler.getStockTransactions();
t.true(stockTransactions.paginaAtual === 1);
});

test.serial('provisioned-events-detail', async t => {
const provisionedEvents = await t.context.ceiCrawler.getProvisionedEvents();
t.true(provisionedEvents.paginaAtual === 1);

// const id = provisionedEvents.itens[0].id;
// const eventDetail = await t.context.ceiCrawler.getProvisionedEventDetail(id);
// t.true(eventDetail !== undefined);
// });

// test.serial('invalid-strategy', async t => {
// await t.throwsAsync(async () => {
// const crawler = new CeiCrawler('', '', {
// loginOptions: {
// strategy: 'invalid-strategy'
// }
// });
// await crawler.login();
// });
// });

// test.serial('invalid-browser-path', async t => {
// await t.throwsAsync(async () => {
// const crawler = new CeiCrawler('', '', {
// loginOptions: {
// strategy: 'user-resolve',
// browserPath: 'C:/invalid/path'
// }
// });
// await crawler.login();
// });
// });

// test.serial('invalid-token', async t => {
// await t.throwsAsync(async () => {
// const crawler = new CeiCrawler('', '', {
// loginOptions: {
// strategy: 'raw-token',
// },
// auth: {
// "cache-guid": "invalid",
// "token": "invalid"
// }
// });
// await crawler.login();
// });
// });

// test.serial('invalid-position-call', async t => {
// await t.throwsAsync(async () => {
// const crawler = new CeiCrawler('', '', {
// loginOptions: {
// strategy: 'raw-token',
// },
// auth: {
// "cache-guid": "invalid",
// "token": "invalid"
// },
// debug: true
// });
// crawler._isLogged = true;
// await crawler.getPositionDetail('id-91', 'cat', 'type');
// });
// });
const id = provisionedEvents.itens[0].id;
const eventDetail = await t.context.ceiCrawler.getProvisionedEventDetail(id);
t.true(eventDetail !== undefined);
});

test.serial('invalid-strategy', async t => {
await t.throwsAsync(async () => {
const crawler = new CeiCrawler('', '', {
loginOptions: {
strategy: 'invalid-strategy'
}
});
await crawler.login();
});
});

test.serial('invalid-browser-path', async t => {
await t.throwsAsync(async () => {
const crawler = new CeiCrawler('', '', {
loginOptions: {
strategy: 'user-resolve',
browserPath: 'C:/invalid/path'
}
});
await crawler.login();
});
});

test.serial('invalid-token', async t => {
await t.throwsAsync(async () => {
const crawler = new CeiCrawler('', '', {
loginOptions: {
strategy: 'raw-token',
},
auth: {
"cache-guid": "invalid",
"token": "invalid"
}
});
await crawler.login();
});
});

test.serial('invalid-position-call', async t => {
await t.throwsAsync(async () => {
const crawler = new CeiCrawler('', '', {
loginOptions: {
strategy: 'raw-token',
},
auth: {
"cache-guid": "invalid",
"token": "invalid"
},
debug: true
});
crawler._isLogged = true;
await crawler.getPositionDetail('id-91', 'cat', 'type');
});
});

test.serial('cei-utils', async t => {
let n = 0;
Expand Down

0 comments on commit 5897eb0

Please sign in to comment.