@@ -47,166 +47,156 @@ describe("redactPii", () => {
4747 ) ;
4848 } ) ;
4949
50-
51- it ( "documents with less than 7 digit number notredacted" , ( ) => {
52- // as the Minimum digit count for something to qualify as a phone number is 7
53- expect ( redactPhones ( "Order 123456" ) ) . toBe (
54- "Order 123456" ,
55- ) ;
56- } ) ;
57-
58- it ( "doesnt redacts a long tracking number as a phone number" , ( ) => {
59- expect (
60- redactPhones ( "Tracking number: 9400111899223856928490" ) ,
61- ) . toBe ( "Tracking number: 9400111899223856928490" ) ;
50+ it ( "documents with less than 7 digit number notredacted" , ( ) => {
51+ // as the Minimum digit count for something to qualify as a phone number is 7
52+ expect ( redactPhones ( "Order 123456" ) ) . toBe ( "Order 123456" ) ;
6253 } ) ;
6354
64- // over-redacts scenarios
55+ it ( "doesnt redacts a long tracking number as a phone number" , ( ) => {
56+ expect ( redactPhones ( "Tracking number: 9400111899223856928490" ) ) . toBe (
57+ "Tracking number: 9400111899223856928490" ,
58+ ) ;
59+ } ) ;
6560
66- it ( "over-redacts emails with invalid local-part separators" , ( ) => {
67- expect (
68- redactEmails (
69- "Contact alice.@example.com and alice..smith@example.com today" ,
70- ) ,
71- ) . toBe ( "Contact [EMAIL REDACTED] and [EMAIL REDACTED] today" ) ;
72- } ) ;
61+ // over-redacts scenarios
7362
74- it ( "over-redacts emails with invalid domain separators" , ( ) => {
75- expect (
76- redactEmails (
77- "Contact bob@-domain.org and bob@domain-.org today" ,
78- ) ,
79- ) . toBe ( "Contact [EMAIL REDACTED] and [EMAIL REDACTED] today" ) ;
80- } ) ;
63+ it ( "over-redacts emails with invalid local-part separators" , ( ) => {
64+ expect (
65+ redactEmails (
66+ "Contact alice.@example.com and alice..smith@example.com today" ,
67+ ) ,
68+ ) . toBe ( "Contact [EMAIL REDACTED] and [EMAIL REDACTED] today" ) ;
69+ } ) ;
8170
82- it ( "over-redacts emails with leading dots in the domain" , ( ) => {
83- expect ( redactEmails ( "Contact bob@.domain.org today" ) ) . toBe (
84- "Contact [EMAIL REDACTED] today" ,
85- ) ;
86- } ) ;
71+ it ( "over-redacts emails with invalid domain separators " , ( ) => {
72+ expect (
73+ redactEmails ( "Contact bob@-domain.org and bob@domain-.org today" ) ,
74+ ) . toBe ( "Contact [EMAIL REDACTED] and [EMAIL REDACTED] today" ) ;
75+ } ) ;
8776
88- it ( "over-redacts emails with consecutive dots in the domain" , ( ) => {
89- expect ( redactEmails ( "Contact bob@domain. .org today" ) ) . toBe (
90- "Contact [EMAIL REDACTED] today" ,
91- ) ;
92- } ) ;
77+ it ( "over-redacts emails with leading dots in the domain" , ( ) => {
78+ expect ( redactEmails ( "Contact bob@.domain .org today" ) ) . toBe (
79+ "Contact [EMAIL REDACTED] today" ,
80+ ) ;
81+ } ) ;
9382
94- it ( "over-redacts an email inside a URL " , ( ) => {
95- expect ( redactEmails ( "Visit https://alice@example.com/profile today" ) ) . toBe (
96- "Visit https:// [EMAIL REDACTED]/profile today",
97- ) ;
98- } ) ;
83+ it ( "over-redacts emails with consecutive dots in the domain " , ( ) => {
84+ expect ( redactEmails ( "Contact bob@domain..org today" ) ) . toBe (
85+ "Contact [EMAIL REDACTED] today",
86+ ) ;
87+ } ) ;
9988
100- it ( "over-redacts a documentation email" , ( ) => {
101- expect ( redactEmails ( "Use user @example.com in the documentation " ) ) . toBe (
102- "Use [EMAIL REDACTED] in the documentation ",
103- ) ;
104- } ) ;
89+ it ( "over-redacts an email inside a URL " , ( ) => {
90+ expect ( redactEmails ( "Visit https://alice @example.com/profile today " ) ) . toBe (
91+ "Visit https:// [EMAIL REDACTED]/profile today ",
92+ ) ;
93+ } ) ;
10594
106- it ( "over-redacts multiple invalid email-like values in one string" , ( ) => {
107- expect (
108- redactEmails (
109- "Values: _alice@example.com bob@domain..org carol.@example.com" ,
110- ) ,
111- ) . toBe (
112- "Values: [EMAIL REDACTED] [EMAIL REDACTED] [EMAIL REDACTED]" ,
113- ) ;
114- } ) ;
95+ it ( "over-redacts a documentation email" , ( ) => {
96+ expect ( redactEmails ( "Use user@example.com in the documentation" ) ) . toBe (
97+ "Use [EMAIL REDACTED] in the documentation" ,
98+ ) ;
99+ } ) ;
115100
116- it ( "over-redacts a plain number as a phone number" , ( ) => {
117- expect ( redactPhones ( "Reference number: 1234567" ) ) . toBe (
118- "Reference number: [PHONE REDACTED]" ,
119- ) ;
120- } ) ;
101+ it ( "over-redacts multiple invalid email-like values in one string" , ( ) => {
102+ expect (
103+ redactEmails (
104+ "Values: _alice@example.com bob@domain..org carol.@example.com" ,
105+ ) ,
106+ ) . toBe ( "Values: [EMAIL REDACTED] [EMAIL REDACTED] [EMAIL REDACTED]" ) ;
107+ } ) ;
121108
122- it ( "over-redacts a long numeric identifier as a phone number" , ( ) => {
123- expect ( redactPhones ( "Order ID: 001234567890 " ) ) . toBe (
124- "Order ID : [PHONE REDACTED]",
125- ) ;
126- } ) ;
109+ it ( "over-redacts a plain number as a phone number" , ( ) => {
110+ expect ( redactPhones ( "Reference number: 1234567 " ) ) . toBe (
111+ "Reference number : [PHONE REDACTED]",
112+ ) ;
113+ } ) ;
127114
128- it ( "over-redacts a version number as a phone number" , ( ) => {
129- expect ( redactPhones ( "Build version: 1.234.567 " ) ) . toBe (
130- "Build version : [PHONE REDACTED]",
131- ) ;
132- } ) ;
115+ it ( "over-redacts a long numeric identifier as a phone number" , ( ) => {
116+ expect ( redactPhones ( "Order ID: 001234567890 " ) ) . toBe (
117+ "Order ID : [PHONE REDACTED]",
118+ ) ;
119+ } ) ;
133120
134- it ( "over-redacts an IP address as a phone number" , ( ) => {
135- expect ( redactPhones ( "Server IP: 192.168.1.1 " ) ) . toBe (
136- "Server IP : [PHONE REDACTED]",
137- ) ;
138- } ) ;
121+ it ( "over-redacts a version number as a phone number" , ( ) => {
122+ expect ( redactPhones ( "Build version: 1.234.567 " ) ) . toBe (
123+ "Build version : [PHONE REDACTED]",
124+ ) ;
125+ } ) ;
139126
140- it ( "over-redacts a date-like value as a phone number" , ( ) => {
141- expect ( redactPhones ( "Reference date: 2026-08-06 " ) ) . toBe (
142- "Reference date : [PHONE REDACTED]",
143- ) ;
144- } ) ;
127+ it ( "over-redacts an IP address as a phone number" , ( ) => {
128+ expect ( redactPhones ( "Server IP: 192.168.1.1 " ) ) . toBe (
129+ "Server IP : [PHONE REDACTED]",
130+ ) ;
131+ } ) ;
145132
146- it ( "over-redacts a timestamp as a phone number" , ( ) => {
147- expect ( redactPhones ( "Created at: 20260806144500 " ) ) . toBe (
148- "Created at : [PHONE REDACTED]",
149- ) ;
150- } ) ;
133+ it ( "over-redacts a date-like value as a phone number" , ( ) => {
134+ expect ( redactPhones ( "Reference date: 2026-08-06 " ) ) . toBe (
135+ "Reference date : [PHONE REDACTED]",
136+ ) ;
137+ } ) ;
151138
152- it ( "over-redacts a postal code as a phone number" , ( ) => {
153- expect ( redactPhones ( "PIN code: 11000123 " ) ) . toBe (
154- "PIN code : [PHONE REDACTED]",
155- ) ;
156- } ) ;
139+ it ( "over-redacts a timestamp as a phone number" , ( ) => {
140+ expect ( redactPhones ( "Created at: 20260806144500 " ) ) . toBe (
141+ "Created at : [PHONE REDACTED]",
142+ ) ;
143+ } ) ;
157144
145+ it ( "over-redacts a postal code as a phone number" , ( ) => {
146+ expect ( redactPhones ( "PIN code: 11000123" ) ) . toBe (
147+ "PIN code: [PHONE REDACTED]" ,
148+ ) ;
149+ } ) ;
158150
159- it ( "over-redacts a currency amount as a phone number" , ( ) => {
160- expect ( redactPhones ( "Total amount: 123.456.789" ) ) . toBe (
161- "Total amount: [PHONE REDACTED]" ,
162- ) ;
163- } ) ;
151+ it ( "over-redacts a currency amount as a phone number" , ( ) => {
152+ expect ( redactPhones ( "Total amount: 123.456.789" ) ) . toBe (
153+ "Total amount: [PHONE REDACTED]" ,
154+ ) ;
155+ } ) ;
164156
165- it ( "over-redacts coordinates as a phone number" , ( ) => {
166- expect ( redactPhones ( "Location: 28.6139 77.2090" ) ) . toBe (
167- "Location: [PHONE REDACTED]" ,
168- ) ;
169- } ) ;
157+ it ( "over-redacts coordinates as a phone number" , ( ) => {
158+ expect ( redactPhones ( "Location: 28.6139 77.2090" ) ) . toBe (
159+ "Location: [PHONE REDACTED]" ,
160+ ) ;
161+ } ) ;
170162
171- it ( "over-redacts an all-zero placeholder as a phone number" , ( ) => {
172- expect ( redactPhones ( "Placeholder: 000-000-0000" ) ) . toBe (
173- "Placeholder: [PHONE REDACTED]" ,
174- ) ;
175- } ) ;
163+ it ( "over-redacts an all-zero placeholder as a phone number" , ( ) => {
164+ expect ( redactPhones ( "Placeholder: 000-000-0000" ) ) . toBe (
165+ "Placeholder: [PHONE REDACTED]" ,
166+ ) ;
167+ } ) ;
176168
177- it ( "over-redacts a parenthesized value as a phone number" , ( ) => {
178- expect ( redactPhones ( "Value: (2026) 1234567" ) ) . toBe (
179- "Value: [PHONE REDACTED]" ,
180- ) ;
181- } ) ;
169+ it ( "over-redacts a parenthesized value as a phone number" , ( ) => {
170+ expect ( redactPhones ( "Value: (2026) 1234567" ) ) . toBe (
171+ "Value: [PHONE REDACTED]" ,
172+ ) ;
173+ } ) ;
182174
183- it ( "over-redacts an extension-like value as a phone number" , ( ) => {
184- expect ( redactPhones ( "Extension: ext-1234568" ) ) . toBe (
185- "Extension: ext-[PHONE REDACTED]" ,
186- ) ;
187- } ) ;
175+ it ( "over-redacts an extension-like value as a phone number" , ( ) => {
176+ expect ( redactPhones ( "Extension: ext-1234568" ) ) . toBe (
177+ "Extension: ext-[PHONE REDACTED]" ,
178+ ) ;
179+ } ) ;
188180
189- it ( "over-redacts a number embedded in an identifier" , ( ) => {
190- expect ( redactPhones ( "Serial number: ABC-1234567-XYZ" ) ) . toBe (
191- "Serial number: ABC-[PHONE REDACTED]-XYZ" ,
192- ) ;
193- } ) ;
181+ it ( "over-redacts a number embedded in an identifier" , ( ) => {
182+ expect ( redactPhones ( "Serial number: ABC-1234567-XYZ" ) ) . toBe (
183+ "Serial number: ABC-[PHONE REDACTED]-XYZ" ,
184+ ) ;
185+ } ) ;
194186
195- it ( "over-redacts multiple non-phone values in one string" , ( ) => {
196- expect (
197- redactPhones (
198- "Date 2026-08-06, IP 192.168.1.1, version 1.234.567, order 001234567890" ,
199- ) ,
200- ) . toBe (
201- "Date [PHONE REDACTED], IP [PHONE REDACTED], version [PHONE REDACTED], order [PHONE REDACTED]" ,
202- ) ;
203- } ) ;
187+ it ( "over-redacts multiple non-phone values in one string" , ( ) => {
188+ expect (
189+ redactPhones (
190+ "Date 2026-08-06, IP 192.168.1.1, version 1.234.567, order 001234567890" ,
191+ ) ,
192+ ) . toBe (
193+ "Date [PHONE REDACTED], IP [PHONE REDACTED], version [PHONE REDACTED], order [PHONE REDACTED]" ,
194+ ) ;
195+ } ) ;
204196
205- it ( "over-redacts an email embedded in a larger token" , ( ) => {
206- expect ( redactEmails ( "Contact prefixalice@example.comsuffix today" ) ) . toBe (
207- "Contact [EMAIL REDACTED] today" ,
208- ) ;
197+ it ( "over-redacts an email embedded in a larger token" , ( ) => {
198+ expect ( redactEmails ( "Contact prefixalice@example.comsuffix today" ) ) . toBe (
199+ "Contact [EMAIL REDACTED] today" ,
200+ ) ;
201+ } ) ;
209202} ) ;
210-
211-
212- } ) ;
0 commit comments