mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 22:18:33 +00:00
Merge branch 'main' into feat/url-encoding-settings-refactor
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export { mockDataFunctions } from './utils/faker-functions';
|
||||
export { default as interpolate } from './interpolate';
|
||||
export { default as isRequestTagsIncluded } from './tags';
|
||||
|
||||
export * as utils from './utils';
|
||||
export * as utils from './utils';
|
||||
43
packages/bruno-common/src/tags/index.spec.ts
Normal file
43
packages/bruno-common/src/tags/index.spec.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import isRequestTagsIncluded from './index';
|
||||
|
||||
describe('isRequestTagsIncluded', () => {
|
||||
it('should include request when it has an included tag', () => {
|
||||
const requestTags = ['tag1', 'tag2'];
|
||||
const includeTags = ['tag1'];
|
||||
const excludeTags: string[] = [];
|
||||
const result = isRequestTagsIncluded(requestTags, includeTags, excludeTags);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should include request when included tags is empty', () => {
|
||||
const requestTags = ['tag1', 'tag2'];
|
||||
const includeTags: string[] = [];
|
||||
const excludeTags: string[] = [];
|
||||
const result = isRequestTagsIncluded(requestTags, includeTags, excludeTags);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should exclude request when it does not have an included tag', () => {
|
||||
const requestTags = ['tag1'];
|
||||
const includeTags = ['tag2'];
|
||||
const excludeTags: string[] = [];
|
||||
const result = isRequestTagsIncluded(requestTags, includeTags, excludeTags);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should exclude request when it has an excluded tag', () => {
|
||||
const requestTags = ['tag1'];
|
||||
const includeTags: string[] = [];
|
||||
const excludeTags = ['tag1'];
|
||||
const result = isRequestTagsIncluded(requestTags, includeTags, excludeTags);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should exclude request when it has both included and excluded tag', () => {
|
||||
const requestTags = ['tag1', 'tag2'];
|
||||
const includeTags: string[] = ['tag2'];
|
||||
const excludeTags = ['tag1'];
|
||||
const result = isRequestTagsIncluded(requestTags, includeTags, excludeTags);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
13
packages/bruno-common/src/tags/index.ts
Normal file
13
packages/bruno-common/src/tags/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* A request should be included if it has at least one tag that is included and no tags that are excluded
|
||||
* @param requestTags Tags of the request
|
||||
* @param includeTags Tags to include
|
||||
* @param excludeTags Tags to exclude
|
||||
*/
|
||||
export const isRequestTagsIncluded = (requestTags: string[], includeTags: string[], excludeTags: string[]) => {
|
||||
const shouldInclude = includeTags.length === 0 || requestTags.some((tag) => includeTags.includes(tag));
|
||||
const shouldExclude = excludeTags.length > 0 && requestTags.some((tag) => excludeTags.includes(tag));
|
||||
return shouldInclude && !shouldExclude;
|
||||
};
|
||||
|
||||
export default isRequestTagsIncluded;
|
||||
Reference in New Issue
Block a user