Skip to content

Commit 90f2dd1

Browse files
adding more tests to improve coverage of a regex helper
1 parent 7febd46 commit 90f2dd1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/helpers/Regex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function escapeSearchSpecialCharacters(value: string): string {
137137
return value.replace(SEARCH_SPECIAL_CHARACTERS_REGEX, "\\$&");
138138
}
139139

140-
const PREFER_CALLBACK_URL_REGEX = /^odata\.callback;\s*url=["']?(.+)["']?$/;
140+
const PREFER_CALLBACK_URL_REGEX = /^odata\.callback;\s*url=["']?(.+?)["']?$/;
141141
export function extractPreferCallbackUrl(value: string): string | null {
142142
const match = PREFER_CALLBACK_URL_REGEX.exec(value);
143143
return match ? match[1] : null;

tests/common.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe("Regex.", () => {
4444
expect(result3).to.be.null;
4545
});
4646
});
47+
4748
describe("extractUuidFromUrl -", function () {
4849
it("uuid", function () {
4950
const result = Regex.extractUuidFromUrl(mocks.webApiUrl + "tests(fb15ee32-524d-41be-b6a0-7d0f28055d52)");
@@ -56,6 +57,32 @@ describe("Regex.", () => {
5657
expect(result2).to.be.null;
5758
});
5859
});
60+
61+
describe("extractPreferCallbackUrl -", function () {
62+
it("url", function () {
63+
const result = Regex.extractPreferCallbackUrl('odata.callback;url="https://test.com"');
64+
expect(result).to.equal("https://test.com");
65+
});
66+
it("not url - returns null", function () {
67+
const result = Regex.extractPreferCallbackUrl("something");
68+
expect(result).to.be.null;
69+
});
70+
});
71+
72+
describe("getUpdateMethod -", function () {
73+
it("PATCH", function () {
74+
const result = Regex.getUpdateMethod("anything");
75+
expect(result).to.equal("PATCH");
76+
});
77+
it("PUT", function () {
78+
const result = Regex.getUpdateMethod("EntityDefinitions");
79+
expect(result).to.equal("PUT");
80+
});
81+
it("not PUT or PATCH - returns null", function () {
82+
const result = Regex.getUpdateMethod(null);
83+
expect(result).to.equal("PATCH");
84+
});
85+
});
5986
});
6087

6188
describe("RequestClient.sendRequest", () => {

0 commit comments

Comments
 (0)