budibase/packages/server/src/integrations/tests/googlesheets.spec.ts

88 lines
2.0 KiB
TypeScript
Raw Normal View History

import { setEnv as setCoreEnv } from "@budibase/backend-core"
import nock from "nock"
import TestConfiguration from "../../tests/utilities/TestConfiguration"
2024-09-04 15:21:25 +02:00
import {
Datasource,
FieldType,
SourceName,
TableSourceType,
} from "@budibase/types"
import { access } from "node:fs"
import { GoogleSheetsMock } from "./utils/googlesheets"
describe("Google Sheets Integration", () => {
2024-09-04 15:21:25 +02:00
const config = new TestConfiguration()
let cleanupEnv: () => void
2024-09-04 15:21:25 +02:00
let datasource: Datasource
let mock: GoogleSheetsMock
2024-09-04 15:21:25 +02:00
beforeAll(async () => {
cleanupEnv = setCoreEnv({
GOOGLE_CLIENT_ID: "test",
GOOGLE_CLIENT_SECRET: "test",
})
2024-09-04 15:21:25 +02:00
await config.init()
2024-09-04 15:21:25 +02:00
datasource = await config.api.datasource.create({
name: "Test Datasource",
type: "datasource",
source: SourceName.GOOGLE_SHEETS,
config: {
spreadsheetId: "randomId",
auth: {
appId: "appId",
accessToken: "accessToken",
refreshToken: "refreshToken",
},
},
2024-09-04 15:21:25 +02:00
})
2023-03-06 11:33:49 +01:00
})
afterAll(async () => {
cleanupEnv()
config.end()
})
beforeEach(async () => {
nock.cleanAll()
mock = GoogleSheetsMock.forDatasource(datasource)
2024-09-06 17:55:16 +02:00
mock.init()
})
describe("create", () => {
it("creates a new table", async () => {
const table = await config.api.table.save({
name: "Test Table",
type: "table",
sourceId: datasource._id!,
sourceType: TableSourceType.EXTERNAL,
schema: {
name: {
name: "name",
type: FieldType.STRING,
constraints: {
type: "string",
},
},
description: {
name: "description",
type: FieldType.STRING,
constraints: {
type: "string",
},
},
},
2023-05-23 10:22:26 +02:00
})
2024-09-06 17:55:16 +02:00
const cell = mock.getCell(table.name, "A1")
if (!cell) {
throw new Error("Cell not found")
}
expect(cell.userEnteredValue.stringValue).toEqual(table.name)
2023-05-23 10:22:26 +02:00
})
})
})