Skip to content

Commit

Permalink
Add mocked test (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyll authored Feb 26, 2024
1 parent 798f713 commit 179be26
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/__tests__/client-id.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
require("dotenv").config();
import fetch from "cross-fetch";

import { appWithClient } from "./test-common";
import { appWithClient, tableWithClient } from "./test-common";

test("sanity", async () => {
jest.mock("cross-fetch", () => jest.fn(jest.requireActual("cross-fetch") as any));

test("sanity - get named table", async () => {
const table = await appWithClient.getTableNamed("Things");
const spy = (fetch as jest.Mock).mockImplementationOnce(fetch);
const clientID = spy.mock.calls[0][1]["headers"]["X-Glide-Client-ID"];
expect(clientID).toBeDefined();
expect(clientID).toEqual(process.env.GLIDE_CLIENT_ID);
expect(table).toBeDefined();
});

test("sanity - get named table", async () => {
const {
data: { columns },
} = await tableWithClient.getSchema();
const spy = (fetch as jest.Mock).mockImplementationOnce(fetch);
const clientID = spy.mock.calls[0][1]["headers"]["X-Glide-Client-ID"];
expect(clientID).toBeDefined();
expect(clientID).toEqual(process.env.GLIDE_CLIENT_ID);
expect(columns).toBeDefined();
});
9 changes: 9 additions & 0 deletions src/__tests__/test-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export const table = app.table({
},
});

export const tableWithClient = appWithClient.table({
table: "native-table-MX8xNW5WWoJhW4fwEeN7",
columns: {
name: { type: "string", name: "Name" },
stock: { type: "number", name: "Description" },
renamed: { type: "string", name: "yPXU2" },
},
});

export const bigTable = app.table({
table: "native-table-9500db9c-fa75-4968-82e3-9d53437893e8",
columns: {
Expand Down

0 comments on commit 179be26

Please sign in to comment.