1
0
Fork 0
mirror of synced 2024-10-05 12:34:50 +13:00

Add basic test

This commit is contained in:
Adria Navarro 2023-05-23 10:14:06 +02:00
parent 74ea851fa3
commit 5ea19986b1

View file

@ -17,12 +17,14 @@ jest.mock("google-spreadsheet")
const { GoogleSpreadsheet } = require("google-spreadsheet")
const sheetsByTitle: { [title: string]: GoogleSpreadsheetWorksheet } = {}
const sheetsByIndex: GoogleSpreadsheetWorksheet[] = []
GoogleSpreadsheet.mockImplementation(() => {
return {
useOAuth2Client: jest.fn(),
loadInfo: jest.fn(),
sheetsByTitle,
sheetsByIndex,
}
})
@ -88,7 +90,7 @@ describe("Google Sheets Integration", () => {
}
describe("update table", () => {
test("adding a new field will be adding a new header row", async () => {
it("adding a new field will be adding a new header row", async () => {
await config.doInContext(structures.uuid(), async () => {
const tableColumns = ["name", "description", "new field"]
const table = createBasicTable(structures.uuid(), tableColumns)
@ -103,7 +105,7 @@ describe("Google Sheets Integration", () => {
})
})
test("removing an existing field will remove the header from the google sheet", async () => {
it("removing an existing field will remove the header from the google sheet", async () => {
const sheet = await config.doInContext(structures.uuid(), async () => {
const tableColumns = ["name"]
const table = createBasicTable(structures.uuid(), tableColumns)
@ -123,4 +125,20 @@ describe("Google Sheets Integration", () => {
expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(1)
})
})
describe("getTableNames", () => {
it("can fetch table names", async () => {
await config.doInContext(structures.uuid(), async () => {
const sheetNames: string[] = []
for (let i = 0; i < 5; i++) {
const sheet = createSheet({ headerValues: [] })
sheetsByIndex.push(sheet)
sheetNames.push(sheet.title)
}
const res = await integration.getTableNames()
expect(res).toEqual(sheetNames)
})
})
})
})