Skip to content

Commit

Permalink
test: integration & unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jackey8616 committed Oct 12, 2024
1 parent 0c8daf3 commit 6fe0265
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 130 deletions.
100 changes: 64 additions & 36 deletions tests/integration/express-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,52 +194,80 @@ describe('Express Server', () => {
});
});

it('Should return on @Res', () => {
return verifyGetRequest(
basePath + '/GetTest/Res',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
400,
);
});
describe('@Res', () => {
it('Should return on @Res', () => {
return verifyGetRequest(
basePath + '/GetTest/Res',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
400,
);
});

it('Should return on @Res with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/Res_Alias',
(_err, res) => {
expect(res.body.name).to.equal('some_thing');
},
400,
);
});
it('Should return on @Res with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/Res_Alias',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('name')).to.equal('some_thing');
},
400,
);
});

[400, 500].forEach(statusCode =>
it('Should support multiple status codes with the same @Res structure', () => {
[400, 500].forEach(statusCode => {
it('Should support multiple status codes with the same @Res structure', () => {
return verifyGetRequest(
basePath + `/GetTest/MultipleStatusCodeRes?statusCode=${statusCode}`,
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
statusCode,
);
});

it('Should support multiple status codes with the same @Res structure with alias', () => {
return verifyGetRequest(
basePath + `/GetTest/MultipleStatusCodeRes_Alias?statusCode=${statusCode}`,
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('name')).to.eq('combine');
},
statusCode,
);
});
});

it('Should not modify the response after headers sent', () => {
return verifyGetRequest(
basePath + `/GetTest/MultipleStatusCodeRes?statusCode=${statusCode}`,
basePath + '/GetTest/MultipleRes',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
statusCode,
400,
);
}),
);
});

it('Should not modify the response after headers sent', () => {
return verifyGetRequest(
basePath + '/GetTest/MultipleRes',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
400,
);
it('Should not modify the response after headers sent with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/MultipleRes_Alias',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('name')).to.eq('some_thing');
},
400,
);
});
});

it('parses buffer parameter', () => {
Expand Down
100 changes: 64 additions & 36 deletions tests/integration/hapi-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1315,52 +1315,80 @@ describe('Hapi Server', () => {
});
});

it('Should return on @Res', () => {
return verifyGetRequest(
basePath + '/GetTest/Res',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
400,
);
});
describe('@Res', () => {
it('Should return on @Res', () => {
return verifyGetRequest(
basePath + '/GetTest/Res',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
400,
);
});

it('Should return on @Res with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/Res_Alias',
(_err, res) => {
expect(res.body.name).to.equal('some_thing');
},
400,
);
});
it('Should return on @Res with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/Res_Alias',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('name')).to.equal('some_thing');
},
400,
);
});

[400, 500].forEach(statusCode =>
it('Should support multiple status codes with the same @Res structure', () => {
[400, 500].forEach(statusCode => {
it('Should support multiple status codes with the same @Res structure', () => {
return verifyGetRequest(
basePath + `/GetTest/MultipleStatusCodeRes?statusCode=${statusCode}`,
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
statusCode,
);
});

it('Should support multiple status codes with the same @Res structure with alias', () => {
return verifyGetRequest(
basePath + `/GetTest/MultipleStatusCodeRes_Alias?statusCode=${statusCode}`,
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('name')).to.eq('combine');
},
statusCode,
);
});
});

it('Should not modify the response after headers sent', () => {
return verifyGetRequest(
basePath + `/GetTest/MultipleStatusCodeRes?statusCode=${statusCode}`,
basePath + '/GetTest/MultipleRes',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
statusCode,
400,
);
}),
);
});

it('Should not modify the response after headers sent', () => {
return verifyGetRequest(
basePath + '/GetTest/MultipleRes',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
400,
);
it('Should not modify the response after headers sent with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/MultipleRes_Alias',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('name')).to.eq('some_thing');
},
400,
);
});
});
});

Expand Down
100 changes: 64 additions & 36 deletions tests/integration/koa-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1295,52 +1295,80 @@ describe('Koa Server', () => {
});
});

it('Should return on @Res', () => {
return verifyGetRequest(
basePath + '/GetTest/Res',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
400,
);
});
describe('@Res', () => {
it('Should return on @Res', () => {
return verifyGetRequest(
basePath + '/GetTest/Res',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
400,
);
});

it('Should return on @Res with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/Res_Alias',
(_err, res) => {
expect(res.body.name).to.equal('some_thing');
},
400,
);
});
it('Should return on @Res with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/Res_Alias',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('name')).to.equal('some_thing');
},
400,
);
});

[400, 500].forEach(statusCode =>
it('Should support multiple status codes with the same @Res structure', () => {
[400, 500].forEach(statusCode => {
it('Should support multiple status codes with the same @Res structure', () => {
return verifyGetRequest(
basePath + `/GetTest/MultipleStatusCodeRes?statusCode=${statusCode}`,
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
statusCode,
);
});

it('Should support multiple status codes with the same @Res structure with alias', () => {
return verifyGetRequest(
basePath + `/GetTest/MultipleStatusCodeRes_Alias?statusCode=${statusCode}`,
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('name')).to.eq('combine');
},
statusCode,
);
});
});

it('Should not modify the response after headers sent', () => {
return verifyGetRequest(
basePath + `/GetTest/MultipleStatusCodeRes?statusCode=${statusCode}`,
basePath + '/GetTest/MultipleRes',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
statusCode,
400,
);
}),
);
});

it('Should not modify the response after headers sent', () => {
return verifyGetRequest(
basePath + '/GetTest/MultipleRes',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('custom-header')).to.eq('hello');
},
400,
);
it('Should not modify the response after headers sent with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/MultipleRes_Alias',
(_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
expect(res.get('name')).to.eq('some_thing');
},
400,
);
});
});
});

Expand Down
Loading

0 comments on commit 6fe0265

Please sign in to comment.