alfresco-ng2-components/lib/js-api/test/path-matcher.spec.ts
Denys Vuika ea2c0ce229
[PRODENG-211] integrate JS-API with monorepo (part 1) (#9081)
* integrate JS-API with monorepo

* [ci:force] fix token issue

[ci:force] migrate docs folder

[ci:force] clean personal tokens

* [ci:force] gha workflow support

* [ci:force] npm publish target

* fix js-api test linting

* [ci:force] fix test linting, mocks, https scheme

* [ci:force] fix https scheme

* [ci:force] typescript mappings

* [ci:force] update scripts

* lint fixes

* linting fixes

* fix linting

* [ci:force] linting fixes

* linting fixes

* [ci:force] remove js-api upstream and corresponding scripts

* [ci:force] jsdoc fixes

* fix jsdoc linting

* [ci:force] jsdoc fixes

* [ci:force] jsdoc fixes

* jsdoc fixes

* jsdoc fixes

* jsdoc fixes

* [ci:force] fix jsdoc

* [ci:force] reduce code duplication

* replace 'chai' expect with node.js assert

* replace 'chai' expect with node.js assert

* [ci:force] remove chai and chai-spies for js-api testing

* [ci:force] cleanup and fix imports

* [ci:force] fix linting

* [ci:force] fix unit test

* [ci:force] fix sonar linting findings

* [ci:force] switch activiti api models to interfaces (-2.5% reduction of bundle)

* [ci:force] switch activiti api models to interfaces

* [ci:force] switch AGS api models to interfaces

* [ci:force] switch AGS api models to interfaces

* [ci:force] switch search api models to interfaces

* [ci:force] switch content api models to interfaces where applicable
2023-11-21 05:27:51 -05:00

102 lines
5.3 KiB
TypeScript

/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import assert from 'assert';
import { PathMatcher } from '../src/utils/path-matcher';
describe('PathMatcher', () => {
const pathPatcher = new PathMatcher();
describe('match', () => {
it('should return true if path is exactly the same like pattern', () => {
assert.equal(pathPatcher.match('public-url', 'public-url'), true);
});
it('should return false if path is not equal to pattern', () => {
assert.equal(pathPatcher.match('some-public-url', 'public-url'), false);
});
it('should return true if absolute path is equal to absolute path', () => {
assert.equal(pathPatcher.match('https://some-public-url', 'https://some-public-url'), true);
});
it('should return true if path matches pattern containing double and single *', () => {
assert.equal(pathPatcher.match('https://some-public-url/123/path', '**/some-public-url/*/path'), true);
});
it('should return true if path matches to pattern after replacing ** with multiple parts at the beginning', () => {
assert.equal(pathPatcher.match('https://test/other-test/some-public-url/path', '**/some-public-url/path'), true);
});
it('should return true if path matches to pattern after replacing ** with multiple parts at the beginning', () => {
assert.equal(pathPatcher.match('https://test/other-test/some-public-url/path', '**/some-public-url/path'), true);
});
it('should return true if path matches to pattern after replacing ** with multiple parts at the end', () => {
assert.equal(pathPatcher.match('https://some-public-url/path/test/other-test', 'https://some-public-url/path/**'), true);
});
it('should return true if path matches to pattern after replacing ** with none parts at the end', () => {
assert.equal(pathPatcher.match('https://some-public-url/path/', 'https://some-public-url/path/**'), true);
});
it('should return false if path does not match to pattern after replacing ** with none parts at the end and cuts last /', () => {
assert.equal(pathPatcher.match('https://some-public-url/path', 'https://some-public-url/path/**'), false);
});
it('should return true if path matches to pattern after replacing ** with multiple parts in the middle', () => {
assert.equal(pathPatcher.match('https://some-public-url/test/other-test/path', 'https://some-public-url/**/path'), true);
});
it('should return true if path matches to pattern after replacing ** with none parts in the middle', () => {
assert.equal(pathPatcher.match('https://some-public-url/path', 'https://some-public-url/**/path'), true);
});
it('should return false if path does not match to pattern with **', () => {
assert.equal(pathPatcher.match('https://some-public-url/', 'https://some-public-url/**/path'), false);
});
it('should return false if path has more than one part as replacement for * in the middle of pattern', () => {
assert.equal(pathPatcher.match('https://some-public-url/123/test/path', 'https://some-public-url/*/path'), false);
});
it('should return false if path has zero parts as replacement for * in the middle of pattern', () => {
assert.equal(pathPatcher.match('https://some-public-url/path', 'https://some-public-url/*/path'), false);
});
it('should return true if path matches to pattern containing * at the end', () => {
assert.equal(pathPatcher.match('https://some-public-url/path/test', 'https://some-public-url/path/*'), true);
});
it('should return false if path matches to pattern containing * at the end and cuts last /', () => {
assert.equal(pathPatcher.match('https://some-public-url/path', 'https://some-public-url/path/*'), false);
});
it('should return false if path has more than one part as replacement for * at the end of pattern', () => {
assert.equal(pathPatcher.match('https://some-public-url/path/test/other-test', 'https://some-public-url/path/*'), false);
});
it('should return false if path has zero parts as replacement for * at the end of pattern', () => {
assert.equal(pathPatcher.match('https://some-public-url/path/test/other-test', 'https://some-public-url/path/*'), false);
});
it('should return false if path starts with https:// and * is at the beginning of pattern', () => {
assert.equal(pathPatcher.match('https://some-public-url/path/test', '*/some-public-url/path'), false);
});
});
});