microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
packages/http/test/utils.test.ts
31lines · modecode
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { extractParamsFromPath } from "../src/utils.js"; |
| 3 | |
| 4 | describe("utils", () => { |
| 5 | describe("extractParamsFromPath", () => { |
| 6 | it("parse single param", () => { |
| 7 | expect(extractParamsFromPath("foo/{name}/bar")).toEqual(["name"]); |
| 8 | }); |
| 9 | |
| 10 | it("parse param with -", () => { |
| 11 | expect(extractParamsFromPath("foo/{foo-bar}/bar")).toEqual(["foo-bar"]); |
| 12 | }); |
| 13 | |
| 14 | it("parse multiple param", () => { |
| 15 | expect(extractParamsFromPath("foo/{name}/bar/{age}")).toEqual(["name", "age"]); |
| 16 | }); |
| 17 | |
| 18 | it("parse single OData params", () => { |
| 19 | expect(extractParamsFromPath("/certificates(thumbprint={thumbprint})/canceldelete")).toEqual([ |
| 20 | "thumbprint", |
| 21 | ]); |
| 22 | }); |
| 23 | it("parse multiple OData params", () => { |
| 24 | expect( |
| 25 | extractParamsFromPath( |
| 26 | "/certificates(thumbprintAlgorithm={thumbprintAlgorithm},thumbprint={thumbprint})/canceldelete" |
| 27 | ) |
| 28 | ).toEqual(["thumbprintAlgorithm", "thumbprint"]); |
| 29 | }); |
| 30 | }); |
| 31 | }); |
| 32 | |