-
Notifications
You must be signed in to change notification settings - Fork 36
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
483c7f3
commit 216aa3c
Showing
9 changed files
with
176 additions
and
8 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,41 @@ | ||
import { createAppClient } from "../../clients/createAppClient"; | ||
import { jest } from "@jest/globals"; | ||
import { viem } from "../../clients/ethereum/viem"; | ||
|
||
describe("status", () => { | ||
const client = createAppClient({ | ||
relayURI: "https://connect.farcaster.xyz", | ||
ethereum: viem(), | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
test("", async () => { | ||
const pending1 = new Response(JSON.stringify({ state: "pending" }), { | ||
status: 202, | ||
}); | ||
const pending2 = new Response(JSON.stringify({ state: "pending" }), { | ||
status: 202, | ||
}); | ||
const completed = new Response(JSON.stringify({ state: "completed" })); | ||
const fetchSpy = jest | ||
.spyOn(global, "fetch") | ||
.mockResolvedValueOnce(pending1) | ||
.mockResolvedValueOnce(pending2) | ||
.mockResolvedValueOnce(completed); | ||
|
||
const callbackSpy = jest.fn(); | ||
|
||
const res = await client.watchStatus({ | ||
channelToken: "some-channel-token", | ||
onResponse: callbackSpy, | ||
}); | ||
|
||
expect(res.response.status).toEqual(200); | ||
expect(res.data).toEqual({ state: "completed" }); | ||
expect(fetchSpy).toHaveBeenCalledTimes(3); | ||
expect(callbackSpy).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
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,41 @@ | ||
import { Client } from "../../clients/createClient"; | ||
import { AsyncHttpResponse, poll, HttpResponse } from "../../clients/transports/http"; | ||
|
||
export interface WatchStatusArgs { | ||
channelToken: string; | ||
timeout?: number; | ||
interval?: number; | ||
onResponse?: (response: HttpResponse<StatusAPIResponse>) => void; | ||
} | ||
|
||
export type WatchStatusResponse = AsyncHttpResponse<StatusAPIResponse>; | ||
|
||
interface StatusAPIResponse { | ||
state: "pending" | "completed"; | ||
nonce: string; | ||
connectURI: string; | ||
message?: string; | ||
signature?: `0x${string}`; | ||
fid?: number; | ||
username?: string; | ||
bio?: string; | ||
displayName?: string; | ||
pfpUrl?: string; | ||
} | ||
|
||
const path = "connect/status"; | ||
|
||
const voidCallback = () => {}; | ||
|
||
export const watchStatus = async (client: Client, args: WatchStatusArgs): WatchStatusResponse => { | ||
return poll<StatusAPIResponse>( | ||
client, | ||
path, | ||
{ | ||
timeout: args?.timeout ?? 10000, | ||
interval: args?.interval ?? 1000, | ||
onResponse: args?.onResponse ?? voidCallback, | ||
}, | ||
{ authToken: args.channelToken }, | ||
); | ||
}; |
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