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

test: more test for HTPipeTest function #70

Open
wants to merge 1 commit 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
138 changes: 135 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,22 @@ async function HTPipeTest<
: never
: never
: never,
TPipeInExpected = TPipeIn,
TPipeOutExpected = TPipeOut
TPipeInRequired,
TPipeOutRequired,
TPipeInExpected = undefined extends TPipeInRequired
? TPipeIn
: TPipeInRequired,
TPipeOutExpected = undefined extends TPipeOutRequired
? TPipeOut
: TPipeOutRequired
>(
pipe: TPipe,
lifecycleStage: TStage,
pipeIn: TPipeIn,
pipeOut: TPipeOut,
valid: TValid
valid: TValid,
pipeInRequired?: TPipeInRequired,
pipeOutRequired?: TPipeOutRequired
) {
const pipedLifecycleStage = pipe[lifecycleStage];

Expand Down Expand Up @@ -595,6 +603,130 @@ describe('HipThrusTS', () => {
// tslint:disable-next-line:no-unused-expression
expect(errorReturned).to.exist;
});
it('should pass when pipeIn accept more parameters then it really using', async () => {
const aPassedIn = 'some string';
const bReturned = 4;
const cReturned = 6;

await HTPipeTest(
{
attachData: (context: { a: string }) => {
return {
aOut: context.a,
c: cReturned,
b: bReturned,
};
},
},
'attachData',
{ a: aPassedIn, g: 'some unneccessary string' },
{ aOut: aPassedIn, b: bReturned, c: cReturned },
true,
{ a: aPassedIn },
{ aOut: aPassedIn, b: bReturned, c: cReturned }
);
});
it('should give error when pipeIn missing one of required params', async () => {
const aPassedIn = 'some string';
const bReturned = 4;
const cReturned = 6;

let errorReturned;

try {
await HTPipeTest(
{
attachData: (context: { a: string }) => {
return {
aOut: context.a,
c: cReturned,
b: bReturned,
};
},
},
'attachData',
{},
{ aOut: aPassedIn, b: bReturned, c: cReturned },
true,
{ a: aPassedIn },
{ aOut: aPassedIn, b: bReturned, c: cReturned }
);
} catch (err) {
errorReturned = err;
}

// tslint:disable-next-line:no-unused-expression
expect(errorReturned).to.exist;
});
it('should give error when pipeOut have more object properties then return object of lifecycle function', async () => {
const aPassedIn = 'some string';
const bReturned = 4;
const cReturned = 6;

let errorReturned;

try {
await HTPipeTest(
{
attachData: (context: { a: string }) => {
return {
aOut: context.a,
c: cReturned,
b: bReturned,
};
},
},
'attachData',
{ a: aPassedIn },
{
aOut: aPassedIn,
b: bReturned,
c: cReturned,
g: 'some unneccessary string',
},
true,
{ a: aPassedIn },
{ aOut: aPassedIn, b: bReturned, c: cReturned }
);
} catch (err) {
errorReturned = err;
}

// tslint:disable-next-line:no-unused-expression
expect(errorReturned).to.exist;
});
it('should give error when pipeOut have less object properties then return object of lifecycle function', async () => {
const aPassedIn = 'some string';
const bReturned = 4;
const cReturned = 6;

let errorReturned;

try {
await HTPipeTest(
{
attachData: (context: { a: string }) => {
return {
aOut: context.a,
c: cReturned,
b: bReturned,
};
},
},
'attachData',
{ a: aPassedIn },
{ aOut: aPassedIn, b: bReturned },
true,
{ a: aPassedIn },
{ aOut: aPassedIn, b: bReturned, c: cReturned }
);
} catch (err) {
errorReturned = err;
}

// tslint:disable-next-line:no-unused-expression
expect(errorReturned).to.exist;
});
});
describe('HTPipe2', () => {
it('works with three operators', () => {
Expand Down