Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Oct 20, 2022
1 parent b9f9c1e commit 3e3b940
Showing 1 changed file with 73 additions and 17 deletions.
90 changes: 73 additions & 17 deletions tests/helpers/parse-match-props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,83 @@ const name = 'scriptlets-redirects helpers';

module(name);

test('Test parseMatchProps for working with different url inputs', (assert) => {
const URL_INPUT_1 = 'example.com';
const URL_INPUT_2 = 'http://example.com';
const URL_INPUT_3 = '/^https?://example.org/';
const URL_INPUT_4 = '/^https?://example.org/section#user:45/comments/';
const GET_METHOD = 'GET';
const METHOD_PROP = 'method';
const URL_PROP = 'url';

const GET_METHOD = 'GET';
const MIXED_INPUT = `url:${URL_INPUT_4} method:${GET_METHOD}`;
const URL1 = 'example.com';
const URL2 = 'http://example.com';
const URL3 = '/^https?://example.org/';
const URL4 = '/^https?://example.org/section#user:45/comments/';

assert.ok(parseMatchProps(URL_INPUT_1).url, URL_INPUT_1, 'No url match prop, no protocol, not regexp');
assert.ok(parseMatchProps(`url: ${URL_INPUT_1}`).url, URL_INPUT_1, 'url match prop, no protocol, not regexp');
test('Test different url props, simple input', (assert) => {
assert.ok(parseMatchProps(URL1).url, URL1, 'No url match prop, no protocol, not regexp');
assert.ok(parseMatchProps(`url: ${URL1}`).url, URL1, 'url match prop, no protocol, not regexp');

assert.ok(parseMatchProps(URL_INPUT_2).url, URL_INPUT_2, 'No url match prop, has protocol, not regexp');
assert.ok(parseMatchProps(`url: ${URL_INPUT_2}`).url, URL_INPUT_2, 'url match prop, has protocol, not regexp');
assert.ok(parseMatchProps(URL2).url, URL2, 'No url match prop, has protocol, not regexp');
assert.ok(parseMatchProps(`url: ${URL2}`).url, URL2, 'url match prop, has protocol, not regexp');

assert.ok(parseMatchProps(URL_INPUT_3).url, URL_INPUT_3, 'No url match prop, has protocol, regexp');
assert.ok(parseMatchProps(`url: ${URL_INPUT_3}`).url, URL_INPUT_3, 'url match prop, has protocol, regexp');
assert.ok(parseMatchProps(URL3).url, URL3, 'No url match prop, has protocol, regexp');
assert.ok(parseMatchProps(`url: ${URL3}`).url, URL3, 'url match prop, has protocol, regexp');

assert.ok(parseMatchProps(URL_INPUT_4).url, URL_INPUT_4, 'No url match prop, has protocol, regexp, extra colon in url');
assert.ok(parseMatchProps(`url: ${URL_INPUT_4}`).url, URL_INPUT_4, 'url match prop, has protocol, extra colon in url');
assert.ok(parseMatchProps(URL4).url, URL4, 'No url match prop, has protocol, regexp, extra colon in url');
assert.ok(parseMatchProps(`url: ${URL4}`).url, URL4, 'url match prop, has protocol, extra colon in url');
});

test('Test different url props, mixed input', (assert) => {
const INPUT1 = `${URL1} ${METHOD_PROP}:${GET_METHOD}`;
const expected1 = {
url: URL1,
[METHOD_PROP]: GET_METHOD,
};
assert.deepEqual(parseMatchProps(INPUT1), expected1, 'No url match prop, no protocol, not regexp');

const INPUT1_PREFIXED = `${URL_PROP}:${URL1} ${METHOD_PROP}:${GET_METHOD}`;
const expectedPrefixed1 = {
url: URL1,
[METHOD_PROP]: GET_METHOD,
};
assert.deepEqual(parseMatchProps(INPUT1_PREFIXED), expectedPrefixed1, 'Has url match prop, no protocol, not regexp');

const INPUT2 = `${URL2} ${METHOD_PROP}:${GET_METHOD}`;
const expected2 = {
url: URL2,
[METHOD_PROP]: GET_METHOD,
};
assert.deepEqual(parseMatchProps(INPUT2), expected2, 'No url match prop, has protocol, not regexp');

const INPUT2_PREFIXED = `${URL_PROP}:${URL2} ${METHOD_PROP}:${GET_METHOD}`;
const expectedPrefixed2 = {
url: URL2,
[METHOD_PROP]: GET_METHOD,
};
assert.deepEqual(parseMatchProps(INPUT2_PREFIXED), expectedPrefixed2, 'Has url match prop, has protocol, not regexp');

const INPUT3 = `${URL3} ${METHOD_PROP}:${GET_METHOD}`;
const expected3 = {
url: URL3,
[METHOD_PROP]: GET_METHOD,
};
assert.deepEqual(parseMatchProps(INPUT3), expected3, 'No url match prop, has protocol, regexp');

const INPUT3_PREFIXED = `${URL_PROP}:${URL3} ${METHOD_PROP}:${GET_METHOD}`;
const expectedPrefixed3 = {
url: URL3,
[METHOD_PROP]: GET_METHOD,
};
assert.deepEqual(parseMatchProps(INPUT3_PREFIXED), expectedPrefixed3, 'Has url match prop, has protocol, regexp');

const INPUT4 = `${URL4} ${METHOD_PROP}:${GET_METHOD}`;
const expected4 = {
url: URL4,
[METHOD_PROP]: GET_METHOD,
};
assert.deepEqual(parseMatchProps(INPUT4), expected4, 'No url match prop, has protocol, regexp, extra colon in url');

assert.ok(parseMatchProps(MIXED_INPUT).url, URL_INPUT_4, 'Mixed input, url is parsed correctly');
assert.ok(parseMatchProps(MIXED_INPUT).method, GET_METHOD, 'Mixed input, method is parsed correctly');
const INPUT4_PREFIXED = `${URL_PROP}:${URL4} ${METHOD_PROP}:${GET_METHOD}`;
const expectedPrefixed4 = {
url: URL4,
[METHOD_PROP]: GET_METHOD,
};
assert.deepEqual(parseMatchProps(INPUT4_PREFIXED), expectedPrefixed4, 'Has url match prop, has protocol, regexp, extra colon in url');
});

0 comments on commit 3e3b940

Please sign in to comment.