Skip to content

Commit 7d1a5dc

Browse files
committed
Add test to ensure it picks the most specific one
1 parent c40fd8c commit 7d1a5dc

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

library/helpers/matchEndpoint.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,51 @@ t.test("it matches wildcard route with specific method", async () => {
223223
}
224224
);
225225
});
226+
227+
t.test("it prefers specific route over wildcard", async () => {
228+
t.same(
229+
matchEndpoint(
230+
{
231+
...context,
232+
route: undefined,
233+
method: "POST",
234+
url: "http://localhost:4000/api/coach",
235+
},
236+
[
237+
{
238+
method: "*",
239+
route: "/api/*",
240+
forceProtectionOff: false,
241+
rateLimiting: {
242+
enabled: true,
243+
maxRequests: 20,
244+
windowSizeInMS: 60000,
245+
},
246+
},
247+
{
248+
method: "POST",
249+
route: "/api/coach",
250+
forceProtectionOff: false,
251+
rateLimiting: {
252+
enabled: true,
253+
maxRequests: 100,
254+
windowSizeInMS: 60000,
255+
},
256+
},
257+
]
258+
),
259+
{
260+
endpoint: {
261+
method: "POST",
262+
route: "/api/coach",
263+
forceProtectionOff: false,
264+
rateLimiting: {
265+
enabled: true,
266+
maxRequests: 100,
267+
windowSizeInMS: 60000,
268+
},
269+
},
270+
route: "/api/coach",
271+
}
272+
);
273+
});

0 commit comments

Comments
 (0)