Skip to content

Commit

Permalink
test(useConnectQuery): add test for fetching data by unique identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanBahati committed Dec 16, 2024
1 parent 1136e11 commit e99b87f
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion packages/react/src/data-connect/useConnectQuery.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { describe, expect, test, beforeEach } from "vitest";
import { useConnectQuery } from "./useConnectQuery";
import { renderHook, waitFor } from "@testing-library/react";
import { listMoviesRef, createMovie } from "@/dataconnect/default-connector";
import {
listMoviesRef,
createMovie,
getMovieByIdRef,
} from "@/dataconnect/default-connector";
import { firebaseApp } from "~/testing-utils";
import { queryClient, wrapper } from "../../utils";

Expand Down Expand Up @@ -104,4 +108,29 @@ describe("useConnectQuery", () => {
expect(i).toHaveProperty("imageUrl");
});
});

test("fetches data by unique identifier", async () => {
const movieData = {
title: "tanstack query firebase",
genre: "library",
imageUrl: "https://invertase.io/",
};
const createdMovie = await createMovie(movieData);

const movieId = createdMovie?.data?.movie_insert?.id;

const { result } = renderHook(
() => useConnectQuery(getMovieByIdRef({ id: movieId })),
{
wrapper,
}
);

await waitFor(() => {
expect(result.current.isSuccess).toBe(true);
expect(result.current.data?.movie?.title).toBe(movieData?.title);
expect(result.current.data?.movie?.genre).toBe(movieData?.genre);
expect(result.current.data?.movie?.imageUrl).toBe(movieData?.imageUrl);
});
});
});

0 comments on commit e99b87f

Please sign in to comment.