Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Sample POST Request
3. Change the base URL locally to `localhost` in the client-side app or when testing to make sure you are testing against the local api
4. Add your changes and validate they are working locally. Add routes as POST.
5. Open a PR to the main branch containing the value of the PR, any screenshots or video recordings to demonstrate the value and any tests that can be added (unit, feature, proof of manual testing)
6. A repo admin/moderator will review the PR along with other contributors. If there is feedback, please address it, commit any changes, and reach out for a rereview.
6. A repo admin/moderator will review the PR along with other contributors. If there is feedback, please address it, commit any changes, and reach out for a review.
7. Once approved a repo admin/moderator will merge the PR to `main`, deploying the service to production

### Dev Standards
Expand Down
40 changes: 39 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,44 @@ app.post('/api/isCountry', async (req, res) => {
const error_details = handleAxiosError(error);
return res.json({ error: error_details });
}
});
} );

/**
* POST /api/isAbaRouting
* @summary Validates whether a given string is a valid ABA routing number.
* @description This endpoint checks if the provided string is a valid ABA routing number using length, prefix validation, and checksum verification.
* @param {BasicRequest} request.body.required - Request body containing the routing number to validate.
* @return {BasicResponse} 200 - Success response indicating if the routing number is valid.
* @return {BadRequestResponse} 400 - Bad request response.
* @example request - test
* {
* "inputString": "011000015"
* }
* @example response - 200 - valid routing number
* {
* "result": true
* }
* @example response - 200 - invalid routing number
* {
* "result": false
* }
* @example response - 400 - missing parameter
* {
* "error": "input string is required as a parameter."
* }
*/
app.post( '/api/isAbaRouting', ( req, res ) =>
{
const { inputString } = req.body;

if ( !inputString )
{
return res.status( 400 ).json( { error: requiredParameterResponse } );
}

const result = ValidationFunctions.isAbaRouting( inputString );
res.json( { result } );
} );


module.exports = app;
113 changes: 113 additions & 0 deletions test/integration/isAbaRouting.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
const request = require( 'supertest' );
const app = require( '../../server.js' );

describe( 'POST /api/isAbaRouting', () =>
{
it( 'should return true for a valid ABA routing number', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( { inputString: '011000015' } ) // Valid routing number


expect( response.status ).toBe( 200 );
expect( response.body.result ).toBe( true );
} );

it( 'should return false for an invalid routing number (checksum fails)', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( { inputString: '123456789' } ) // Fails checksum validation


expect( response.status ).toBe( 200 );
expect( response.body.result ).toBe( false );
} );

it( 'should return false for a routing number with invalid length (too short)', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( { inputString: '12345678' } ) // Only 8 digits


expect( response.status ).toBe( 200 );
expect( response.body.result ).toBe( false );
} );

it( 'should return false for a routing number with invalid length (too long)', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( { inputString: '1234567890' } ) // 10 digits instead of 9


expect( response.status ).toBe( 200 );
expect( response.body.result ).toBe( false );
} );

it( 'should return false for a routing number with non-numeric characters', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( { inputString: '12345A789' } ) // Contains a letter


expect( response.status ).toBe( 200 );
expect( response.body.result ).toBe( false );
} );

it( 'should return 400 if inputString is missing in the request body', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( {} ) // No input string

expect( response.status ).toBe( 400 );
expect( response.body.error ).toBe( 'Input string required as a parameter.' );
} );

it( 'should return false for an empty string as inputString', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( { inputString: '' } ) // Empty input

expect( response.status ).toBe( 400 );
expect( response.body.error ).toBe( 'Input string required as a parameter.' );
} );

it( 'should return false for a routing number with an invalid prefix', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( { inputString: '991234567' } ) // Starts with invalid prefix (99)


expect( response.status ).toBe( 200 );
expect( response.body.result ).toBe( false );
} );

it( 'should return false for a routing number starting with 00', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( { inputString: '001234567' } ) // Starts with 00


expect( response.status ).toBe( 200 );
expect( response.body.result ).toBe( false );
} );

it( 'should return true for known valid routing numbers', async () =>
{
const response = await request( app )
.post( '/api/isAbaRouting' )
.send( { inputString: '021000021' } ) // Chase Bank


expect( response.status ).toBe( 200 );
expect( response.body.result ).toBe( true );
} );
} );
83 changes: 83 additions & 0 deletions test/unit/isAbaRouting.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const { isAbaRouting } = require( '../../validationFunctions' );

describe( 'isAbaRouting', () =>
{
it( 'should return true for a valid ABA routing number', () =>
{
expect( isAbaRouting( '011000015' ) ).toBe( true ); // Valid ABA routing number
} );

it( 'should return false for an invalid routing number with incorrect checksum', () =>
{
expect( isAbaRouting( '123456789' ) ).toBe( false ); // Fails checksum validation
} );

it( 'should return false for a routing number that is too short', () =>
{
expect( isAbaRouting( '12345678' ) ).toBe( false ); // Only 8 digits
} );

it( 'should return false for a routing number that is too long', () =>
{
expect( isAbaRouting( '1234567890' ) ).toBe( false ); // 10 digits instead of 9
} );

it( 'should return false for a routing number containing non-numeric characters', () =>
{
expect( isAbaRouting( '12345A789' ) ).toBe( false ); // Contains 'A'
} );

it( 'should return false for an empty string', () =>
{
expect( isAbaRouting( '' ) ).toBe( false ); // Empty input
} );

it( 'should return false for null input', () =>
{
expect( isAbaRouting( null ) ).toBe( false ); // Null value
} );

it( 'should return false for undefined input', () =>
{
expect( isAbaRouting( undefined ) ).toBe( false ); // Undefined value
} );

it( 'should return false for a routing number with an invalid prefix', () =>
{
expect( isAbaRouting( '991234567' ) ).toBe( false ); // Starts with an invalid prefix (99)
} );

it( 'should return false for a routing number starting with 00', () =>
{
expect( isAbaRouting( '001234567' ) ).toBe( false ); // 00 is not allowed
} );

it( 'should return true for valid routing numbers from different banks', () =>
{
expect( isAbaRouting( '021000021' ) ).toBe( true ); // Chase Bank
expect( isAbaRouting( '322271627' ) ).toBe( true ); // Wells Fargo
expect( isAbaRouting( '121000358' ) ).toBe( true ); // Bank of America
} );

it( 'should return true for more valid test cases', () =>
{
expect( [
'322070381',
'011103093',
'263170175',
'124303065',
].every(isAbaRouting) ).toBe( true ); // All valid ABA routing numbers
} )

it( 'should return false for more invalid test cases', () =>
{
expect( [
'426317017',
'789456124',
'603558459',
'qwerty',
'12430306',
'382070381',
].every(isAbaRouting) ).toBe( false ); // All invalid ABA routing numbers
})
} );
Loading