2021-06-25 14:46:02 +02:00
|
|
|
module FetchMock {
|
|
|
|
const fetch = jest.requireActual("node-fetch")
|
|
|
|
|
|
|
|
module.exports = async (url: any, opts: any) => {
|
|
|
|
function json(body: any, status = 200) {
|
|
|
|
return {
|
|
|
|
status,
|
|
|
|
headers: {
|
|
|
|
get: () => {
|
|
|
|
return ["application/json"]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
json: async () => {
|
|
|
|
return body
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 11:02:24 +02:00
|
|
|
if (url.includes("/api/admin")) {
|
2021-06-25 14:46:02 +02:00
|
|
|
return json({
|
|
|
|
email: "test@test.com",
|
|
|
|
_id: "us_test@test.com",
|
|
|
|
status: "active",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// mocked data based on url
|
|
|
|
else 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
|
|
|
|
)
|
|
|
|
} else if (url.includes("_search")) {
|
|
|
|
return json({
|
|
|
|
rows: [
|
|
|
|
{
|
|
|
|
doc: {
|
|
|
|
_id: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
bookmark: "test",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return fetch(url, opts)
|
|
|
|
}
|
|
|
|
}
|