Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Dec 4, 2023
1 parent 22ddde2 commit f678014
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion formats/cpa005.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function validateTransactions(eftTransactions) {
warningCount += 1;
}
if (transaction.segments.length > 6) {
debug('Transaction record has more than 6 segments, we be split into multiple transactions.');
debug('Transaction record has more than 6 segments, will be split into multiple transactions.');
warningCount += 1;
}
if (!['C', 'D'].includes(transaction.recordType)) {
Expand Down
6 changes: 2 additions & 4 deletions formats/cpa005.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@ function validateTransactions(eftTransactions: EFTTransaction[]): number {

if (transaction.segments.length > 6) {
debug(
'Transaction record has more than 6 segments, we be split into multiple transactions.'
'Transaction record has more than 6 segments, will be split into multiple transactions.'
)
warningCount += 1
}

if (!['C', 'D'].includes(transaction.recordType)) {
throw new Error(
`Unknown recordType: ${transaction.recordType}`
)
throw new Error(`Unknown recordType: ${transaction.recordType}`)
}

for (const segment of transaction.segments) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,34 @@ describe('eft-generator - CPA-005', () => {
assert.ok(output.length > 0);
assert.strictEqual(output.charAt(0), 'A');
});
it('Throws error when originatorId length is too long.', () => {
const eftGenerator = new EFTGenerator({
originatorId: '12345678901234567890',
originatorLongName: '',
fileCreationNumber: '0001'
});
try {
eftGenerator.toCPA005();
assert.fail();
}
catch {
assert.ok(true);
}
});
it('Throws error when fileCreationNumber is invalid.', () => {
const eftGenerator = new EFTGenerator({
originatorId: '1',
originatorLongName: '',
fileCreationNumber: 'abcdefg'
});
try {
eftGenerator.toCPA005();
assert.fail();
}
catch {
assert.ok(true);
}
});
it('Warns on missing originatorShortName', () => {
const eftGenerator = new EFTGenerator({
originatorId: '01',
Expand Down
30 changes: 30 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,36 @@ describe('eft-generator - CPA-005', () => {
assert.strictEqual(output.charAt(0), 'A')
})

it('Throws error when originatorId length is too long.', () => {
const eftGenerator = new EFTGenerator({
originatorId: '12345678901234567890',
originatorLongName: '',
fileCreationNumber: '0001'
})

try {
eftGenerator.toCPA005()
assert.fail()
} catch {
assert.ok(true)
}
})

it('Throws error when fileCreationNumber is invalid.', () => {
const eftGenerator = new EFTGenerator({
originatorId: '1',
originatorLongName: '',
fileCreationNumber: 'abcdefg'
})

try {
eftGenerator.toCPA005()
assert.fail()
} catch {
assert.ok(true)
}
})

it('Warns on missing originatorShortName', () => {
const eftGenerator = new EFTGenerator({
originatorId: '01',
Expand Down

0 comments on commit f678014

Please sign in to comment.