<commit_before>const { expect } = require('chai');
const { ObjectId } = require('mongoose').Types;
const { Forbidden, BadRequest } = require('@feathersjs/errors');
const app = require('../../../../src/app');
const testObjects = require('../../helpers/testObjects')(app);
const {
	rejectQueryingOtherUsers,
} = require('../../../../src/services/teams/hooks/scopePermissions.js');

describe.only('scopePermissionService hook', () => {
	describe('rejectQueryingOtherUsers', () => {
		const fut = rejectQueryingOtherUsers;

		it('should fail if a user requests a different user id on GET', () => {
			const userId = new ObjectId();
			const id = new ObjectId().toString();
			const params = { account: { userId } };
			expect(() => fut({ method: 'get', id, params })).to.throw(Forbidden);
		});

		it('should fail if a user requests a different user id on FIND', () => {
			const userId = new ObjectId();
			const id = new ObjectId().toString();
			const params = {
				account: { userId },
				query: { userId: id },
			};
			expect(() => fut({ method: 'find', params })).to.throw(Forbidden);
		});

		it('should fail if no user id is requested', () => {
			const userId = new ObjectId();
			const params = { account: { userId } };
			expect(() => fut({ method: 'find', params })).to.throw(BadRequest);
		});

		it('should fail for all methods except find & get', () => {
			const userId = new ObjectId();
			const params = { account: { userId } };
			expect(() => fut({ params })).to.throw(BadRequest);
		});

		it('should let external requesters only query their own userId', () => {
			const userId = new ObjectId();
			const id = userId.toString();
			const params = {
				account: { userId },
			};
			expect(() => fut({ method: 'find', params: { ...params, query: { userId: id } } })).not.to.throw();
			expect(() => fut({ method: 'get', id, params })).not.to.throw();
		});
	});
});
<commit_msg>Improve test and remove only<commit_after>const { expect } = require('chai');
const { ObjectId } = require('mongoose').Types;
const { Forbidden, BadRequest } = require('@feathersjs/errors');
const app = require('../../../../src/app');
const testObjects = require('../../helpers/testObjects')(app);
const {
	rejectQueryingOtherUsers,
} = require('../../../../src/services/teams/hooks/scopePermissions.js');

describe('scopePermissionService hook', () => {
	describe('rejectQueryingOtherUsers', () => {
		const fut = rejectQueryingOtherUsers;

		it('should fail if a user requests a different user id on GET', () => {
			const userId = new ObjectId();
			const id = new ObjectId().toString();
			const params = { account: { userId } };
			expect(() => fut({ method: 'get', id, params })).to.throw(Forbidden);
		});

		it('should fail if a user requests a different user id on FIND', () => {
			const userId = new ObjectId();
			const id = new ObjectId().toString();
			const params = {
				account: { userId },
				query: { userId: id },
			};
			expect(() => fut({ method: 'find', params })).to.throw(Forbidden);
		});

		it('should fail if no user id is requested', () => {
			const userId = new ObjectId();
			const params = { account: { userId } };
			expect(() => fut({ method: 'find', params })).to.throw(BadRequest);
		});

		it('should fail for all methods except find & get', () => {
			const userId = new ObjectId();
			const params = { account: { userId } };
			expect(() => fut({ params })).to.throw(BadRequest);
			expect(() => fut({ method: 'delete', params })).to.throw(BadRequest);
		});

		it('should let external requesters only query their own userId', () => {
			const userId = new ObjectId();
			const id = userId.toString();
			const params = {
				account: { userId },
			};
			expect(() => fut({ method: 'find', params: { ...params, query: { userId: id } } })).not.to.throw();
			expect(() => fut({ method: 'get', id, params })).not.to.throw();
		});
	});
});

{'fraction_non_alphanumeric': 0.2030404534913682, 'fraction_numerical': 0.0, 'mean_word_length': 3.503480278422274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6433832', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1183, 'n_words': 346}