-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added the getHealthyProvidersWhiteList helper for requestors
So that they are able to use it with the whitelisting filters and work with a healthy provider JST-468.
- Loading branch information
Showing
6 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { MockPropertyPolicy, imock, instance, when } from "@johanblumenberg/ts-mockito"; | ||
|
||
import { getHealthyProvidersWhiteList } from "./helpers"; | ||
|
||
const mockFetch = jest.spyOn(global, "fetch"); | ||
const response = imock<Response>(); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe("Market Helpers", () => { | ||
describe("Getting public healthy providers whitelist", () => { | ||
describe("Positive cases", () => { | ||
test("Will return the list returned by the endpoint", async () => { | ||
// Given | ||
when(response.json()).thenResolve(["0xAAA", "0xBBB"]); | ||
mockFetch.mockResolvedValue(instance(response)); | ||
|
||
// When | ||
const data = await getHealthyProvidersWhiteList(); | ||
|
||
// Then | ||
expect(data).toEqual(["0xAAA", "0xBBB"]); | ||
}); | ||
}); | ||
|
||
describe("Negative cases", () => { | ||
test("If the request will be made, but will not be a successful one, it will return an empty array", async () => { | ||
// Given | ||
const mockResponse = imock<Response>(MockPropertyPolicy.StubAsProperty); | ||
when(mockResponse.ok).thenReturn(false); | ||
mockFetch.mockResolvedValue(instance(mockResponse)); | ||
|
||
// When | ||
const data = await getHealthyProvidersWhiteList(); | ||
|
||
// Then | ||
expect(data).toEqual([]); | ||
}); | ||
|
||
test("If the implementation will throw any kind of error, then it will return an empty array", async () => { | ||
// Given | ||
mockFetch.mockImplementation(() => { | ||
throw new Error("Something went wrong really bad!"); | ||
}); | ||
|
||
// When | ||
const data = await getHealthyProvidersWhiteList(); | ||
|
||
// Then | ||
expect(data).toEqual([]); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export async function getHealthyProvidersWhiteList(): Promise<string[]> { | ||
try { | ||
const response = await fetch("https://provider-health.golem.network/v1/provider-whitelist"); | ||
|
||
if (response.ok) { | ||
return response.json(); | ||
} else { | ||
const body = await response.text(); | ||
console.error("Request to download healthy provider whitelist failed.", body); | ||
|
||
return []; | ||
} | ||
} catch (err) { | ||
console.error("Failed to download healthy provider whitelist due to an error", err); | ||
|
||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters