diff --git a/src/__tests__/client-id.test.ts b/src/__tests__/client-id.test.ts index 812a490..0c9dd00 100644 --- a/src/__tests__/client-id.test.ts +++ b/src/__tests__/client-id.test.ts @@ -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(); +}); diff --git a/src/__tests__/test-common.ts b/src/__tests__/test-common.ts index 96a1100..50d99bc 100644 --- a/src/__tests__/test-common.ts +++ b/src/__tests__/test-common.ts @@ -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: {