This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62d0a6b
commit 51503e2
Showing
18 changed files
with
589 additions
and
228 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import React from "react"; | ||
|
||
import { EnvironmentProvider } from "./Environment"; | ||
|
||
describe("Environment Context", () => { | ||
it("should render the wrapper properly", async () => { | ||
const { container, asFragment } = render( | ||
<EnvironmentProvider> | ||
<span>Provider testing</span> | ||
</EnvironmentProvider>, | ||
); | ||
|
||
await waitFor(async () => { | ||
await expect(screen.findByText("Provider testing")).resolves.toBeInTheDocument(); | ||
}); | ||
|
||
expect(container).toBeTruthy(); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); |
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,21 @@ | ||
// Coins | ||
import { ARK } from "@arkecosystem/platform-sdk-ark"; | ||
// Env | ||
import { Environment } from "@arkecosystem/platform-sdk-profiles"; | ||
// Services | ||
import { httpClient } from "app/services"; | ||
import React, { createContext } from "react"; | ||
|
||
type Props = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
const EnvironmentContext = createContext({}); | ||
|
||
const EnvironmentProvider = ({ children }: Props) => { | ||
const env: Environment = new Environment({ coins: { ARK }, httpClient, storage: "indexeddb" }); | ||
|
||
return <EnvironmentContext.Provider value={{ env }}>{children}</EnvironmentContext.Provider>; | ||
}; | ||
|
||
export { EnvironmentContext, EnvironmentProvider }; |
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,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Environment Context should render the wrapper properly 1`] = ` | ||
<DocumentFragment> | ||
<span> | ||
Provider testing | ||
</span> | ||
</DocumentFragment> | ||
`; |
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 @@ | ||
export * from "./Environment"; |
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,55 @@ | ||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
|
||
import { HttpClient } from "./HttpClient"; | ||
|
||
jest.mock("axios", () => ({ | ||
create: () => ({ | ||
get: () => jest.fn(), | ||
post: () => jest.fn(), | ||
}), | ||
})); | ||
|
||
let subject: HttpClient; | ||
|
||
beforeEach(() => (subject = new HttpClient())); | ||
|
||
describe("HttpClient", () => { | ||
beforeEach(() => { | ||
jest.spyOn(subject, "get"); | ||
jest.spyOn(subject, "post"); | ||
}); | ||
|
||
it("should get without params", async () => { | ||
await subject.get("/hello-world"); | ||
|
||
expect(subject.get).toHaveBeenCalledWith("/hello-world"); | ||
}); | ||
|
||
it("should get with params", async () => { | ||
await subject.get("/hello-world", { q: "my-param" }); | ||
|
||
expect(subject.get).toHaveBeenCalledWith("/hello-world", { q: "my-param" }); | ||
}); | ||
|
||
it("should post without params", async () => { | ||
await subject.post("/hello-world", { key: "value" }); | ||
|
||
expect(subject.post).toHaveBeenCalledWith("/hello-world", { key: "value" }); | ||
}); | ||
|
||
it("should post without headers", async () => { | ||
await subject.post("/hello-world", { name: "my-param" }); | ||
|
||
expect(subject.post).toHaveBeenCalledWith("/hello-world", { name: "my-param" }); | ||
}); | ||
|
||
it("should post without headers", async () => { | ||
await subject.post("/hello-world", { name: "my-param" }, { authorization: "Bearer bear" }); | ||
|
||
expect(subject.post).toHaveBeenCalledWith( | ||
"/hello-world", | ||
{ name: "my-param" }, | ||
{ authorization: "Bearer bear" }, | ||
); | ||
}); | ||
}); |
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,22 @@ | ||
import { Contracts } from "@arkecosystem/platform-sdk"; | ||
import axios, { AxiosInstance, AxiosRequestConfig } from "axios"; | ||
|
||
export class HttpClient implements Contracts.HttpClient { | ||
readonly client: AxiosInstance; | ||
|
||
public constructor() { | ||
const config: AxiosRequestConfig = { | ||
timeout: 2000, | ||
}; | ||
|
||
this.client = axios.create(config); | ||
} | ||
|
||
public async get(path: string, query: object = {}): Promise<Record<string, any>> { | ||
return await this.client.get(path, { params: { ...query } }); | ||
} | ||
|
||
public async post(path: string, body: object, headers: object = {}) { | ||
return await this.client.post(path, { body, headers }); | ||
} | ||
} |
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,3 @@ | ||
import { HttpClient } from "./HttpClient"; | ||
|
||
export const httpClient = new HttpClient(); |
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
Oops, something went wrong.