-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from jesieldotdev/master
Feature: RG GENERATE AND VALIDATE
- Loading branch information
Showing
8 changed files
with
162 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { RG } from '../lib/index'; | ||
|
||
interface IRG { | ||
rg: string; | ||
isValid: boolean; | ||
} | ||
|
||
const rgMock: IRG = { | ||
rg: '30.737.817-2', | ||
isValid: true, | ||
}; | ||
|
||
describe('RG lib', () => { | ||
it('should create an instance', () => { | ||
expect(new RG()).toBeTruthy(); | ||
}); | ||
|
||
it('should be valid RG', async () => { | ||
const RGIsValid = await RG.validate({ rg: rgMock.rg }); | ||
|
||
expect(RGIsValid.isValid).toBe(rgMock.isValid); | ||
}); | ||
|
||
it('should generate a RG with dots', async () => { | ||
const { rg } = await RG.generate({ isWithDots: true }); | ||
|
||
expect(rg).toHaveLength(12); | ||
}); | ||
|
||
it('should generate a RG without dots', async () => { | ||
const { rg } = await RG.generate({ isWithDots: false }); | ||
|
||
expect(rg).toHaveLength(9); | ||
|
||
|
||
}); | ||
|
||
it('should generate a RG with state', async () => { | ||
const { rg } = await RG.generate({ stateCode: 'BA' }); | ||
|
||
expect(rg).toHaveLength(9); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { Certificates } from './modules/Certificates'; | ||
import { CPF } from './modules/CPF'; | ||
import { CNH } from './modules/CNH'; | ||
import { RG } from './modules/RG'; | ||
|
||
export { Certificates, CPF, CNH }; | ||
export { Certificates, CPF, CNH, RG }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface IRGValid { | ||
isValid: boolean; | ||
} | ||
|
||
export interface IRGGenerated { | ||
rg: string; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { RequestUtil } from '../../utils/RequestUtil'; | ||
import { IRGGenerated } from '../../interfaces/IRG'; | ||
|
||
export class GenerateRG { | ||
requestUtil = new RequestUtil(); | ||
async execute({ | ||
isWithDots, | ||
stateCode, | ||
}: { | ||
isWithDots?: boolean; | ||
stateCode?: string; | ||
}): Promise<IRGGenerated> { | ||
const { data: rg }: { data: string } = await this.requestUtil.post({ | ||
path: '/ferramentas_online.php', | ||
json: { | ||
acao: 'gerar_rg', | ||
pontuacao: isWithDots ? 'S' : 'N', | ||
rg_estado: stateCode || '', | ||
}, | ||
}); | ||
|
||
return { | ||
rg, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { RequestUtil } from '../../utils/RequestUtil'; | ||
import { IRGValid } from '../../interfaces/IRG'; | ||
|
||
export class ValidateRG { | ||
requestUtil = new RequestUtil(); | ||
async execute({ rg }: { rg: string }): Promise<IRGValid> { | ||
const { data }: { data: string } = await this.requestUtil.post({ | ||
path: '/ferramentas_online.php', | ||
json: { | ||
acao: 'validar_rg', | ||
txt_rg: rg, | ||
}, | ||
}); | ||
const isValid = data.toLowerCase().includes('verdadeiro'); | ||
|
||
return { | ||
isValid, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ValidateRG } from './ValidateRG'; | ||
import { GenerateRG } from './GenerateRG'; | ||
|
||
import { IRGValid } from '../../interfaces/IRG'; | ||
import { IRGGenerated } from '../../interfaces/IRG'; | ||
|
||
export class RG { | ||
public static async validate({ rg }: { rg: string }): Promise<IRGValid> { | ||
const validateRG = new ValidateRG(); | ||
return await validateRG.execute({ rg }); | ||
} | ||
public static async generate(options?: { | ||
isWithDots?: boolean; | ||
stateCode?: string; | ||
}): Promise<IRGGenerated> { | ||
const generateRG = new GenerateRG(); | ||
return await generateRG.execute(options ? options : {}); | ||
} | ||
} |