2024-08-09 11:30:27 +02:00
|
|
|
import { setEnv as setCoreEnv } from "@budibase/backend-core"
|
2024-08-01 12:44:58 +02:00
|
|
|
import nock from "nock"
|
2023-02-27 17:25:48 +01:00
|
|
|
|
|
|
|
import TestConfiguration from "../../tests/utilities/TestConfiguration"
|
2024-09-04 15:21:25 +02:00
|
|
|
import {
|
|
|
|
Datasource,
|
|
|
|
FieldType,
|
|
|
|
SourceName,
|
|
|
|
TableSourceType,
|
|
|
|
} from "@budibase/types"
|
2024-09-06 16:03:17 +02:00
|
|
|
import { access } from "node:fs"
|
|
|
|
import { GoogleSheetsMock } from "./utils/googlesheets"
|
2023-02-27 17:25:48 +01:00
|
|
|
|
|
|
|
describe("Google Sheets Integration", () => {
|
2024-09-04 15:21:25 +02:00
|
|
|
const config = new TestConfiguration()
|
|
|
|
|
2023-10-30 17:46:27 +01:00
|
|
|
let cleanupEnv: () => void
|
2024-09-04 15:21:25 +02:00
|
|
|
let datasource: Datasource
|
2024-09-06 16:03:17 +02:00
|
|
|
let mock: GoogleSheetsMock
|
2024-09-04 15:21:25 +02:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
2024-08-09 11:30:27 +02:00
|
|
|
cleanupEnv = setCoreEnv({
|
2023-10-30 17:46:27 +01:00
|
|
|
GOOGLE_CLIENT_ID: "test",
|
|
|
|
GOOGLE_CLIENT_SECRET: "test",
|
|
|
|
})
|
2024-09-04 15:21:25 +02:00
|
|
|
|
2024-09-06 16:03:17 +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,
|
2024-09-06 16:03:17 +02:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2023-03-27 20:38:49 +02:00
|
|
|
afterAll(async () => {
|
2023-10-30 17:46:27 +01:00
|
|
|
cleanupEnv()
|
|
|
|
config.end()
|
2023-03-27 20:38:49 +02:00
|
|
|
})
|
|
|
|
|
2023-02-27 17:25:48 +01:00
|
|
|
beforeEach(async () => {
|
2024-08-01 12:44:58 +02:00
|
|
|
nock.cleanAll()
|
2024-09-06 16:03:17 +02:00
|
|
|
mock = GoogleSheetsMock.forDatasource(datasource)
|
|
|
|
mock.mockAuth()
|
2024-08-01 12:44:58 +02:00
|
|
|
})
|
2024-08-01 12:43:37 +02:00
|
|
|
|
2024-09-06 16:03:17 +02:00
|
|
|
describe("create", () => {
|
|
|
|
it("creates a new table", async () => {
|
|
|
|
nock("https://sheets.googleapis.com/", {
|
|
|
|
reqheaders: { authorization: "Bearer test" },
|
|
|
|
})
|
|
|
|
.get("/v4/spreadsheets/randomId/")
|
|
|
|
.reply(200, {})
|
|
|
|
|
|
|
|
const table = await config.api.table.save({
|
|
|
|
name: "Test Table",
|
|
|
|
type: "table",
|
|
|
|
sourceId: datasource._id!,
|
|
|
|
sourceType: TableSourceType.EXTERNAL,
|
|
|
|
schema: {
|
|
|
|
name: {
|
|
|
|
name: "name",
|
2023-02-27 17:25:48 +01:00
|
|
|
type: FieldType.STRING,
|
|
|
|
constraints: {
|
|
|
|
type: "string",
|
|
|
|
},
|
2024-09-06 16:03:17 +02:00
|
|
|
},
|
|
|
|
description: {
|
|
|
|
name: "description",
|
|
|
|
type: FieldType.STRING,
|
|
|
|
constraints: {
|
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-05-23 10:22:26 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2023-02-27 17:25:48 +01:00
|
|
|
})
|