Add basic test

This commit is contained in:
Adria Navarro 2023-05-23 10:14:06 +02:00
parent 74ea851fa3
commit 5ea19986b1
1 changed files with 20 additions and 2 deletions

View File

@ -17,12 +17,14 @@ jest.mock("google-spreadsheet")
const { GoogleSpreadsheet } = require("google-spreadsheet") const { GoogleSpreadsheet } = require("google-spreadsheet")
const sheetsByTitle: { [title: string]: GoogleSpreadsheetWorksheet } = {} const sheetsByTitle: { [title: string]: GoogleSpreadsheetWorksheet } = {}
const sheetsByIndex: GoogleSpreadsheetWorksheet[] = []
GoogleSpreadsheet.mockImplementation(() => { GoogleSpreadsheet.mockImplementation(() => {
return { return {
useOAuth2Client: jest.fn(), useOAuth2Client: jest.fn(),
loadInfo: jest.fn(), loadInfo: jest.fn(),
sheetsByTitle, sheetsByTitle,
sheetsByIndex,
} }
}) })
@ -88,7 +90,7 @@ describe("Google Sheets Integration", () => {
} }
describe("update table", () => { 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 () => { await config.doInContext(structures.uuid(), async () => {
const tableColumns = ["name", "description", "new field"] const tableColumns = ["name", "description", "new field"]
const table = createBasicTable(structures.uuid(), tableColumns) 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 sheet = await config.doInContext(structures.uuid(), async () => {
const tableColumns = ["name"] const tableColumns = ["name"]
const table = createBasicTable(structures.uuid(), tableColumns) 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) 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)
})
})
})
}) })