Skip to content

Commit e99b87f

Browse files
committed
test(useConnectQuery): add test for fetching data by unique identifier
1 parent 1136e11 commit e99b87f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

packages/react/src/data-connect/useConnectQuery.test.tsx

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { describe, expect, test, beforeEach } from "vitest";
22
import { useConnectQuery } from "./useConnectQuery";
33
import { renderHook, waitFor } from "@testing-library/react";
4-
import { listMoviesRef, createMovie } from "@/dataconnect/default-connector";
4+
import {
5+
listMoviesRef,
6+
createMovie,
7+
getMovieByIdRef,
8+
} from "@/dataconnect/default-connector";
59
import { firebaseApp } from "~/testing-utils";
610
import { queryClient, wrapper } from "../../utils";
711

@@ -104,4 +108,29 @@ describe("useConnectQuery", () => {
104108
expect(i).toHaveProperty("imageUrl");
105109
});
106110
});
111+
112+
test("fetches data by unique identifier", async () => {
113+
const movieData = {
114+
title: "tanstack query firebase",
115+
genre: "library",
116+
imageUrl: "https://invertase.io/",
117+
};
118+
const createdMovie = await createMovie(movieData);
119+
120+
const movieId = createdMovie?.data?.movie_insert?.id;
121+
122+
const { result } = renderHook(
123+
() => useConnectQuery(getMovieByIdRef({ id: movieId })),
124+
{
125+
wrapper,
126+
}
127+
);
128+
129+
await waitFor(() => {
130+
expect(result.current.isSuccess).toBe(true);
131+
expect(result.current.data?.movie?.title).toBe(movieData?.title);
132+
expect(result.current.data?.movie?.genre).toBe(movieData?.genre);
133+
expect(result.current.data?.movie?.imageUrl).toBe(movieData?.imageUrl);
134+
});
135+
});
107136
});

0 commit comments

Comments
 (0)