Skip to content

Commit

Permalink
#21
Browse files Browse the repository at this point in the history
  • Loading branch information
mariohmol committed Nov 14, 2019
1 parent b194fa7 commit 315277f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 47 deletions.
100 changes: 60 additions & 40 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,75 @@ export const fakerBr = {
return cns.substr(0, cns.length - 2) + digito;
},
contabanco: makeGeneric(MASKS['contabanco']),
cpf: () => {
let cpf = makeGeneric(MASKS['cpf'])();
let restos = create_cpf(cpf);
cpf = cpf.substr(0, cpf.length - 2) + restos[0] + restos[1];
restos = create_cpf(cpf);
return cpf.substr(0, cpf.length - 2) + restos[0] + restos[1];
},
cpfcnpj: makeGeneric(MASKS['cpfcnpj']),
cartaocredito: makeGeneric(MASKS['cartaocredito']),

currency: () => {
const x = Math.random() * 10000;
return x.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' });
},
currencyNumber: () => {
const x = Math.random() * 10000;
return parseFloat(x.toFixed(2));
},
date: (config: any = {}) => {
let date = new Date();
if (config.dias) {
date.setDate(date.getDate() + config.dias);
}
if (config.meses) {
date.setMonth(date.getMonth() + config.meses);
}
if (config.idadeMin && config.idadeMax) {
config.anos = -randomNumber(config.idadeMin, config.idadeMax);
}
if (config.anos) {
date.setFullYear(date.getFullYear() + config.anos);
}
return `${date.getDate()}/${date.getMonth()}/${date.getFullYear()}`;
},
ect: () => {
const ect = makeGeneric(MASKS['ect'])();
const dv = create_ect(ect.substr(0, ect.length - 1));
return ect.substr(0, ect.length - 1) + dv;
},
email: (options: any = {}) => {
let name = randArray(NOMES_MASCULINOS)
if (options.name) {
name = options.name.match(/\w/g).join('');
}
name = name.toLowerCase();
const ect = makeGeneric(MASKS['ect'])();
const dv = create_ect(ect.substr(0, ect.length - 1));
return ect.substr(0, ect.length - 1) + dv;
},
empresa: () => {
const faker = this.fakerBr;
const cnpj = faker.cnpj();
const telefone = faker.telefone();
const celular = faker.celular();
const endereco = faker.endereco();
const inscricaoestadual = faker.inscricaoestadual(endereco.estadoSigla);
const dataAbertura = fakerBr.date({
idadeMin: 4,
idadeMax: 20
});


// const dataAbertura = faker.celular();
// const site = faker.site();
// const email = faker.email();

return {
name: randArray(EMPRESAS_TIPOS) + ' ' + randArray(EMPRESAS_NOMES), // TODO
inscricaoestadual,
cnpj, telefone, celular,
endereco
endereco, dataAbertura
}
},
endereco: () => {
Expand All @@ -151,41 +202,6 @@ export const fakerBr = {
estadoSigla: estado.uf
}
},
cpf: () => {
let cpf = makeGeneric(MASKS['cpf'])();
let restos = create_cpf(cpf);
cpf = cpf.substr(0, cpf.length - 2) + restos[0] + restos[1];
restos = create_cpf(cpf);
return cpf.substr(0, cpf.length - 2) + restos[0] + restos[1];
},
cpfcnpj: makeGeneric(MASKS['cpfcnpj']),
cartaocredito: makeGeneric(MASKS['cartaocredito']),

currency: () => {
const x = Math.random() * 10000;
return x.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' });
},
currencyNumber: () => {
const x = Math.random() * 10000;
return parseFloat(x.toFixed(2));
},

date: makeGeneric(MASKS['date']),
ect: () => {
const ect = makeGeneric(MASKS['ect'])();
const dv = create_ect(ect.substr(0, ect.length - 1));
return ect.substr(0, ect.length - 1) + dv;
},
email: (options: any = {}) => {
let name = randArray(NOMES_MASCULINOS)
if (options.name) {
name = options.name.match(/\w/g).join('');
}
name = name.toLowerCase();
const ect = makeGeneric(MASKS['ect'])();
const dv = create_ect(ect.substr(0, ect.length - 1));
return ect.substr(0, ect.length - 1) + dv;
},
inscricaoestadual: estado => {
estado = estado.toLowerCase();
let val = makeGeneric(MASKS['inscricaoestadual'][estado])();
Expand Down Expand Up @@ -220,7 +236,10 @@ export const fakerBr = {
const telefone = faker.telefone();
const celular = faker.celular();

// const dataNascimento = faker.celular();
const dataNascimento = fakerBr.date({
idadeMin: 18,
idadeMax: 40
});
// const site = faker.site();
// const email = faker.email();
// const senha = faker.password();
Expand All @@ -232,7 +251,8 @@ export const fakerBr = {
mae: 'TEST', // TODO
pai: 'TEST', // TODO
rg,
cpf, telefone, celular
cpf, telefone, celular,
dataNascimento
}

},
Expand Down
17 changes: 10 additions & 7 deletions test/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ describe('Faker test', () => {
expect(validateBr.contabanco(contabanco)).to.be.true;
});


it('CPF', () => {
const cpf = fakerBr.cpf();
expect(fakerBr.cpf()).to.exist;
Expand All @@ -72,21 +71,25 @@ describe('Faker test', () => {
expect(validateBr.cpfcnpj(cpfcnpj)).to.be.true;
});


it('Currency', () => {
// expect(fakerBr.currency()).to.exist;
// expect(fakerBr.currency()).to.exist;
// const currency = fakerBr.currency();
// expect(validateBr.currency(currency)).to.be.true;
const currencyNumber = fakerBr.currencyNumber();
expect(validateBr.currency(currencyNumber)).to.be.true;
});

it('date', () => {
const date = fakerBr.date();
let date = fakerBr.date();
expect(validateBr.date(date)).to.be.true;
date = fakerBr.date({
idadeMin: 18,
idadeMax: 40
});
expect(validateBr.date(date)).to.be.true;
});


it('ECT', () => {
const ect = fakerBr.ect();
expect(validateBr.ect(ect)).to.be.true;
Expand Down Expand Up @@ -114,7 +117,7 @@ describe('Faker test', () => {
expect(endereco.estado).to.exist;
expect(endereco.estadoSigla).to.exist;
});


it('inscricaoestadual - TODO', () => {
// expect(fakerBr.inscricaoestadual()).to.exist;
Expand Down Expand Up @@ -168,7 +171,7 @@ describe('Faker test', () => {
expect(validateBr.telefone(telefone)).to.be.true;
});
// it('Time', () => {
// expect(fakerBr.time()).to.exist;
// expect(fakerBr.time()).to.exist;
// const time = fakerBr.time();
// expect(validateBr.time(time)).to.be.true;
// });
Expand Down

0 comments on commit 315277f

Please sign in to comment.