2021-03-09 17:07:44 +01:00
|
|
|
const fetch = jest.requireActual("node-fetch")
|
|
|
|
|
|
|
|
module.exports = async (url, opts) => {
|
2021-03-12 16:32:16 +01:00
|
|
|
function json(body, status = 200) {
|
2021-03-09 17:07:44 +01:00
|
|
|
return {
|
2021-03-12 16:32:16 +01:00
|
|
|
status,
|
2021-03-09 17:07:44 +01:00
|
|
|
json: async () => {
|
2021-03-12 16:32:16 +01:00
|
|
|
return body
|
2021-03-09 17:07:44 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-03-12 16:32:16 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
|
)
|
|
|
|
}
|
2021-03-09 17:07:44 +01:00
|
|
|
return fetch(url, opts)
|
|
|
|
}
|