私はハピを使用していますが、これは私のハンドラ関数です:テスト時に自分のクッキーがハンドラ関数で利用できないのはなぜですか?
function propertyDetailsValidateHandler(request, reply, source, error) {
console.log(request.state)
var data = joiValidationHelper.checkForErrors(request, error);
if (typeof data !== "undefined"){
return reply.view('property-details', data).code(400);
} else {
var details = request.state.details;
details.propertyType = request.payload.propertyType;
details.newBuild = request.payload.newBuild;
return reply.redirect('/property-details/postcode').state('details', details, {path: '/'});
}
}
そして、これはジャスミン使って書かれた私のテストで:
describe('tell us about the property youre buying flow', function(){
it('test /property-details, status code and location', function(done){
var options = {
method: 'POST',
url: '/property-details',
headers: {
cookie: {details: { test: "test"}}
},
payload: {
propertyType: "freehold",
newBuild: true
}
};
server.inject(options, function(response){
detailsTestCookie = response.headers['set-cookie'][0].split(';')[0];
expect(response.statusCode).toBe(302);
expect(response.headers.location).toMatch("/property-details/postcode");
done();
});
});
})
私は自分のサーバーを実行し、ブラウザを使用する場合、ハンドラ関数が正しく実行をテストを実行すると、request.stateは空のオブジェクトです。テストで提供したクッキーであることが予想されていたため、request.state.detailsが定義されていないため、テストが失敗します。これは私のテストでクッキーをヘッダに提供する正しい方法ですか?
んクッキーは間違いなくブラウザに設定されていますか? response.statusCodeは間違いなく302テストですか? – Eoin
Cookieがブラウザに確実に設定されます。 StatusCodeは、request.stateが空であるため、 'request.state.details'で壊れているので現在500を返しています – Ruth