diff --git a/test/index.test.ts b/test/index.test.ts index 51a9982..18dc860 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -653,6 +653,10 @@ describe('HipThrusTS', () => { c: testConstants.cReturned, }; + const testOutputForSanitizers = { + c: testConstants.cReturned, + }; + return { left: { [stage]: leftProjector, @@ -662,6 +666,7 @@ describe('HipThrusTS', () => { } as Record, testInput, testOutput, + testOutputForSanitizers, }; } @@ -678,6 +683,45 @@ describe('HipThrusTS', () => { true ); }); + it('sanitize params test', async () => { + const lifecycleStage = 'sanitizeParams'; + await HTPipeTest( + HTPipe( + fullyCoveredCaseTest(lifecycleStage).left, + fullyCoveredCaseTest(lifecycleStage).right + ), + lifecycleStage, + fullyCoveredCaseTest(lifecycleStage).testInput, + fullyCoveredCaseTest(lifecycleStage).testOutputForSanitizers, + true + ); + }); + it('sanitize query params test', async () => { + const lifecycleStage = 'sanitizeQueryParams'; + await HTPipeTest( + HTPipe( + fullyCoveredCaseTest(lifecycleStage).left, + fullyCoveredCaseTest(lifecycleStage).right + ), + lifecycleStage, + fullyCoveredCaseTest(lifecycleStage).testInput, + fullyCoveredCaseTest(lifecycleStage).testOutputForSanitizers, + true + ); + }); + it('sanitize body test', async () => { + const lifecycleStage = 'sanitizeBody'; + await HTPipeTest( + HTPipe( + fullyCoveredCaseTest(lifecycleStage).left, + fullyCoveredCaseTest(lifecycleStage).right + ), + lifecycleStage, + fullyCoveredCaseTest(lifecycleStage).testInput, + fullyCoveredCaseTest(lifecycleStage).testOutputForSanitizers, + true + ); + }); it('attachData test sync', async () => { const lifecycleStage = 'attachData'; await HTPipeTest( @@ -765,6 +809,45 @@ describe('HipThrusTS', () => { true ); }); + it('sanitizeParams test', async () => { + const lifecycleStage = 'sanitizeParams'; + await HTPipeTest( + HTPipe( + transformedTypeCaseTest(lifecycleStage).left, + transformedTypeCaseTest(lifecycleStage).right + ), + lifecycleStage, + transformedTypeCaseTest(lifecycleStage).testInput, + transformedTypeCaseTest(lifecycleStage).testOutput, + true + ); + }); + it('sanitizeQueryParams test', async () => { + const lifecycleStage = 'sanitizeQueryParams'; + await HTPipeTest( + HTPipe( + transformedTypeCaseTest(lifecycleStage).left, + transformedTypeCaseTest(lifecycleStage).right + ), + lifecycleStage, + transformedTypeCaseTest(lifecycleStage).testInput, + transformedTypeCaseTest(lifecycleStage).testOutput, + true + ); + }); + it('sanitizeBody test', async () => { + const lifecycleStage = 'sanitizeBody'; + await HTPipeTest( + HTPipe( + transformedTypeCaseTest(lifecycleStage).left, + transformedTypeCaseTest(lifecycleStage).right + ), + lifecycleStage, + transformedTypeCaseTest(lifecycleStage).testInput, + transformedTypeCaseTest(lifecycleStage).testOutput, + true + ); + }); it('attachData sync', async () => { const lifecycleStage = 'attachData'; await HTPipeTest( @@ -946,6 +1029,57 @@ describe('HipThrusTS', () => { true ); }); + it('sanitizeParams should give error in this case because of his filtration functionality test', () => { + async function expectErrorWithHTPipe() { + const lifecycleStage = 'sanitizeParams'; + await HTPipeTest( + // @ts-expect-error + HTPipe( + notCoveredCaseTest(lifecycleStage).left, + notCoveredCaseTest(lifecycleStage).right + ), + lifecycleStage, + notCoveredCaseTest(lifecycleStage).testInput, + notCoveredCaseTest(lifecycleStage).testOutput, + // @ts-expect-error + true + ); + } + }); + it('sanitizeQueryParams should give error in this case because of his filtration functionality test', () => { + async function expectErrorWithHTPipe() { + const lifecycleStage = 'sanitizeQueryParams'; + await HTPipeTest( + // @ts-expect-error + HTPipe( + notCoveredCaseTest(lifecycleStage).left, + notCoveredCaseTest(lifecycleStage).right + ), + lifecycleStage, + notCoveredCaseTest(lifecycleStage).testInput, + notCoveredCaseTest(lifecycleStage).testOutput, + // @ts-expect-error + true + ); + } + }); + it('sanitizeBody should give error in this case because of his filtration functionality test', () => { + async function expectErrorWithHTPipe() { + const lifecycleStage = 'sanitizeBody'; + await HTPipeTest( + // @ts-expect-error + HTPipe( + notCoveredCaseTest(lifecycleStage).left, + notCoveredCaseTest(lifecycleStage).right + ), + lifecycleStage, + notCoveredCaseTest(lifecycleStage).testInput, + notCoveredCaseTest(lifecycleStage).testOutput, + // @ts-expect-error + true + ); + } + }); it('attachData sync', async () => { const lifecycleStage = 'attachData'; await HTPipeTest( @@ -1025,6 +1159,45 @@ describe('HipThrusTS', () => { true ); }); + it('sanitizeParams test', async () => { + const lifecycleStage = 'sanitizeParams'; + await HTPipeTest( + HTPipe( + leftOnlyCaseTest(lifecycleStage).left, + leftOnlyCaseTest(lifecycleStage).right + ), + lifecycleStage, + leftOnlyCaseTest(lifecycleStage).testInput, + leftOnlyCaseTest(lifecycleStage).testOutput, + true + ); + }); + it('sanitizeQueryParams test', async () => { + const lifecycleStage = 'sanitizeQueryParams'; + await HTPipeTest( + HTPipe( + leftOnlyCaseTest(lifecycleStage).left, + leftOnlyCaseTest(lifecycleStage).right + ), + lifecycleStage, + leftOnlyCaseTest(lifecycleStage).testInput, + leftOnlyCaseTest(lifecycleStage).testOutput, + true + ); + }); + it('sanitizeBody test', async () => { + const lifecycleStage = 'sanitizeBody'; + await HTPipeTest( + HTPipe( + leftOnlyCaseTest(lifecycleStage).left, + leftOnlyCaseTest(lifecycleStage).right + ), + lifecycleStage, + leftOnlyCaseTest(lifecycleStage).testInput, + leftOnlyCaseTest(lifecycleStage).testOutput, + true + ); + }); it('attachData sync', async () => { const lifecycleStage = 'attachData'; await HTPipeTest( @@ -1104,6 +1277,45 @@ describe('HipThrusTS', () => { true ); }); + it('sanitizeParams test', async () => { + const lifecycleStage = 'sanitizeParams'; + await HTPipeTest( + HTPipe( + rightOnlyCaseTest(lifecycleStage).left, + rightOnlyCaseTest(lifecycleStage).right + ), + lifecycleStage, + rightOnlyCaseTest(lifecycleStage).testInput, + rightOnlyCaseTest(lifecycleStage).testOutput, + true + ); + }); + it('sanitizeQueryParams test', async () => { + const lifecycleStage = 'sanitizeQueryParams'; + await HTPipeTest( + HTPipe( + rightOnlyCaseTest(lifecycleStage).left, + rightOnlyCaseTest(lifecycleStage).right + ), + lifecycleStage, + rightOnlyCaseTest(lifecycleStage).testInput, + rightOnlyCaseTest(lifecycleStage).testOutput, + true + ); + }); + it('sanitizeBody test', async () => { + const lifecycleStage = 'sanitizeBody'; + await HTPipeTest( + HTPipe( + rightOnlyCaseTest(lifecycleStage).left, + rightOnlyCaseTest(lifecycleStage).right + ), + lifecycleStage, + rightOnlyCaseTest(lifecycleStage).testInput, + rightOnlyCaseTest(lifecycleStage).testOutput, + true + ); + }); it('attachData sync', async () => { const lifecycleStage = 'attachData'; await HTPipeTest( @@ -1170,6 +1382,36 @@ describe('HipThrusTS', () => { ); } }); + it('sanitizeParams test', async () => { + const lifecycleStage = 'sanitizeParams'; + function expectErrorWithHTPipe() { + // @ts-expect-error + const pipedError = HTPipe( + errorCaseTest(lifecycleStage).left, + errorCaseTest(lifecycleStage).right + ); + } + }); + it('sanitizeQueryParams test', async () => { + const lifecycleStage = 'sanitizeQueryParams'; + function expectErrorWithHTPipe() { + // @ts-expect-error + const pipedError = HTPipe( + errorCaseTest(lifecycleStage).left, + errorCaseTest(lifecycleStage).right + ); + } + }); + it('sanitizeBody test', async () => { + const lifecycleStage = 'sanitizeBody'; + function expectErrorWithHTPipe() { + // @ts-expect-error + const pipedError = HTPipe( + errorCaseTest(lifecycleStage).left, + errorCaseTest(lifecycleStage).right + ); + } + }); it('attachData sync', async () => { it('no attaches data when left sync outputs have type mismatch with right inputs', () => { const lifecycleStage = 'attachData';