Improve test

This commit is contained in:
Adria Navarro 2023-05-23 10:17:42 +02:00
parent 5ea19986b1
commit b7b604ca00
1 changed files with 11 additions and 8 deletions

View File

@ -18,15 +18,14 @@ const { GoogleSpreadsheet } = require("google-spreadsheet")
const sheetsByTitle: { [title: string]: GoogleSpreadsheetWorksheet } = {} const sheetsByTitle: { [title: string]: GoogleSpreadsheetWorksheet } = {}
const sheetsByIndex: GoogleSpreadsheetWorksheet[] = [] const sheetsByIndex: GoogleSpreadsheetWorksheet[] = []
const mockGoogleIntegration = {
GoogleSpreadsheet.mockImplementation(() => {
return {
useOAuth2Client: jest.fn(), useOAuth2Client: jest.fn(),
loadInfo: jest.fn(), loadInfo: jest.fn(),
sheetsByTitle, sheetsByTitle,
sheetsByIndex, sheetsByIndex,
} }
})
GoogleSpreadsheet.mockImplementation(() => mockGoogleIntegration)
import { structures } from "@budibase/backend-core/tests" import { structures } from "@budibase/backend-core/tests"
import TestConfiguration from "../../tests/utilities/TestConfiguration" import TestConfiguration from "../../tests/utilities/TestConfiguration"
@ -55,6 +54,8 @@ describe("Google Sheets Integration", () => {
}, },
}) })
await config.init() await config.init()
jest.clearAllMocks()
}) })
function createBasicTable(name: string, columns: string[]): Table { function createBasicTable(name: string, columns: string[]): Table {
@ -137,6 +138,8 @@ describe("Google Sheets Integration", () => {
} }
const res = await integration.getTableNames() const res = await integration.getTableNames()
expect(mockGoogleIntegration.loadInfo).toBeCalledTimes(1)
expect(res).toEqual(sheetNames) expect(res).toEqual(sheetNames)
}) })
}) })