1
0
Fork 0
mirror of synced 2024-07-02 13:01:09 +12:00
budibase/packages/server/__mocks__/node-fetch.js
Martin McKeaveney b7a230065b more branch cov
2021-03-16 19:27:18 +00:00

36 lines
629 B
JavaScript

const fetch = jest.requireActual("node-fetch")
module.exports = async (url, opts) => {
function json(body, status = 200) {
return {
status,
json: async () => {
return body
},
}
}
// mocked data based on url
if (url.includes("api/apps")) {
return json({
app1: {
url: "/app1",
},
})
} else if (url.includes("test.com")) {
return json({
body: opts.body,
url,
method: opts.method,
})
} else if (url.includes("invalid.com")) {
return json(
{
invalid: true,
},
404
)
}
return fetch(url, opts)
}