Node.js · TypeScript
Gerador de CNH em Node.js
SDK fakeforge-br gera CNH mod-11 DENATRAN. TypeScript types. Snippets pra Jest, NestJS, Express.
npm install fakeforge-br
import { FakeForge } from "fakeforge-br"
const cnhs = await new FakeForge().cnh(100)SDK + preset motorista
import { FakeForge } from "fakeforge-br"
const ff = new FakeForge()
// 100 CNHs válidas
const cnhs = await ff.cnh(100)
// Combine com customer pra motorista completo
const [motorista] = await Promise.all([
ff.preset("customer", 1),
ff.cnh(1),
]).then(([[c], [cnh]]) => [{ ...c, cnh }])Uso em Jest — app de motorista (Uber/99)
// tests/motorista.test.ts
import { FakeForge } from "fakeforge-br"
import { MotoristaService } from "../src/motorista.service"
const ff = new FakeForge()
describe("MotoristaService.cadastrar", () => {
let motoristasFake: Array<{ cpf: string; nome: string; cnh: string }>
beforeAll(async () => {
const [customers, cnhs] = await Promise.all([
ff.preset("customer", 20),
ff.cnh(20),
])
motoristasFake = customers.map((c, i) => ({
cpf: c.cpf, nome: c.nome, cnh: cnhs[i]
}))
})
test.each([0, 1, 2, 3, 4])("cadastra motorista #%i", async (i) => {
const service = new MotoristaService()
const result = await service.cadastrar(motoristasFake[i])
expect(result.aprovado).toBe(true)
})
})Uso em NestJS (seed)
// motorista.seed.command.ts
@Command({ name: "seed:motoristas" })
export class MotoristaSeedCommand extends CommandRunner {
async run() {
const ff = new FakeForge()
const [customers, cnhs] = await Promise.all([
ff.preset("customer", 1000),
ff.cnh(1000),
])
const dados = customers.map((c, i) => ({
cpf: c.cpf,
nome: c.nome,
cnh: cnhs[i],
categoria: ["A", "B", "AB", "C", "D"][i % 5],
}))
await this.motoristas.bulkCreate(dados)
}
}