mirror of
				https://github.com/HabitRPG/habitica.git
				synced 2025-10-31 05:05:07 +01:00 
			
		
		
		
	* Updated userItemsNotEnough string * Added a variable to be passed to the deleteSocialAccountText string. This variable name is `magic_word` and is set as DELETE where used * modified incorrectDeletePhrase to use a variable rather than translatable string for the word DELETE. Updated the DELETE-user test and the user api * Changed noSudoAccess from translatable string to static * Changed enterprisePlansEmailSubject from a translatable string to a static string within groupPlans.vue * Fixed test problems with translation fixes * Added no sudo access string to api messages * changed plain string to apiMessage for no sudo access messages
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* eslint-disable global-require */
 | |
| import {
 | |
|   generateRes,
 | |
|   generateReq,
 | |
|   generateNext,
 | |
| } from '../../../../helpers/api-unit.helper';
 | |
| import i18n from '../../../../../website/common/script/i18n';
 | |
| import { ensureAdmin, ensureSudo } from '../../../../../website/server/middlewares/ensureAccessRight';
 | |
| import { NotAuthorized } from '../../../../../website/server/libs/errors';
 | |
| import apiMessages from '../../../../../website/server/libs/apiMessages';
 | |
| 
 | |
| describe('ensure access middlewares', () => {
 | |
|   let res, req, next;
 | |
| 
 | |
|   beforeEach(() => {
 | |
|     res = generateRes();
 | |
|     req = generateReq();
 | |
|     next = generateNext();
 | |
|   });
 | |
| 
 | |
|   context('ensure admin', () => {
 | |
|     it('returns not authorized when user is not an admin', () => {
 | |
|       res.locals = {user: {contributor: {admin: false}}};
 | |
| 
 | |
|       ensureAdmin(req, res, next);
 | |
| 
 | |
|       expect(next).to.be.calledWith(new NotAuthorized(i18n.t('noAdminAccess')));
 | |
|     });
 | |
| 
 | |
|     it('passes when user is an admin', () => {
 | |
|       res.locals = {user: {contributor: {admin: true}}};
 | |
| 
 | |
|       ensureAdmin(req, res, next);
 | |
| 
 | |
|       expect(next).to.be.calledOnce;
 | |
|       expect(next.args[0]).to.be.empty;
 | |
|     });
 | |
|   });
 | |
| 
 | |
|   context('ensure sudo', () => {
 | |
|     it('returns not authorized when user is not a sudo user', () => {
 | |
|       res.locals = {user: {contributor: {sudo: false}}};
 | |
| 
 | |
|       ensureSudo(req, res, next);
 | |
| 
 | |
|       expect(next).to.be.calledWith(new NotAuthorized(apiMessages('noSudoAccess')));
 | |
|     });
 | |
| 
 | |
|     it('passes when user is a sudo user', () => {
 | |
|       res.locals = {user: {contributor: {sudo: true}}};
 | |
| 
 | |
|       ensureSudo(req, res, next);
 | |
| 
 | |
|       expect(next).to.be.calledOnce;
 | |
|       expect(next.args[0]).to.be.empty;
 | |
|     });
 | |
|   });
 | |
| });
 |