|
1 | 1 | import { describe, expect, test, beforeEach } from "vitest";
|
2 | 2 | import { useConnectQuery } from "./useConnectQuery";
|
3 | 3 | 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"; |
5 | 9 | import { firebaseApp } from "~/testing-utils";
|
6 | 10 | import { queryClient, wrapper } from "../../utils";
|
7 | 11 |
|
@@ -104,4 +108,29 @@ describe("useConnectQuery", () => {
|
104 | 108 | expect(i).toHaveProperty("imageUrl");
|
105 | 109 | });
|
106 | 110 | });
|
| 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 | + }); |
107 | 136 | });
|
0 commit comments