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

156 lines
3.7 KiB
TypeScript
Raw Normal View History

import { default as DynamoDBIntegration } from "../dynamodb"
2021-03-15 20:45:39 +01:00
jest.mock("aws-sdk")
class TestConfiguration {
integration: any
constructor(config: any = {}) {
this.integration = new DynamoDBIntegration.integration(config)
2021-03-15 20:45:39 +01:00
}
}
describe("DynamoDB Integration", () => {
let config: any
2021-03-15 20:45:39 +01:00
let tableName = "Users"
beforeEach(() => {
config = new TestConfiguration()
})
it("calls the create method with the correct params", async () => {
const response = await config.integration.create({
2021-03-15 20:45:39 +01:00
table: tableName,
json: {
Name: "John",
},
2021-03-15 20:45:39 +01:00
})
expect(config.integration.client.put).toHaveBeenCalledWith({
TableName: tableName,
Name: "John",
2021-03-15 20:45:39 +01:00
})
})
it("calls the read method with the correct params", async () => {
const indexName = "Test"
const response = await config.integration.read({
2021-03-15 20:45:39 +01:00
table: tableName,
index: indexName,
json: {},
2021-03-15 20:45:39 +01:00
})
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({
2021-03-15 20:45:39 +01:00
table: tableName,
index: indexName,
json: {},
2021-03-15 20:45:39 +01:00
})
expect(config.integration.client.scan).toHaveBeenCalledWith({
TableName: tableName,
IndexName: indexName,
})
expect(response).toEqual([
{
Name: "test",
},
])
2021-03-15 20:45:39 +01:00
})
it("calls the get method with the correct params", async () => {
const response = await config.integration.get({
2021-03-15 20:45:39 +01:00
table: tableName,
json: {
Id: 123,
},
2021-03-15 20:45:39 +01:00
})
expect(config.integration.client.get).toHaveBeenCalledWith({
TableName: tableName,
Id: 123,
2021-03-15 20:45:39 +01:00
})
})
it("calls the update method with the correct params", async () => {
const response = await config.integration.update({
2021-03-15 20:45:39 +01:00
table: tableName,
json: {
Name: "John",
},
2021-03-15 20:45:39 +01:00
})
expect(config.integration.client.update).toHaveBeenCalledWith({
TableName: tableName,
Name: "John",
2021-03-15 20:45:39 +01:00
})
})
it("calls the delete method with the correct params", async () => {
const response = await config.integration.delete({
2021-03-15 20:45:39 +01:00
table: tableName,
json: {
Name: "John",
},
2021-03-15 20:45:39 +01:00
})
expect(config.integration.client.delete).toHaveBeenCalledWith({
TableName: tableName,
Name: "John",
2021-03-15 20:45:39 +01:00
})
})
it("configures the dynamoDB constructor based on an empty endpoint parameter", async () => {
const config = {
region: "us-east-1",
accessKeyId: "test",
secretAccessKey: "test",
}
const integration: any = new DynamoDBIntegration.integration(config)
expect(integration.config).toEqual({
currentClockSkew: true,
...config,
})
})
it("configures the dynamoDB constructor based on a localhost endpoint parameter", async () => {
const config = {
region: "us-east-1",
accessKeyId: "test",
secretAccessKey: "test",
endpoint: "localhost:8080",
}
const integration: any = new DynamoDBIntegration.integration(config)
expect(integration.config).toEqual({
region: "us-east-1",
currentClockSkew: true,
endpoint: "localhost:8080",
})
})
it("configures the dynamoDB constructor based on a remote endpoint parameter", async () => {
const config = {
region: "us-east-1",
accessKeyId: "test",
secretAccessKey: "test",
endpoint: "dynamodb.aws.foo.net",
}
const integration = new DynamoDBIntegration.integration(config)
// @ts-ignore
expect(integration.config).toEqual({
currentClockSkew: true,
...config,
})
})
})