Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MERGE ONLY AFTER PR #86: Test sanitize body lifecycle #87

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
242 changes: 242 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ describe('HipThrusTS', () => {
c: testConstants.cReturned,
};

const testOutputForSanitizers = {
c: testConstants.cReturned,
};

return {
left: {
[stage]: leftProjector,
Expand All @@ -662,6 +666,7 @@ describe('HipThrusTS', () => {
} as Record<TStage, typeof rightProjector>,
testInput,
testOutput,
testOutputForSanitizers,
};
}

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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';
Expand Down