Page 485 - Nodejs 교과서 개정2판
P. 485

};


           exports.isNotLoggedIn	=	(req,	res,	next)	=>	{
           		if	(!req.isAuthenticated())	{
           				next();
           		}	else	{
           				const	message	=	encodeURIComponent('로그인한	상태입니다.');
           				res.redirect(`/?error=${message}`);
           		}
           };




         पઁ ௏٘ীࢲח ੊झ೐ۨझо req  res ё୓৬ next ೣࣻܳ ੋࣻ۽ ֍঻ӝী ࢎਊೡ ࣻ ੓঻૑݅  పझ౟ ജ҃

         ীࢲח যڌѱ ֍যঠ ೡ૑ Ҋ޹ؾפ׮  req ё୓ীח isAuthenticated ݫࢲ٘о ઓ੤ೞҊ res ё୓ীب TUBUV
         T  send  redirect ݫࢲ٘о ઓ੤ೞחؘ  ௏٘о ࢿҕ੸ਵ۽ प೯غѱ ೞ۰ݶ ੉Ѫٜਸ ݽف ҳഅ೧ঠ ೤פ׮

         ੉ۡ ٸח җхೞѱ о૞ ё୓৬ ೣࣻܳ ٜ݅য ֍ਵݶ ؾפ׮  పझ౟੄ ৉ೡ਷ ௏٘ա ೣࣻо ઁ؀۽ प೯غח

         ૑ܳ ѨࢎೞҊ ч੉ ੌ஖ೞח૑ܳ Ѩࢎೞח Ѫ੉޲۽  పझ౟ ௏٘੄ ё୓о पઁ ੊झ೐ۨझ ё୓о ইפযب
         ؾפ׮  ੉ۧѱ о૞ ё୓  о૞ ೣࣻܳ ֍ח ೯ਤܳ ݽఊ NPDLJOH ੉ۄҊ ೤פ׮


          routes/middlewares.test.js
           const	{	isLoggedIn,	isNotLoggedIn	}	=	require('./middlewares');


           describe('isLoggedIn',	()	=>	{
           		const	res	=	{
           				status:	jest.fn(()	=>	res),
           				send:	jest.fn(),
           		};
           		const	next	=	jest.fn();


           		test('로그인되어	있으면	isLoggedIn이	next를	호출해야	함',	()	=>	{
           				const	req	=	{
           						isAuthenticated:	jest.fn(()	=>	true),
           				};
           				isLoggedIn(req,	res,	next);
           				expect(next).toBeCalledTimes(1);
           		});


           		test('로그인되어	있지	않으면	isLoggedIn이	에러를	응답해야	함',	()	=>	{
           				const	req	=	{
           						isAuthenticated:	jest.fn(()	=>	false),
           				};
           				isLoggedIn(req,	res,	next);
           				expect(res.status).toBeCalledWith(403);
   480   481   482   483   484   485   486   487   488   489   490