Skip to content

Commit

Permalink
fix: undefined txid length (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
thalesog committed Aug 28, 2022
1 parent a8e50d3 commit 25b5624
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function createStaticPix(
},
};

if (params.txid.length > 25)
if (params.txid && params.txid.length > 25)
return {
error: true,
message: 'txid character limit exceeded (> 25)',
Expand Down
17 changes: 16 additions & 1 deletion tests/creator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import {

describe('EMV Code Creation', () => {
it('should be able to create a static pix from mandatory fields', () => {
const staticPixFn = createStaticPix({
merchantName: 'Thales Ogliari',
merchantCity: 'SAO MIGUEL DO OESTE'.substr(0, 15),
pixKey: 'thalesog@me.com',
infoAdicional: 'Pedido 123',
transactionAmount: 10,
});

expect(hasError(staticPixFn)).toBe(false);
if (hasError(staticPixFn)) return;

expect(staticPixFn.toBRCode()).toBe(STATIC_TEST_EMV);
});

it('should be able to create a static pix from mandatory fields and empty txid', () => {
const staticPixFn = createStaticPix({
merchantName: 'Thales Ogliari',
merchantCity: 'SAO MIGUEL DO OESTE'.substr(0, 15),
Expand All @@ -23,7 +38,7 @@ describe('EMV Code Creation', () => {
expect(staticPixFn.toBRCode()).toBe(STATIC_TEST_EMV);
});

it('should be able to create a static pix from mandatory fields with no value', () => {
it('should be able to create a static pix from mandatory fields with no amount defined', () => {
const staticPixFn = createStaticPix({
merchantName: 'Thales Ogliari',
merchantCity: 'SAO MIGUEL DO OESTE'.substr(0, 15),
Expand Down

0 comments on commit 25b5624

Please sign in to comment.