Skip to content

ci: adds additional test cases #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 22, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,53 @@ import { test } from '../src/index.js';
describe('test', function () {
it('should detect as path template', function () {
assert.isTrue(test('/{path}'));
// trailing slash is allowed
assert.isTrue(test('/{path}/'));
assert.isTrue(test('/pets/{petId}'));
assert.isTrue(test('/{entity}/me'));
assert.isTrue(test('/books/{id}'));
assert.isTrue(test('/a{test}'));
assert.isTrue(test('/{test}a'));
// parentheses are allowed
assert.isTrue(test('/range({x},{y})'));
// repeated parameter names are allowed
assert.isTrue(test('/range({x},{y})/secondRange({x},{y})'));
assert.isTrue(test('/{entity}/{another-entity}/me'));
// NOTE: the following scenario should probably be considered invalid, query parameters are not allowed in path templates
assert.isTrue(test('/pets?offset=0&limit=10'));
// -->
assert.isTrue(test('/'));
// special characters in literal are allowed
assert.isTrue(test('/-/'));
assert.isTrue(test('/~/'));
// NOTE: the following scenario should probably be considered invalid, fragments are not allowed in path templates
assert.isTrue(test('/#baz'));
// NOTE: the following scenarios should probably be considered invalid, should we allow RFC 6570 operators in parameter names?
assert.isTrue(test('/{+baz}'));
assert.isTrue(test('/{;baz}'));
assert.isTrue(test('/{&baz}'));
assert.isTrue(test('/{.baz}'));
assert.isTrue(test('/{count*}'));
assert.isTrue(test('/{y,x}'), '/{y,x}');
// NOTE: the following scenarios should probably be considered invalid due to the use of special characters
assert.isTrue(test('/{foo:baz}'));
assert.isTrue(test('/{=baz}'));
assert.isTrue(test('/{$baz}'));
assert.isTrue(test('/{~baz}'));
// -->
assert.isTrue(test('/%20'));
assert.isTrue(test('/functions/t_Dist_2T'));
assert.isTrue(test('/users/$count'));
assert.isTrue(test('/users/delta()'));
assert.isTrue(test('/directoryObjects/microsoft.graph.user'));
assert.isTrue(test('/applications(appId=\'{appId}\')'));
assert.isTrue(test('/communications/onlineMeetings/getAllRecordings(meetingOrganizerUserId=\'@meetingOrganizerUserId\')'));
// special characters in parameter names are allowed
assert.isTrue(test('/users/{user-id}'));
});

it('should not detect expression', function () {
assert.isFalse(test('//'));
assert.isFalse(test(''));
assert.isFalse(test('1'));
assert.isFalse(test('{petId}'));
Expand All @@ -24,6 +61,18 @@ describe('test', function () {
assert.isFalse(test(1));
assert.isFalse(test(null));
assert.isFalse(test(undefined));
// special characters in parameter names are not allowed
assert.isFalse(test('/{#baz}'));
assert.isFalse(test('/{?baz}'));
assert.isFalse(test('/{/baz}'));
assert.isFalse(test('/{foo baz}'));
assert.isFalse(test('/{|baz}'));
assert.isFalse(test('/{^baz}'));
assert.isFalse(test('/{`baz}'));
assert.isFalse(test('/{❤️}'));
assert.isFalse(test('/{%}'));
// special characters in literals are not allowed
assert.isFalse(test('/❤️'));
});

context('given strict option', function () {
Expand Down