forked from tsai/budibase
7 changed files with 126 additions and 24 deletions
@ -0,0 +1,103 @@ |
|||
const { Firestore } = 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() |
|||
}) |
|||
|
|||
it("calls the create method with the correct params", async () => { |
|||
const response = await config.integration.create({ |
|||
table: tableName, |
|||
json: { |
|||
Name: "John" |
|||
} |
|||
}) |
|||
expect(config.integration.client.put).toHaveBeenCalledWith({ |
|||
TableName: tableName, |
|||
Name: "John" |
|||
}) |
|||
}) |
|||
|
|||
it("calls the read method with the correct params", async () => { |
|||
const indexName = "Test" |
|||
|
|||
const response = await config.integration.read({ |
|||
table: tableName, |
|||
index: indexName, |
|||
json: {} |
|||
}) |
|||
expect(config.integration.client.query).toHaveBeenCalledWith({ |
|||
TableName: tableName, |
|||
IndexName: indexName, |
|||
}) |
|||
expect(response).toEqual([]) |
|||
}) |
|||
|
|||
it("calls the scan method with the correct params", async () => { |
|||
const indexName = "Test" |
|||
|
|||
const response = await config.integration.scan({ |
|||
table: tableName, |
|||
index: indexName, |
|||
json: {} |
|||
}) |
|||
expect(config.integration.client.scan).toHaveBeenCalledWith({ |
|||
TableName: tableName, |
|||
IndexName: indexName, |
|||
}) |
|||
expect(response).toEqual([{ |
|||
Name: "test" |
|||
}]) |
|||
}) |
|||
|
|||
it("calls the get method with the correct params", async () => { |
|||
const response = await config.integration.get({ |
|||
table: tableName, |
|||
json: { |
|||
Id: 123 |
|||
} |
|||
}) |
|||
|
|||
expect(config.integration.client.get).toHaveBeenCalledWith({ |
|||
TableName: tableName, |
|||
Id: 123 |
|||
}) |
|||
}) |
|||
|
|||
it("calls the update method with the correct params", async () => { |
|||
const response = await config.integration.update({ |
|||
table: tableName, |
|||
json: { |
|||
Name: "John" |
|||
} |
|||
}) |
|||
expect(config.integration.client.update).toHaveBeenCalledWith({ |
|||
TableName: tableName, |
|||
Name: "John" |
|||
}) |
|||
}) |
|||
|
|||
it("calls the delete method with the correct params", async () => { |
|||
const response = await config.integration.delete({ |
|||
table: tableName, |
|||
json: { |
|||
Name: "John" |
|||
} |
|||
}) |
|||
expect(config.integration.client.delete).toHaveBeenCalledWith({ |
|||
TableName: tableName, |
|||
Name: "John" |
|||
}) |
|||
}) |
|||
}) |
|||
Loading…
Reference in new issue