MCPcopy
hub / github.com/di-sukharev/opencommit / getMockDispatch

Function getMockDispatch

out/cli.cjs:57242–57262  ·  view source on GitHub ↗
(mockDispatches, key)

Source from the content-addressed store, hash-verified

57240 if (Buffer.isBuffer(data)) {
57241 return data;
57242 } else if (typeof data === "object") {
57243 return JSON.stringify(data);
57244 } else {
57245 return data.toString();
57246 }
57247 }
57248 function getMockDispatch(mockDispatches, key) {
57249 const basePath = key.query ? buildURL2(key.path, key.query) : key.path;
57250 const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
57251 let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path5 }) => matchValue(safeUrl(path5), resolvedPath));
57252 if (matchedMockDispatches.length === 0) {
57253 throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
57254 }
57255 matchedMockDispatches = matchedMockDispatches.filter(({ method }) => matchValue(method, key.method));
57256 if (matchedMockDispatches.length === 0) {
57257 throw new MockNotMatchedError(`Mock dispatch not matched for method '${key.method}'`);
57258 }
57259 matchedMockDispatches = matchedMockDispatches.filter(({ body }) => typeof body !== "undefined" ? matchValue(body, key.body) : true);
57260 if (matchedMockDispatches.length === 0) {
57261 throw new MockNotMatchedError(`Mock dispatch not matched for body '${key.body}'`);
57262 }
57263 matchedMockDispatches = matchedMockDispatches.filter((mockDispatch2) => matchHeaders(mockDispatch2, key.headers));
57264 if (matchedMockDispatches.length === 0) {
57265 throw new MockNotMatchedError(`Mock dispatch not matched for headers '${typeof key.headers === "object" ? JSON.stringify(key.headers) : key.headers}'`);

Callers 1

mockDispatchFunction · 0.85

Calls 5

buildURL2Function · 0.85
safeUrlFunction · 0.85
matchValueFunction · 0.85
matchHeadersFunction · 0.85
filterMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…