-
Notifications
You must be signed in to change notification settings - Fork 70
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
Showing
46 changed files
with
3,509 additions
and
3,485 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@tanstack-query-firebase/react", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "TanStack Query bindings for Firebase and React", | ||
"type": "module", | ||
"scripts": { | ||
|
@@ -29,6 +29,10 @@ | |
"email": "[email protected]", | ||
"url": "https://github.com/invertase/tanstack-query-firebase" | ||
}, | ||
"files": [ | ||
"dist", | ||
"README.md" | ||
], | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@testing-library/react": "^16.0.1", | ||
|
@@ -37,7 +41,7 @@ | |
"@dataconnect/default-connector": "workspace:*" | ||
}, | ||
"peerDependencies": { | ||
"firebase": "^11.1.0", | ||
"@tanstack/react-query": "^5.55.4" | ||
"firebase": "^11", | ||
"@tanstack/react-query": "^5" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,101 +1,101 @@ | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { act, renderHook, waitFor } from "@testing-library/react"; | ||
import { type User, createUserWithEmailAndPassword } from "firebase/auth"; | ||
import React from "react"; | ||
import type React from "react"; | ||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; | ||
import { auth, wipeAuth } from "~/testing-utils"; | ||
import { useDeleteUserMutation } from "./useDeleteUserMutation"; | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { retry: false }, | ||
mutations: { retry: false }, | ||
}, | ||
defaultOptions: { | ||
queries: { retry: false }, | ||
mutations: { retry: false }, | ||
}, | ||
}); | ||
|
||
const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
); | ||
|
||
describe("useVerifyPasswordResetCodeMutation", () => { | ||
const email = "[email protected]"; | ||
const password = "TanstackQueryFirebase#123"; | ||
let user: User; | ||
|
||
beforeEach(async () => { | ||
queryClient.clear(); | ||
await wipeAuth(); | ||
const userCredential = await createUserWithEmailAndPassword( | ||
auth, | ||
email, | ||
password, | ||
); | ||
user = userCredential.user; | ||
}); | ||
|
||
afterEach(async () => { | ||
vi.clearAllMocks(); | ||
await auth.signOut(); | ||
}); | ||
|
||
test("successfully verifies the reset code", async () => { | ||
const { result } = renderHook(() => useDeleteUserMutation(auth), { | ||
wrapper, | ||
}); | ||
|
||
await act(async () => { | ||
result.current.mutate(user); | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(result.current.data).toBeUndefined(); | ||
}); | ||
|
||
test("resets mutation state correctly", async () => { | ||
const { result } = renderHook(() => useDeleteUserMutation(auth), { | ||
wrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.mutate(user); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(result.current.isSuccess).toBe(true); | ||
}); | ||
|
||
act(() => { | ||
result.current.reset(); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(result.current.isIdle).toBe(true); | ||
expect(result.current.data).toBeUndefined(); | ||
expect(result.current.error).toBeNull(); | ||
}); | ||
}); | ||
|
||
test("should call onSuccess when the user is successfully deleted", async () => { | ||
const onSuccess = vi.fn(); | ||
|
||
const { result } = renderHook( | ||
() => | ||
useDeleteUserMutation(auth, { | ||
onSuccess, | ||
}), | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
|
||
act(() => { | ||
result.current.mutate(user); | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(onSuccess).toHaveBeenCalledTimes(1); | ||
expect(result.current.data).toBeUndefined(); | ||
}); | ||
const email = "[email protected]"; | ||
const password = "TanstackQueryFirebase#123"; | ||
let user: User; | ||
|
||
beforeEach(async () => { | ||
queryClient.clear(); | ||
await wipeAuth(); | ||
const userCredential = await createUserWithEmailAndPassword( | ||
auth, | ||
email, | ||
password, | ||
); | ||
user = userCredential.user; | ||
}); | ||
|
||
afterEach(async () => { | ||
vi.clearAllMocks(); | ||
await auth.signOut(); | ||
}); | ||
|
||
test("successfully verifies the reset code", async () => { | ||
const { result } = renderHook(() => useDeleteUserMutation(auth), { | ||
wrapper, | ||
}); | ||
|
||
await act(async () => { | ||
result.current.mutate(user); | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(result.current.data).toBeUndefined(); | ||
}); | ||
|
||
test("resets mutation state correctly", async () => { | ||
const { result } = renderHook(() => useDeleteUserMutation(auth), { | ||
wrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.mutate(user); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(result.current.isSuccess).toBe(true); | ||
}); | ||
|
||
act(() => { | ||
result.current.reset(); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(result.current.isIdle).toBe(true); | ||
expect(result.current.data).toBeUndefined(); | ||
expect(result.current.error).toBeNull(); | ||
}); | ||
}); | ||
|
||
test("should call onSuccess when the user is successfully deleted", async () => { | ||
const onSuccess = vi.fn(); | ||
|
||
const { result } = renderHook( | ||
() => | ||
useDeleteUserMutation(auth, { | ||
onSuccess, | ||
}), | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
|
||
act(() => { | ||
result.current.mutate(user); | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(onSuccess).toHaveBeenCalledTimes(1); | ||
expect(result.current.data).toBeUndefined(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import { type UseMutationOptions, useMutation } from "@tanstack/react-query"; | ||
import { | ||
type Auth, | ||
type AuthError, | ||
type User, | ||
deleteUser, | ||
type Auth, | ||
type AuthError, | ||
type User, | ||
deleteUser, | ||
} from "firebase/auth"; | ||
|
||
type AuthUMutationOptions< | ||
TData = unknown, | ||
TError = Error, | ||
TVariables = void, | ||
TData = unknown, | ||
TError = Error, | ||
TVariables = void, | ||
> = Omit<UseMutationOptions<TData, TError, TVariables>, "mutationFn">; | ||
|
||
export function useDeleteUserMutation( | ||
auth: Auth, | ||
options?: AuthUMutationOptions<void, AuthError, User>, | ||
auth: Auth, | ||
options?: AuthUMutationOptions<void, AuthError, User>, | ||
) { | ||
return useMutation<void, AuthError, User>({ | ||
...options, | ||
mutationFn: (user: User) => deleteUser(user), | ||
}); | ||
return useMutation<void, AuthError, User>({ | ||
...options, | ||
mutationFn: (user: User) => deleteUser(user), | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,70 +1,70 @@ | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { act, renderHook, waitFor } from "@testing-library/react"; | ||
import { | ||
type User, | ||
createUserWithEmailAndPassword, | ||
signInWithEmailAndPassword, | ||
type User, | ||
createUserWithEmailAndPassword, | ||
signInWithEmailAndPassword, | ||
} from "firebase/auth"; | ||
import React from "react"; | ||
import type React from "react"; | ||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; | ||
import { auth, wipeAuth } from "~/testing-utils"; | ||
import { useReloadMutation } from "./useReloadMutation"; | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { retry: false }, | ||
mutations: { retry: false }, | ||
}, | ||
defaultOptions: { | ||
queries: { retry: false }, | ||
mutations: { retry: false }, | ||
}, | ||
}); | ||
|
||
const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
); | ||
|
||
describe("useReloadMutation", () => { | ||
const email = "[email protected]"; | ||
const password = "TanstackQueryFirebase#123"; | ||
let user: User; | ||
beforeEach(async () => { | ||
queryClient.clear(); | ||
await wipeAuth(); | ||
const userCredential = await createUserWithEmailAndPassword( | ||
auth, | ||
email, | ||
password, | ||
); | ||
user = userCredential.user; | ||
}); | ||
const email = "[email protected]"; | ||
const password = "TanstackQueryFirebase#123"; | ||
let user: User; | ||
beforeEach(async () => { | ||
queryClient.clear(); | ||
await wipeAuth(); | ||
const userCredential = await createUserWithEmailAndPassword( | ||
auth, | ||
email, | ||
password, | ||
); | ||
user = userCredential.user; | ||
}); | ||
|
||
afterEach(async () => { | ||
vi.clearAllMocks(); | ||
await auth.signOut(); | ||
}); | ||
afterEach(async () => { | ||
vi.clearAllMocks(); | ||
await auth.signOut(); | ||
}); | ||
|
||
test.sequential("should successfully reloads user data", async () => { | ||
await signInWithEmailAndPassword(auth, email, password); | ||
test.sequential("should successfully reloads user data", async () => { | ||
await signInWithEmailAndPassword(auth, email, password); | ||
|
||
const { result } = renderHook(() => useReloadMutation(), { wrapper }); | ||
const { result } = renderHook(() => useReloadMutation(), { wrapper }); | ||
|
||
act(() => result.current.mutate(user)); | ||
act(() => result.current.mutate(user)); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
}); | ||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
}); | ||
|
||
test("should handle onSuccess callback", async () => { | ||
await signInWithEmailAndPassword(auth, email, password); | ||
test("should handle onSuccess callback", async () => { | ||
await signInWithEmailAndPassword(auth, email, password); | ||
|
||
const onSuccess = vi.fn(); | ||
const { result } = renderHook(() => useReloadMutation({ onSuccess }), { | ||
wrapper, | ||
}); | ||
const onSuccess = vi.fn(); | ||
const { result } = renderHook(() => useReloadMutation({ onSuccess }), { | ||
wrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.mutate(user); | ||
}); | ||
act(() => { | ||
result.current.mutate(user); | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(onSuccess).toHaveBeenCalled(); | ||
}); | ||
expect(onSuccess).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.