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
18 changes: 17 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- "main"

jobs:
unit-tests:
python-tests:
runs-on: ubuntu-latest
permissions:
# Gives the action the necessary permissions for publishing new
Expand Down Expand Up @@ -43,3 +43,19 @@ jobs:
name: python-coverage-comment-action
# If you use a different name, update COMMENT_FILENAME accordingly
path: python-coverage-comment-action.txt

node-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
- name: Install dependencies
run: yarn install
- name: Run node unit tests
run: yarn test
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@
"node": ">=20"
},
"scripts": {
"build": "node src/node/build.js ; vite build"
"build": "node src/node/build.js ; vite build",
"test": "vitest"
},
"dependencies": {
"typescript": "^5.7.2",
"yaml": "^2.6.1"
"typescript": "^5.9.3",
"yaml": "^2.8.1"
},
"devDependencies": {
"@types/node": "^20.10.1",
"vite": "3.2.10",
"vite-plugin-dts": "^2.2.0",
"vite-tsconfig-paths": "3.5.2"
"@types/node": "^24.10.0",
"@vitest/ui": "^4.0.7",
"vite": "^7.1.12",
"vite-plugin-dts": "^4.5.4",
"vite-tsconfig-paths": "5.1.4",
"vitest": "^4.0.7"
},
"packageManager": "yarn@4.2.1"
}
108 changes: 108 additions & 0 deletions src/node/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { describe, it, expect } from 'vitest';
import { RegtechRegex, RegtechRegexNames } from '../index';

describe('RegtechRegex', () => {
it('should have all expected regex configurations', () => {
const expectedConfigs: RegtechRegexNames[] = [
'email',
'lei',
'rssd_id',
'simple_us_phone_number',
'tin',
];

expectedConfigs.forEach((configName) => {
expect(RegtechRegex).toHaveProperty(configName);
expect(RegtechRegex[configName]).toHaveProperty('regex');
expect(RegtechRegex[configName]).toHaveProperty('description');
expect(RegtechRegex[configName]).toHaveProperty('error_text');
});
});

describe('email regex', () => {
it('should match valid email addresses', () => {
const goodEmail = 'Jason.Adam@cfpb.gov';
const regex = new RegExp(RegtechRegex.email.regex);

expect(regex.test(goodEmail)).toBe(true);
});

it('should not match invalid email addresses', () => {
const badEmail = 'something@bad_domain';
const regex = new RegExp(RegtechRegex.email.regex);

expect(regex.test(badEmail)).toBe(false);
});
});

describe('lei regex', () => {
it('should match valid LEI codes', () => {
const goodLei = '1234567890ABCDEFGH00';
const regex = new RegExp(RegtechRegex.lei.regex);

expect(regex.test(goodLei)).toBe(true);
});

it('should not match LEI codes that are too short', () => {
const badLei = '123';
const regex = new RegExp(RegtechRegex.lei.regex);

expect(regex.test(badLei)).toBe(false);
});

it('should not match LEI codes that are too long', () => {
const anotherBadLei = '1234567890ABCDEFGHIJ';
const regex = new RegExp(RegtechRegex.lei.regex);

expect(regex.test(anotherBadLei)).toBe(false);
});
});

describe('rssd_id regex', () => {
it('should match valid RSSD IDs', () => {
const goodRssd = '1234';
const regex = new RegExp(RegtechRegex.rssd_id.regex);

expect(regex.test(goodRssd)).toBe(true);
});

it('should not match invalid RSSD IDs', () => {
const badRssd = 'ABC';
const regex = new RegExp(RegtechRegex.rssd_id.regex);

expect(regex.test(badRssd)).toBe(false);
});
});

describe('simple_us_phone_number regex', () => {
it('should match valid phone numbers', () => {
const goodPhone = '555-555-5555';
const regex = new RegExp(RegtechRegex.simple_us_phone_number.regex);

expect(regex.test(goodPhone)).toBe(true);
});

it('should not match invalid phone numbers', () => {
const badPhone = '12-34-56-78-90';
const regex = new RegExp(RegtechRegex.simple_us_phone_number.regex);

expect(regex.test(badPhone)).toBe(false);
});
});

describe('tin regex', () => {
it('should match valid TIN numbers', () => {
const goodTin = '98-7654321';
const regex = new RegExp(RegtechRegex.tin.regex);

expect(regex.test(goodTin)).toBe(true);
});

it('should not match invalid TIN numbers', () => {
const badTin = '123456789';
const regex = new RegExp(RegtechRegex.tin.regex);

expect(regex.test(badTin)).toBe(false);
});
});
});
19 changes: 6 additions & 13 deletions src/node/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
export type RegtechRegexNames = "email" | "lei" | "rssd_id" | "simple_us_phone_number" | "tin";
export type RegtechRegexConfigs = Record<RegtechRegexNames, RegtechRegexConfig>;
export type RegtechRegexConfig = {
description: string;
error_text: string;
regex: string;
examples?: string[];
link?: string;
references?: string[];
};
export declare const RegtechRegex: RegtechRegexConfigs;
declare const _default: RegtechRegexConfigs;
export default _default;
export * from './src/node/index'
export {}
import RegtechRegex from './src/node/index'
export default RegtechRegex
export * from './src/node/index'
export {}
2 changes: 1 addition & 1 deletion src/node/dist/regtech-regex.cjs.js

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

61 changes: 5 additions & 56 deletions src/node/dist/regtech-regex.es.js

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

Loading
Loading