mirror of https://github.com/Budibase/budibase.git
35 changed files with 322 additions and 139 deletions
@ -0,0 +1,61 @@ |
|||
const { |
|||
generateAppID, |
|||
getDevelopmentAppID, |
|||
getProdAppID, |
|||
isDevAppID, |
|||
isProdAppID, |
|||
} = require("../utils") |
|||
|
|||
function getID() { |
|||
const appId = generateAppID() |
|||
const split = appId.split("_") |
|||
const uuid = split[split.length - 1] |
|||
const devAppId = `app_dev_${uuid}` |
|||
return { appId, devAppId, split, uuid } |
|||
} |
|||
|
|||
describe("app ID manipulation", () => { |
|||
it("should be able to generate a new app ID", () => { |
|||
expect(generateAppID().startsWith("app_")).toEqual(true) |
|||
}) |
|||
|
|||
it("should be able to convert a production app ID to development", () => { |
|||
const { appId, uuid } = getID() |
|||
expect(getDevelopmentAppID(appId)).toEqual(`app_dev_${uuid}`) |
|||
}) |
|||
|
|||
it("should be able to convert a development app ID to development", () => { |
|||
const { devAppId, uuid } = getID() |
|||
expect(getDevelopmentAppID(devAppId)).toEqual(`app_dev_${uuid}`) |
|||
}) |
|||
|
|||
it("should be able to convert a development ID to a production", () => { |
|||
const { devAppId, uuid } = getID() |
|||
expect(getProdAppID(devAppId)).toEqual(`app_${uuid}`) |
|||
}) |
|||
|
|||
it("should be able to convert a production ID to production", () => { |
|||
const { appId, uuid } = getID() |
|||
expect(getProdAppID(appId)).toEqual(`app_${uuid}`) |
|||
}) |
|||
|
|||
it("should be able to confirm dev app ID is development", () => { |
|||
const { devAppId } = getID() |
|||
expect(isDevAppID(devAppId)).toEqual(true) |
|||
}) |
|||
|
|||
it("should be able to confirm prod app ID is not development", () => { |
|||
const { appId } = getID() |
|||
expect(isDevAppID(appId)).toEqual(false) |
|||
}) |
|||
|
|||
it("should be able to confirm prod app ID is prod", () => { |
|||
const { appId } = getID() |
|||
expect(isProdAppID(appId)).toEqual(true) |
|||
}) |
|||
|
|||
it("should be able to confirm dev app ID is not prod", () => { |
|||
const { devAppId } = getID() |
|||
expect(isProdAppID(devAppId)).toEqual(false) |
|||
}) |
|||
}) |
|||
@ -0,0 +1,36 @@ |
|||
module FirebaseMock { |
|||
const firebase: any = {} |
|||
|
|||
firebase.Firestore = function () { |
|||
this.get = jest.fn(() => [ |
|||
{ |
|||
data: jest.fn(() => ({ result: "test" })), |
|||
}, |
|||
]) |
|||
|
|||
this.update = jest.fn() |
|||
this.set = jest.fn() |
|||
this.delete = jest.fn() |
|||
|
|||
this.doc = jest.fn(() => ({ |
|||
update: this.update, |
|||
set: this.set, |
|||
delete: this.delete, |
|||
get: jest.fn(() => ({ |
|||
data: jest.fn(() => ({ result: "test" })), |
|||
})), |
|||
id: "test_id", |
|||
})) |
|||
|
|||
this.where = jest.fn(() => ({ |
|||
get: this.get, |
|||
})) |
|||
|
|||
this.collection = jest.fn(() => ({ |
|||
doc: this.doc, |
|||
where: this.where, |
|||
})) |
|||
} |
|||
|
|||
module.exports = firebase |
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
const firebase = require("@google-cloud/firestore") |
|||
const FirebaseIntegration = require("../firebase") |
|||
jest.mock("@google-cloud/firestore") |
|||
|
|||
class TestConfiguration { |
|||
constructor(config = {}) { |
|||
this.integration = new FirebaseIntegration.integration(config) |
|||
} |
|||
} |
|||
|
|||
describe("Firebase Integration", () => { |
|||
let config |
|||
let tableName = "Users" |
|||
|
|||
beforeEach(() => { |
|||
config = new TestConfiguration({ |
|||
serviceAccount: "{}" |
|||
}) |
|||
}) |
|||
|
|||
it("calls the create method with the correct params", async () => { |
|||
await config.integration.create({ |
|||
table: tableName, |
|||
json: { |
|||
Name: "Test Name" |
|||
}, |
|||
extra: { |
|||
collection: "test" |
|||
} |
|||
}) |
|||
expect(config.integration.client.collection).toHaveBeenCalledWith("test") |
|||
expect(config.integration.client.set).toHaveBeenCalledWith({ |
|||
Name: "Test Name", |
|||
id: "test_id" |
|||
}) |
|||
}) |
|||
|
|||
it("calls the read method with the correct params", async () => { |
|||
const response = await config.integration.read({ |
|||
table: tableName, |
|||
json: { |
|||
Name: "Test" |
|||
}, |
|||
extra: { |
|||
collection: "test", |
|||
filterField: "field", |
|||
filter: "==", |
|||
filterValue: "value", |
|||
} |
|||
}) |
|||
expect(config.integration.client.collection).toHaveBeenCalledWith("test") |
|||
expect(config.integration.client.where).toHaveBeenCalledWith("field", "==", "value") |
|||
expect(response).toEqual([{ result: "test"}]) |
|||
}) |
|||
|
|||
it("calls the update method with the correct params", async () => { |
|||
const response = await config.integration.update({ |
|||
table: tableName, |
|||
json: { |
|||
id: "test", |
|||
Name: "Test" |
|||
}, |
|||
extra: { |
|||
collection: "test" |
|||
} |
|||
}) |
|||
expect(config.integration.client.collection).toHaveBeenCalledWith("test") |
|||
expect(config.integration.client.update).toHaveBeenCalledWith({ |
|||
Name: "Test", |
|||
id: "test" |
|||
}) |
|||
expect(response).toEqual({ |
|||
result: "test" |
|||
}) |
|||
}) |
|||
|
|||
it("calls the delete method with the correct params", async () => { |
|||
const response = await config.integration.delete({ |
|||
table: tableName, |
|||
json: { |
|||
id: "test", |
|||
Name: "Test" |
|||
}, |
|||
extra: { |
|||
collection: "test" |
|||
} |
|||
}) |
|||
expect(config.integration.client.collection).toHaveBeenCalledWith("test") |
|||
expect(config.integration.client.doc).toHaveBeenCalledWith("test") |
|||
expect(config.integration.client.delete).toHaveBeenCalled() |
|||
}) |
|||
}) |
|||
Loading…
Reference in new issue