Skip to content

Commit

Permalink
chore: Bump version + liniting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehesp committed Dec 25, 2024
1 parent 950213a commit fd0a466
Show file tree
Hide file tree
Showing 46 changed files with 3,509 additions and 3,485 deletions.
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
"indentStyle": "space"
},
"organizeImports": {
"enabled": true
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"test": "vitest --dom --coverage",
"serve:coverage": "npx serve coverage",
"emulator": "firebase emulators:start --project demo-projectc",
"emulator:kill": "lsof -t -i:4001 -i:8080 -i:9000 -i:9099 -i:9199 -i:8085 | xargs kill -9"
"emulator:kill": "lsof -t -i:4001 -i:8080 -i:9000 -i:9099 -i:9199 -i:8085 | xargs kill -9",
"check": "pnpm biome check --write ./packages/react/src"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
Expand Down
10 changes: 7 additions & 3 deletions packages/react/package.json
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": {
Expand Down Expand Up @@ -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",
Expand All @@ -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"
}
}
172 changes: 86 additions & 86 deletions packages/react/src/auth/useDeleteUserMutation.test.tsx
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();
});
});
26 changes: 13 additions & 13 deletions packages/react/src/auth/useDeleteUserMutation.ts
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),
});
}
88 changes: 44 additions & 44 deletions packages/react/src/auth/useReloadMutation.test.tsx
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();
});
});
Loading

0 comments on commit fd0a466

Please sign in to comment.