@@ -2,33 +2,33 @@ import { v } from '../core';
2
2
3
3
import * as dotenv from 'dotenv' ;
4
4
dotenv . config ( {
5
- path : './config/test/.env'
5
+ path : './config/test/.env.test.sample '
6
6
} ) ;
7
7
8
8
// --- PROTOCOL ---
9
9
10
- test ( 'Protocol Success http ' , ( ) => {
10
+ test ( 'Protocol Error ' , ( ) => {
11
11
const mockSchema = v . schema ( {
12
12
PROTOCOL_TEST_1 : v . str ( ) . protocol ( )
13
13
} ) ;
14
14
15
- expect ( mockSchema . safeParse ( process . env ) . success ) . toBeTruthy ( ) ;
15
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
16
16
} ) ;
17
17
18
- test ( 'Protocol Success https ' , ( ) => {
18
+ test ( 'Protocol Success http ' , ( ) => {
19
19
const mockSchema = v . schema ( {
20
- PROTOCOL_TEST_3 : v . str ( ) . protocol ( )
20
+ PROTOCOL_TEST_2 : v . str ( ) . protocol ( )
21
21
} ) ;
22
22
23
23
expect ( mockSchema . safeParse ( process . env ) . success ) . toBeTruthy ( ) ;
24
24
} ) ;
25
25
26
- test ( 'Protocol Error ' , ( ) => {
26
+ test ( 'Protocol Success https ' , ( ) => {
27
27
const mockSchema = v . schema ( {
28
- PROTOCOL_TEST_2 : v . str ( ) . protocol ( )
28
+ PROTOCOL_TEST_3 : v . str ( ) . protocol ( )
29
29
} ) ;
30
30
31
- expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
31
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeTruthy ( ) ;
32
32
} ) ;
33
33
34
34
// --- HOST ---
@@ -65,24 +65,49 @@ test('Host Error contains letters', () => {
65
65
expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
66
66
} ) ;
67
67
68
- // --- URL ---
68
+ // --- LOCALHOST ---
69
69
70
- test ( 'URL Success ' , ( ) => {
70
+ test ( 'LOCALHOST error, doesnt have port number. ' , ( ) => {
71
71
const mockSchema = v . schema ( {
72
- TEST_URL_1 : v . str ( ) . url ( )
72
+ TEST_LOCALHOST_1 : v . str ( ) . localhost ( )
73
+ } ) ;
74
+
75
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
76
+ } ) ;
77
+
78
+ test ( 'LOCALHOST success, doesnt have protocol.' , ( ) => {
79
+ const mockSchema = v . schema ( {
80
+ TEST_LOCALHOST_2 : v . str ( ) . localhost ( )
81
+ } ) ;
82
+
83
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeTruthy ( ) ;
84
+ } ) ;
85
+
86
+ test ( 'LOCALHOST success, with protocol.' , ( ) => {
87
+ const mockSchema = v . schema ( {
88
+ TEST_LOCALHOST_3 : v . str ( ) . localhost ( )
73
89
} ) ;
74
90
75
91
expect ( mockSchema . safeParse ( process . env ) . success ) . toBeTruthy ( ) ;
76
92
} ) ;
77
93
94
+ // --- URL ---
78
95
test ( 'URL Error invalid protocol' , ( ) => {
79
96
const mockSchema = v . schema ( {
80
- TEST_URL_2 : v . str ( ) . url ( )
97
+ TEST_URL_1 : v . str ( ) . url ( )
81
98
} ) ;
82
99
83
100
expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
84
101
} ) ;
85
102
103
+ test ( 'URL Success' , ( ) => {
104
+ const mockSchema = v . schema ( {
105
+ TEST_URL_2 : v . str ( ) . url ( )
106
+ } ) ;
107
+
108
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeTruthy ( ) ;
109
+ } ) ;
110
+
86
111
test ( 'URL Success with Localhost' , ( ) => {
87
112
const mockSchema = v . schema ( {
88
113
TEST_URL_3 : v . str ( ) . url ( )
@@ -307,20 +332,70 @@ test('Boolean success, is false.', () => {
307
332
308
333
// --- NUMBER ---
309
334
310
- test ( 'Boolean error, is not a valid number.' , ( ) => {
335
+ test ( 'Number error, is not a valid number.' , ( ) => {
311
336
const mockSchema = v . schema ( {
312
337
TEST_NUMBER_1 : v . str ( ) . number ( )
313
338
} ) ;
314
339
315
340
expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
316
341
} ) ;
317
342
318
- test ( 'Boolean success, is a valid number.' , ( ) => {
343
+ test ( 'Number success, is a valid number.' , ( ) => {
319
344
const mockSchema = v . schema ( {
320
345
TEST_NUMBER_2 : v . str ( ) . number ( )
321
346
} ) ;
322
347
323
348
expect ( mockSchema . safeParse ( process . env ) . success ) . toBeTruthy ( ) ;
324
349
} ) ;
325
350
326
- // TODO undefined cases
351
+ // --- POSTGRESURL ---
352
+
353
+ test ( 'POSTGRESURL error, doesnt start with postgresql://.' , ( ) => {
354
+ const mockSchema = v . schema ( {
355
+ TEST_POSTGRES_URL_1 : v . str ( ) . postgresUrl ( )
356
+ } ) ;
357
+
358
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
359
+ } ) ;
360
+
361
+ test ( 'POSTGRESURL error, wrong format, doesnt contain @.' , ( ) => {
362
+ const mockSchema = v . schema ( {
363
+ TEST_POSTGRES_URL_2 : v . str ( ) . postgresUrl ( )
364
+ } ) ;
365
+
366
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
367
+ } ) ;
368
+
369
+ test ( 'POSTGRESURL error, invalid host.' , ( ) => {
370
+ const mockSchema = v . schema ( {
371
+ TEST_POSTGRES_URL_3 : v . str ( ) . postgresUrl ( )
372
+ } ) ;
373
+
374
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
375
+ } ) ;
376
+
377
+ test ( 'POSTGRESURL success, valid postgres url.' , ( ) => {
378
+ const mockSchema = v . schema ( {
379
+ TEST_POSTGRES_URL_4 : v . str ( ) . postgresUrl ( )
380
+ } ) ;
381
+
382
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeTruthy ( ) ;
383
+ } ) ;
384
+
385
+ // --- STARTS WITH ---
386
+
387
+ test ( 'Startswith error, doesnt starts with given value.' , ( ) => {
388
+ const mockSchema = v . schema ( {
389
+ TEST_START_WITH_1 : v . str ( ) . startsWith ( 'AVALUE' )
390
+ } ) ;
391
+
392
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeFalsy ( ) ;
393
+ } ) ;
394
+
395
+ test ( 'Startswith success, starts with given value.' , ( ) => {
396
+ const mockSchema = v . schema ( {
397
+ TEST_START_WITH_2 : v . str ( ) . startsWith ( 'WORLD' )
398
+ } ) ;
399
+
400
+ expect ( mockSchema . safeParse ( process . env ) . success ) . toBeTruthy ( ) ;
401
+ } ) ;
0 commit comments