merge next
This commit is contained in:
commit
fcd7d577d0
|
@ -1,12 +1,9 @@
|
||||||
<script>
|
<script>
|
||||||
import { automationStore, backendUiStore } from "builderStore"
|
import { automationStore } from "builderStore"
|
||||||
import Flowchart from "./FlowChart/FlowChart.svelte"
|
import Flowchart from "./FlowChart/FlowChart.svelte"
|
||||||
import BlockList from "./BlockList.svelte"
|
import BlockList from "./BlockList.svelte"
|
||||||
|
|
||||||
$: automation = $automationStore.selectedAutomation?.automation
|
$: automation = $automationStore.selectedAutomation?.automation
|
||||||
$: automationLive = automation?.live
|
|
||||||
$: instanceId = $backendUiStore.selectedDatabase._id
|
|
||||||
$: automationCount = $automationStore.automations?.length ?? 0
|
|
||||||
|
|
||||||
function onSelect(block) {
|
function onSelect(block) {
|
||||||
automationStore.update(state => {
|
automationStore.update(state => {
|
||||||
|
@ -19,14 +16,4 @@
|
||||||
{#if automation}
|
{#if automation}
|
||||||
<BlockList />
|
<BlockList />
|
||||||
<Flowchart {automation} {onSelect} />
|
<Flowchart {automation} {onSelect} />
|
||||||
{:else if automationCount === 0}
|
{/if}
|
||||||
<i>Create your first automation to get started</i>
|
|
||||||
{:else}<i>Select an automation to edit</i>{/if}
|
|
||||||
|
|
||||||
<style>
|
|
||||||
i {
|
|
||||||
font-size: var(--font-size-m);
|
|
||||||
color: var(--grey-5);
|
|
||||||
margin-top: 2px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
import { automationStore } from "builderStore"
|
import { automationStore } from "builderStore"
|
||||||
import { DropdownMenu, Modal } from "@budibase/bbui"
|
import { DropdownMenu, Modal } from "@budibase/bbui"
|
||||||
import { DropdownContainer, DropdownItem } from "components/common/Dropdowns"
|
import { DropdownContainer, DropdownItem } from "components/common/Dropdowns"
|
||||||
import analytics from "analytics"
|
|
||||||
import CreateWebhookModal from "../Shared/CreateWebhookModal.svelte"
|
import CreateWebhookModal from "../Shared/CreateWebhookModal.svelte"
|
||||||
|
|
||||||
$: hasTrigger = $automationStore.selectedAutomation.hasTrigger()
|
$: hasTrigger = $automationStore.selectedAutomation.hasTrigger()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
import { goto } from "@sveltech/routify"
|
||||||
import { automationStore } from "builderStore"
|
import { automationStore } from "builderStore"
|
||||||
import NavItem from "components/common/NavItem.svelte"
|
import NavItem from "components/common/NavItem.svelte"
|
||||||
import EditAutomationPopover from "./EditAutomationPopover.svelte"
|
import EditAutomationPopover from "./EditAutomationPopover.svelte"
|
||||||
|
@ -9,6 +10,10 @@
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
automationStore.actions.fetch()
|
automationStore.actions.fetch()
|
||||||
})
|
})
|
||||||
|
function selectAutomation(automation) {
|
||||||
|
automationStore.actions.select(automation)
|
||||||
|
$goto(`./${automation._id}`)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="automations-list">
|
<div class="automations-list">
|
||||||
|
@ -18,7 +23,7 @@
|
||||||
icon="ri-stackshare-line"
|
icon="ri-stackshare-line"
|
||||||
text={automation.name}
|
text={automation.name}
|
||||||
selected={automation._id === selectedAutomationId}
|
selected={automation._id === selectedAutomationId}
|
||||||
on:click={() => automationStore.actions.select(automation)}>
|
on:click={() => selectAutomation(automation)}>
|
||||||
<EditAutomationPopover {automation} />
|
<EditAutomationPopover {automation} />
|
||||||
</NavItem>
|
</NavItem>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { store, backendUiStore, automationStore } from "builderStore"
|
import { backendUiStore, automationStore } from "builderStore"
|
||||||
|
import { goto } from "@sveltech/routify"
|
||||||
import { notifier } from "builderStore/store/notifications"
|
import { notifier } from "builderStore/store/notifications"
|
||||||
import { Input, ModalContent } from "@budibase/bbui"
|
import { Input, ModalContent } from "@budibase/bbui"
|
||||||
import analytics from "analytics"
|
import analytics from "analytics"
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
instanceId,
|
instanceId,
|
||||||
})
|
})
|
||||||
notifier.success(`Automation ${name} created.`)
|
notifier.success(`Automation ${name} created.`)
|
||||||
|
$goto(`./${$automationStore.selectedAutomation.automation._id}`)
|
||||||
analytics.captureEvent("Automation Created", { name })
|
analytics.captureEvent("Automation Created", { name })
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
|
import { goto } from "@sveltech/routify"
|
||||||
import { automationStore, backendUiStore } from "builderStore"
|
import { automationStore, backendUiStore } from "builderStore"
|
||||||
import { notifier } from "builderStore/store/notifications"
|
import { notifier } from "builderStore/store/notifications"
|
||||||
import { DropdownMenu } from "@budibase/bbui"
|
import { DropdownMenu } from "@budibase/bbui"
|
||||||
|
@ -23,6 +24,7 @@
|
||||||
automation,
|
automation,
|
||||||
})
|
})
|
||||||
notifier.success("Automation deleted.")
|
notifier.success("Automation deleted.")
|
||||||
|
$goto('../automate')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<script>
|
<script>
|
||||||
import { backendUiStore, store, allScreens } from "builderStore"
|
import { goto } from "@sveltech/routify"
|
||||||
|
import { backendUiStore } from "builderStore"
|
||||||
import { notifier } from "builderStore/store/notifications"
|
import { notifier } from "builderStore/store/notifications"
|
||||||
import { DropdownMenu, Button, Input } from "@budibase/bbui"
|
import { DropdownMenu } from "@budibase/bbui"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
import { DropdownContainer, DropdownItem } from "components/common/Dropdowns"
|
import { DropdownContainer, DropdownItem } from "components/common/Dropdowns"
|
||||||
|
|
||||||
|
@ -10,9 +11,6 @@
|
||||||
let anchor
|
let anchor
|
||||||
let dropdown
|
let dropdown
|
||||||
let confirmDeleteDialog
|
let confirmDeleteDialog
|
||||||
let error = ""
|
|
||||||
let originalName = datasource.name
|
|
||||||
let willBeDeleted
|
|
||||||
|
|
||||||
function hideEditor() {
|
function hideEditor() {
|
||||||
dropdown?.hide()
|
dropdown?.hide()
|
||||||
|
@ -26,6 +24,7 @@
|
||||||
async function deleteDatasource() {
|
async function deleteDatasource() {
|
||||||
await backendUiStore.actions.datasources.delete(datasource)
|
await backendUiStore.actions.datasources.delete(datasource)
|
||||||
notifier.success("Datasource deleted")
|
notifier.success("Datasource deleted")
|
||||||
|
$goto('./datasource')
|
||||||
hideEditor()
|
hideEditor()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
import { TableNames } from "constants"
|
import { TableNames } from "constants"
|
||||||
import EditTablePopover from "./popovers/EditTablePopover.svelte"
|
import EditTablePopover from "./popovers/EditTablePopover.svelte"
|
||||||
import EditViewPopover from "./popovers/EditViewPopover.svelte"
|
import EditViewPopover from "./popovers/EditViewPopover.svelte"
|
||||||
import { Switcher } from "@budibase/bbui"
|
|
||||||
import NavItem from "components/common/NavItem.svelte"
|
import NavItem from "components/common/NavItem.svelte"
|
||||||
|
|
||||||
$: selectedView =
|
$: selectedView =
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function showErrorReasonModal(err) {
|
function showErrorReasonModal(err) {
|
||||||
|
if (!err) return
|
||||||
errorReason = err
|
errorReason = err
|
||||||
errorReasonModal.show()
|
errorReasonModal.show()
|
||||||
}
|
}
|
||||||
|
@ -118,13 +119,11 @@
|
||||||
{#if deployment.status.toLowerCase() === 'pending'}
|
{#if deployment.status.toLowerCase() === 'pending'}
|
||||||
<Spinner size="10" />
|
<Spinner size="10" />
|
||||||
{/if}
|
{/if}
|
||||||
<div class={`deployment-status ${deployment.status}`}>
|
<div on:click={() => showErrorReasonModal(deployment.err)} class={`deployment-status ${deployment.status}`}>
|
||||||
<span>
|
<span>
|
||||||
{deployment.status}
|
{deployment.status}
|
||||||
{#if deployment.status === DeploymentStatus.FAILURE}
|
{#if deployment.status === DeploymentStatus.FAILURE}
|
||||||
<i
|
<i class="ri-information-line"/>
|
||||||
class="ri-information-line"
|
|
||||||
on:click={() => showErrorReasonModal(deployment.err)} />
|
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
const response = await api.put(`/api/keys/${key}`, { value })
|
const response = await api.put(`/api/keys/${key}`, { value })
|
||||||
const res = await response.json()
|
const res = await response.json()
|
||||||
keys = { ...keys, ...res }
|
keys = { ...keys, ...res }
|
||||||
|
notifier.success("API Key saved.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Keys
|
// Get Keys
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
<script>
|
<script>
|
||||||
import { store } from "builderStore"
|
import { automationStore } from "builderStore"
|
||||||
import { params } from "@roxi/routify"
|
import { params } from "@sveltech/routify"
|
||||||
|
|
||||||
store.actions.layouts.select($params.layout)
|
if ($params.automation) {
|
||||||
|
const automation = $automationStore.automations.find(
|
||||||
|
m => m._id === $params.automation
|
||||||
|
)
|
||||||
|
if (automation) {
|
||||||
|
automationStore.actions.select(automation)
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<slot />
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<script>
|
||||||
|
import AutomationBuilder from "components/automation/AutomationBuilder/AutomationBuilder.svelte"
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<AutomationBuilder />
|
||||||
|
|
|
@ -1,5 +1,26 @@
|
||||||
<script>
|
<script>
|
||||||
import AutomationBuilder from "components/automation/AutomationBuilder/AutomationBuilder.svelte"
|
import { goto, leftover } from "@sveltech/routify"
|
||||||
|
import { onMount } from 'svelte'
|
||||||
|
import { automationStore } from "builderStore"
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
// navigate to first automation in list, if not already selected
|
||||||
|
if (
|
||||||
|
!$leftover &&
|
||||||
|
$automationStore.automations.length > 0 &&
|
||||||
|
(!$automationStore.selectedAutomation || !$automationStore.selectedAutomation?.automation?._id)
|
||||||
|
) {
|
||||||
|
$goto(`../${$automationStore.automations[0]._id}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AutomationBuilder />
|
<i>Create your first automation to get started</i>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
i {
|
||||||
|
font-size: var(--font-size-m);
|
||||||
|
color: var(--grey-5);
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { params } from "@roxi/routify"
|
import { isActive, goto } from "@sveltech/routify"
|
||||||
import { Button, Switcher, Modal } from "@budibase/bbui"
|
import { Switcher, Modal } from "@budibase/bbui"
|
||||||
import TableNavigator from "components/backend/TableNavigator/TableNavigator.svelte"
|
import TableNavigator from "components/backend/TableNavigator/TableNavigator.svelte"
|
||||||
import DatasourceNavigator from "components/backend/DatasourceNavigator/DatasourceNavigator.svelte"
|
import DatasourceNavigator from "components/backend/DatasourceNavigator/DatasourceNavigator.svelte"
|
||||||
import CreateDatasourceModal from "components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte"
|
import CreateDatasourceModal from "components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte"
|
||||||
|
@ -17,7 +17,16 @@
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
let tab = $params.selectedDatasource ? "datasource" : "table"
|
let tab = $isActive('./datasource') ? "datasource" : "table"
|
||||||
|
|
||||||
|
function selectFirstTableOrSource({ detail }) {
|
||||||
|
const type = detail.heading.key
|
||||||
|
if (type === 'datasource') {
|
||||||
|
$goto("./datasource")
|
||||||
|
} else {
|
||||||
|
$goto("./table")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let modal
|
let modal
|
||||||
</script>
|
</script>
|
||||||
|
@ -25,7 +34,7 @@
|
||||||
<!-- routify:options index=0 -->
|
<!-- routify:options index=0 -->
|
||||||
<div class="root">
|
<div class="root">
|
||||||
<div class="nav">
|
<div class="nav">
|
||||||
<Switcher headings={tabs} bind:value={tab}>
|
<Switcher headings={tabs} bind:value={tab} on:change={selectFirstTableOrSource}>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<i
|
<i
|
||||||
data-cy={`new-${tab}`}
|
data-cy={`new-${tab}`}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<script>
|
||||||
|
import { params } from "@sveltech/routify"
|
||||||
|
import { backendUiStore } from "builderStore"
|
||||||
|
|
||||||
|
if ($params.query) {
|
||||||
|
const query = $backendUiStore.queries.find(
|
||||||
|
m => m._id === $params.query
|
||||||
|
)
|
||||||
|
if (query) {
|
||||||
|
backendUiStore.actions.queries.select(query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<slot />
|
|
@ -2,12 +2,12 @@
|
||||||
import { params } from "@roxi/routify"
|
import { params } from "@roxi/routify"
|
||||||
import { backendUiStore } from "builderStore"
|
import { backendUiStore } from "builderStore"
|
||||||
|
|
||||||
if ($params.selectedDatasourceId) {
|
if ($params.selectedDatasource) {
|
||||||
const datasource = $backendUiStore.datasources.find(
|
const datasource = $backendUiStore.datasources.find(
|
||||||
m => m._id === $params.selectedDatasource
|
m => m._id === $params.selectedDatasource
|
||||||
)
|
)
|
||||||
if (datasource) {
|
if (datasource) {
|
||||||
backendUiStore.actions.datasources.select(datasource)
|
backendUiStore.actions.datasources.select(datasource._id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { goto, beforeUrlChange } from "@roxi/routify"
|
import { goto, beforeUrlChange } from "@sveltech/routify"
|
||||||
import { Button, Heading, Body, Spacer, Icon } from "@budibase/bbui"
|
import { Button, Heading, Body, Spacer } from "@budibase/bbui"
|
||||||
import { backendUiStore } from "builderStore"
|
import { backendUiStore } from "builderStore"
|
||||||
import { notifier } from "builderStore/store/notifications"
|
import { notifier } from "builderStore/store/notifications"
|
||||||
import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte"
|
import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte"
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<script>
|
||||||
|
import { backendUiStore } from "builderStore"
|
||||||
|
import { goto } from "@sveltech/routify"
|
||||||
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
// navigate to first table in list, if not already selected
|
||||||
|
$backendUiStore.datasources.length > 0 && $goto(`../${$backendUiStore.datasources[0]._id}`)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if $backendUiStore.tables.length === 0}
|
||||||
|
<i>Connect your first datasource to start building.</i>
|
||||||
|
{:else}<i>Select a datasource to edit</i>{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
i {
|
||||||
|
font-size: var(--font-size-m);
|
||||||
|
color: var(--grey-5);
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -1,23 +1,10 @@
|
||||||
<script>
|
<script>
|
||||||
import { store, backendUiStore } from "builderStore"
|
import { backendUiStore } from "builderStore"
|
||||||
import { goto, leftover } from "@roxi/routify"
|
import { goto } from "@sveltech/routify"
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
async function selectTable(table) {
|
|
||||||
backendUiStore.actions.tables.select(table)
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
// navigate to first table in list, if not already selected
|
$backendUiStore.tables.length > 0 && $goto(`../${$backendUiStore.tables[0]._id}`)
|
||||||
// and this is the final url (i.e. no selectedTable)
|
|
||||||
if (
|
|
||||||
!$leftover &&
|
|
||||||
$backendUiStore.tables.length > 0 &&
|
|
||||||
(!$backendUiStore.selectedTable || !$backendUiStore.selectedTable._id)
|
|
||||||
) {
|
|
||||||
// this file routes as .../tables/index, so, go up one.
|
|
||||||
$goto(`../${$backendUiStore.tables[0]._id}`)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
const elastic = {}
|
||||||
|
|
||||||
|
elastic.Client = function() {
|
||||||
|
this.index = jest.fn().mockResolvedValue({ body: [] })
|
||||||
|
this.search = jest.fn().mockResolvedValue({
|
||||||
|
body: {
|
||||||
|
hits: {
|
||||||
|
hits: [
|
||||||
|
{
|
||||||
|
_source: {
|
||||||
|
name: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
this.update = jest.fn().mockResolvedValue({ body: [] })
|
||||||
|
this.delete = jest.fn().mockResolvedValue({ body: [] })
|
||||||
|
|
||||||
|
this.close = jest.fn()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = elastic
|
|
@ -0,0 +1,5 @@
|
||||||
|
function Airtable() {
|
||||||
|
this.base = jest.fn()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Airtable
|
|
@ -0,0 +1,21 @@
|
||||||
|
const arangodb = {}
|
||||||
|
|
||||||
|
arangodb.Database = function() {
|
||||||
|
this.query = jest.fn(() => ({
|
||||||
|
all: jest.fn(),
|
||||||
|
}))
|
||||||
|
this.collection = jest.fn(() => "collection")
|
||||||
|
this.close = jest.fn()
|
||||||
|
}
|
||||||
|
|
||||||
|
arangodb.aql = (strings, ...args) => {
|
||||||
|
let str = strings.join("{}")
|
||||||
|
|
||||||
|
for (let arg of args) {
|
||||||
|
str = str.replace("{}", arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = arangodb
|
|
@ -0,0 +1,38 @@
|
||||||
|
const aws = {}
|
||||||
|
|
||||||
|
const response = body => () => ({ promise: () => body })
|
||||||
|
|
||||||
|
function DocumentClient() {
|
||||||
|
this.put = jest.fn(response({}))
|
||||||
|
this.query = jest.fn(
|
||||||
|
response({
|
||||||
|
Items: [],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
this.scan = jest.fn(
|
||||||
|
response({
|
||||||
|
Items: [
|
||||||
|
{
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
this.get = jest.fn(response({}))
|
||||||
|
this.update = jest.fn(response({}))
|
||||||
|
this.delete = jest.fn(response({}))
|
||||||
|
}
|
||||||
|
|
||||||
|
function S3() {
|
||||||
|
this.listObjects = jest.fn(
|
||||||
|
response({
|
||||||
|
Contents: {},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
aws.DynamoDB = { DocumentClient }
|
||||||
|
aws.S3 = S3
|
||||||
|
aws.config = { update: jest.fn() }
|
||||||
|
|
||||||
|
module.exports = aws
|
|
@ -0,0 +1,19 @@
|
||||||
|
const mongodb = {}
|
||||||
|
|
||||||
|
mongodb.MongoClient = function() {
|
||||||
|
this.connect = jest.fn()
|
||||||
|
this.close = jest.fn()
|
||||||
|
this.insertOne = jest.fn()
|
||||||
|
this.find = jest.fn(() => ({ toArray: () => [] }))
|
||||||
|
|
||||||
|
this.collection = jest.fn(() => ({
|
||||||
|
insertOne: this.insertOne,
|
||||||
|
find: this.find,
|
||||||
|
}))
|
||||||
|
|
||||||
|
this.db = () => ({
|
||||||
|
collection: this.collection,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = mongodb
|
|
@ -0,0 +1,14 @@
|
||||||
|
const mssql = {}
|
||||||
|
|
||||||
|
mssql.query = jest.fn(() => ({
|
||||||
|
recordset: [
|
||||||
|
{
|
||||||
|
a: "string",
|
||||||
|
b: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}))
|
||||||
|
|
||||||
|
mssql.connect = jest.fn(() => ({ recordset: [] }))
|
||||||
|
|
||||||
|
module.exports = mssql
|
|
@ -0,0 +1,10 @@
|
||||||
|
const mysql = {}
|
||||||
|
|
||||||
|
const client = {
|
||||||
|
connect: jest.fn(),
|
||||||
|
query: jest.fn(),
|
||||||
|
}
|
||||||
|
|
||||||
|
mysql.createConnection = jest.fn(() => client)
|
||||||
|
|
||||||
|
module.exports = mysql
|
|
@ -3,18 +3,16 @@ const pg = {}
|
||||||
// constructor
|
// constructor
|
||||||
function Client() {}
|
function Client() {}
|
||||||
|
|
||||||
Client.prototype.query = async function() {
|
Client.prototype.query = jest.fn(() => ({
|
||||||
return {
|
rows: [
|
||||||
rows: [
|
{
|
||||||
{
|
a: "string",
|
||||||
a: "string",
|
b: 1,
|
||||||
b: 1,
|
},
|
||||||
},
|
],
|
||||||
],
|
}))
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Client.prototype.connect = async function() {}
|
Client.prototype.connect = jest.fn()
|
||||||
|
|
||||||
pg.Client = Client
|
pg.Client = Client
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
function CouchDB() {
|
||||||
|
this.post = jest.fn()
|
||||||
|
this.allDocs = jest.fn(() => ({ rows: [] }))
|
||||||
|
this.put = jest.fn()
|
||||||
|
this.remove = jest.fn()
|
||||||
|
this.plugin = jest.fn()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CouchDB
|
|
@ -166,7 +166,7 @@ class DynamoDBIntegration {
|
||||||
|
|
||||||
async update(query) {
|
async update(query) {
|
||||||
const params = {
|
const params = {
|
||||||
TableName: query.Table,
|
TableName: query.table,
|
||||||
...query.json,
|
...query.json,
|
||||||
}
|
}
|
||||||
return this.client.update(params).promise()
|
return this.client.update(params).promise()
|
||||||
|
|
|
@ -65,7 +65,7 @@ class SqlServerIntegration {
|
||||||
try {
|
try {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
const response = await this.client.query(query.sql)
|
const response = await this.client.query(query.sql)
|
||||||
return response.recordset
|
return response.recordset || [{ created: true }]
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error querying MS SQL Server", err)
|
console.error("Error querying MS SQL Server", err)
|
||||||
throw err
|
throw err
|
||||||
|
|
|
@ -73,20 +73,23 @@ class MySQLIntegration {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
create(query) {
|
async create(query) {
|
||||||
return this.query(query)
|
const results = await this.query(query)
|
||||||
|
return results.length ? results : [{ created: true }]
|
||||||
}
|
}
|
||||||
|
|
||||||
read(query) {
|
read(query) {
|
||||||
return this.query(query)
|
return this.query(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
update(query) {
|
async update(query) {
|
||||||
return this.query(query)
|
const results = await this.query(query)
|
||||||
|
return results.length ? results : [{ updated: true }]
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(query) {
|
async delete(query) {
|
||||||
return this.query(query)
|
const results = await this.query(query)
|
||||||
|
return results.length ? results : [{ deleted: true }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
const Airtable = require("airtable")
|
||||||
|
const AirtableIntegration = require("../airtable")
|
||||||
|
jest.mock("airtable")
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new AirtableIntegration.integration(config)
|
||||||
|
this.client = {
|
||||||
|
create: jest.fn(),
|
||||||
|
select: jest.fn(),
|
||||||
|
update: jest.fn(),
|
||||||
|
destroy: jest.fn(),
|
||||||
|
}
|
||||||
|
this.integration.client = () => this.client
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("Airtable Integration", () => {
|
||||||
|
let config
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method with the correct params", async () => {
|
||||||
|
const response = await config.integration.create({
|
||||||
|
table: "test",
|
||||||
|
json: {}
|
||||||
|
})
|
||||||
|
expect(config.client.create).toHaveBeenCalledWith([
|
||||||
|
{
|
||||||
|
fields: {}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const response = await config.integration.read({
|
||||||
|
table: "test",
|
||||||
|
view: "Grid view"
|
||||||
|
})
|
||||||
|
expect(config.client.select).toHaveBeenCalledWith({
|
||||||
|
maxRecords: 10, view: "Grid view"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the update method with the correct params", async () => {
|
||||||
|
const response = await config.integration.update({
|
||||||
|
table: "test",
|
||||||
|
id: "123",
|
||||||
|
json: {
|
||||||
|
name: "test"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
expect(config.client.update).toHaveBeenCalledWith([
|
||||||
|
{
|
||||||
|
id: "123",
|
||||||
|
fields: { name: "test" }
|
||||||
|
}
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the delete method with the correct params", async () => {
|
||||||
|
const ids = [1,2,3,4]
|
||||||
|
const response = await config.integration.delete({
|
||||||
|
ids
|
||||||
|
})
|
||||||
|
expect(config.client.destroy).toHaveBeenCalledWith(ids)
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,35 @@
|
||||||
|
const arangodb = require("arangojs")
|
||||||
|
const ArangoDBIntegration = require("../arangodb")
|
||||||
|
jest.mock("arangojs")
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new ArangoDBIntegration.integration(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("ArangoDB Integration", () => {
|
||||||
|
let config
|
||||||
|
let indexName = "Users"
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method with the correct params", async () => {
|
||||||
|
const body = {
|
||||||
|
json: "Hello"
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await config.integration.create(body)
|
||||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(`INSERT Hello INTO collection RETURN NEW`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const query = {
|
||||||
|
json: `test`,
|
||||||
|
}
|
||||||
|
const response = await config.integration.read(query)
|
||||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(query.sql)
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,68 @@
|
||||||
|
const PouchDB = require("pouchdb")
|
||||||
|
const CouchDBIntegration = require("../couchdb")
|
||||||
|
jest.mock("pouchdb", () => function CouchDBMock() {
|
||||||
|
this.post = jest.fn()
|
||||||
|
this.allDocs = jest.fn(() => ({ rows: [] }))
|
||||||
|
this.put = jest.fn()
|
||||||
|
this.remove = jest.fn()
|
||||||
|
this.plugin = jest.fn()
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new CouchDBIntegration.integration(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("CouchDB Integration", () => {
|
||||||
|
let config
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method with the correct params", async () => {
|
||||||
|
const doc = {
|
||||||
|
test: 1
|
||||||
|
}
|
||||||
|
const response = await config.integration.create({
|
||||||
|
json: doc
|
||||||
|
})
|
||||||
|
expect(config.integration.client.post).toHaveBeenCalledWith(doc)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const doc = {
|
||||||
|
name: "search"
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await config.integration.read({
|
||||||
|
json: doc
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(config.integration.client.allDocs).toHaveBeenCalledWith({
|
||||||
|
include_docs: true,
|
||||||
|
name: "search"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the update method with the correct params", async () => {
|
||||||
|
const doc = {
|
||||||
|
_id: "1234",
|
||||||
|
name: "search"
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await config.integration.update({
|
||||||
|
json: doc
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(config.integration.client.put).toHaveBeenCalledWith(doc)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the delete method with the correct params", async () => {
|
||||||
|
const id = "1234"
|
||||||
|
const response = await config.integration.delete({ id })
|
||||||
|
expect(config.integration.client.remove).toHaveBeenCalledWith(id)
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,103 @@
|
||||||
|
const AWS = require("aws-sdk")
|
||||||
|
const DynamoDBIntegration = require("../dynamodb")
|
||||||
|
jest.mock("aws-sdk")
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new DynamoDBIntegration.integration(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("DynamoDB 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"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,81 @@
|
||||||
|
const elasticsearch = require("@elastic/elasticsearch")
|
||||||
|
const ElasticSearchIntegration = require("../elasticsearch")
|
||||||
|
jest.mock("@elastic/elasticsearch")
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new ElasticSearchIntegration.integration(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("Elasticsearch Integration", () => {
|
||||||
|
let config
|
||||||
|
let indexName = "Users"
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method with the correct params", async () => {
|
||||||
|
const body = {
|
||||||
|
name: "Hello"
|
||||||
|
}
|
||||||
|
const response = await config.integration.create({
|
||||||
|
index: indexName,
|
||||||
|
json: body
|
||||||
|
})
|
||||||
|
expect(config.integration.client.index).toHaveBeenCalledWith({
|
||||||
|
index: indexName,
|
||||||
|
body
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const body = {
|
||||||
|
query: {
|
||||||
|
term: {
|
||||||
|
name: "kimchy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const response = await config.integration.read({
|
||||||
|
index: indexName,
|
||||||
|
json: body
|
||||||
|
})
|
||||||
|
expect(config.integration.client.search).toHaveBeenCalledWith({
|
||||||
|
index: indexName,
|
||||||
|
body
|
||||||
|
})
|
||||||
|
expect(response).toEqual(expect.any(Array))
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the update method with the correct params", async () => {
|
||||||
|
const body = {
|
||||||
|
name: "updated"
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await config.integration.update({
|
||||||
|
id: "1234",
|
||||||
|
index: indexName,
|
||||||
|
json: body
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(config.integration.client.update).toHaveBeenCalledWith({
|
||||||
|
id: "1234",
|
||||||
|
index: indexName,
|
||||||
|
body
|
||||||
|
})
|
||||||
|
expect(response).toEqual(expect.any(Array))
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the delete method with the correct params", async () => {
|
||||||
|
const body = {
|
||||||
|
id: "1234"
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await config.integration.delete(body)
|
||||||
|
|
||||||
|
expect(config.integration.client.delete).toHaveBeenCalledWith(body)
|
||||||
|
expect(response).toEqual(expect.any(Array))
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,47 @@
|
||||||
|
const sqlServer = require("mssql")
|
||||||
|
const MSSQLIntegration = require("../microsoftSqlServer")
|
||||||
|
jest.mock("mssql")
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new MSSQLIntegration.integration(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("MS SQL Server Integration", () => {
|
||||||
|
let config
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method with the correct params", async () => {
|
||||||
|
const sql = "insert into users (name, age) values ('Joe', 123);"
|
||||||
|
const response = await config.integration.create({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const sql = "select * from users;"
|
||||||
|
const response = await config.integration.read({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("no rows returned", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
config.integration.client.query.mockImplementation(() => ({ rows: [] }))
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the correct response when the create response has no rows", async () => {
|
||||||
|
const sql = "insert into users (name, age) values ('Joe', 123);"
|
||||||
|
const response = await config.integration.create({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(response).toEqual([{ created: true }])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,40 @@
|
||||||
|
const mongo = require("mongodb")
|
||||||
|
const MongoDBIntegration = require("../mongodb")
|
||||||
|
jest.mock("mongodb")
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new MongoDBIntegration.integration(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("MongoDB Integration", () => {
|
||||||
|
let config
|
||||||
|
let indexName = "Users"
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method with the correct params", async () => {
|
||||||
|
const body = {
|
||||||
|
name: "Hello"
|
||||||
|
}
|
||||||
|
const response = await config.integration.create({
|
||||||
|
index: indexName,
|
||||||
|
json: body
|
||||||
|
})
|
||||||
|
expect(config.integration.client.insertOne).toHaveBeenCalledWith(body)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const query = {
|
||||||
|
json: {
|
||||||
|
address: "test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const response = await config.integration.read(query)
|
||||||
|
expect(config.integration.client.find).toHaveBeenCalledWith(query.json)
|
||||||
|
expect(response).toEqual(expect.any(Array))
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,83 @@
|
||||||
|
const pg = require("mysql")
|
||||||
|
const MySQLIntegration = require("../mysql")
|
||||||
|
jest.mock("mysql")
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = { ssl: {} }) {
|
||||||
|
this.integration = new MySQLIntegration.integration(config)
|
||||||
|
this.query = jest.fn(() => [{ id: 1 }])
|
||||||
|
this.integration.query = this.query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("MySQL Integration", () => {
|
||||||
|
let config
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method with the correct params", async () => {
|
||||||
|
const sql = "insert into users (name, age) values ('Joe', 123);"
|
||||||
|
const response = await config.integration.create({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.query).toHaveBeenCalledWith({ sql })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const sql = "select * from users;"
|
||||||
|
const response = await config.integration.read({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.query).toHaveBeenCalledWith({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the update method with the correct params", async () => {
|
||||||
|
const sql = "update table users set name = 'test';"
|
||||||
|
const response = await config.integration.update({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.query).toHaveBeenCalledWith({ sql })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the delete method with the correct params", async () => {
|
||||||
|
const sql = "delete from users where name = 'todelete';"
|
||||||
|
const response = await config.integration.delete({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.query).toHaveBeenCalledWith({ sql })
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("no rows returned", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
config.query.mockImplementation(() => [])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the correct response when the create response has no rows", async () => {
|
||||||
|
const sql = "insert into users (name, age) values ('Joe', 123);"
|
||||||
|
const response = await config.integration.create({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(response).toEqual([{ created: true }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the correct response when the update response has no rows", async () => {
|
||||||
|
const sql = "update table users set name = 'test';"
|
||||||
|
const response = await config.integration.update({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(response).toEqual([{ updated: true }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the correct response when the delete response has no rows", async () => {
|
||||||
|
const sql = "delete from users where name = 'todelete';"
|
||||||
|
const response = await config.integration.delete({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(response).toEqual([{ deleted: true }])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,79 @@
|
||||||
|
const pg = require("pg")
|
||||||
|
const PostgresIntegration = require("../postgres")
|
||||||
|
jest.mock("pg")
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new PostgresIntegration.integration(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("Postgres Integration", () => {
|
||||||
|
let config
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method with the correct params", async () => {
|
||||||
|
const sql = "insert into users (name, age) values ('Joe', 123);"
|
||||||
|
const response = await config.integration.create({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const sql = "select * from users;"
|
||||||
|
const response = await config.integration.read({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the update method with the correct params", async () => {
|
||||||
|
const sql = "update table users set name = 'test';"
|
||||||
|
const response = await config.integration.update({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the delete method with the correct params", async () => {
|
||||||
|
const sql = "delete from users where name = 'todelete';"
|
||||||
|
const response = await config.integration.delete({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("no rows returned", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
config.integration.client.query.mockImplementation(() => ({ rows: [] }))
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the correct response when the create response has no rows", async () => {
|
||||||
|
const sql = "insert into users (name, age) values ('Joe', 123);"
|
||||||
|
const response = await config.integration.create({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(response).toEqual([{ created: true }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the correct response when the update response has no rows", async () => {
|
||||||
|
const sql = "update table users set name = 'test';"
|
||||||
|
const response = await config.integration.update({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(response).toEqual([{ updated: true }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the correct response when the delete response has no rows", async () => {
|
||||||
|
const sql = "delete from users where name = 'todelete';"
|
||||||
|
const response = await config.integration.delete({
|
||||||
|
sql
|
||||||
|
})
|
||||||
|
expect(response).toEqual([{ deleted: true }])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,98 @@
|
||||||
|
const fetch = require("node-fetch")
|
||||||
|
const RestIntegration = require("../rest")
|
||||||
|
jest.mock("node-fetch", () => jest.fn(() => ({ json: jest.fn(), text: jest.fn() })))
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new RestIntegration.integration(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("REST Integration", () => {
|
||||||
|
const BASE_URL = "https://myapi.com"
|
||||||
|
let config
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration({
|
||||||
|
url: BASE_URL
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method with the correct params", async () => {
|
||||||
|
const query = {
|
||||||
|
path: "/api",
|
||||||
|
queryString: "?test=1",
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json"
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
name: "test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const response = await config.integration.create(query)
|
||||||
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
||||||
|
method: "POST",
|
||||||
|
body: "{\"name\":\"test\"}",
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const query = {
|
||||||
|
path: "/api",
|
||||||
|
queryString: "?test=1",
|
||||||
|
headers: {
|
||||||
|
Accept: "text/html"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const response = await config.integration.read(query)
|
||||||
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
||||||
|
headers: {
|
||||||
|
Accept: "text/html"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the update method with the correct params", async () => {
|
||||||
|
const query = {
|
||||||
|
path: "/api",
|
||||||
|
queryString: "?test=1",
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json"
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
name: "test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const response = await config.integration.update(query)
|
||||||
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
||||||
|
method: "POST",
|
||||||
|
body: "{\"name\":\"test\"}",
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the delete method with the correct params", async () => {
|
||||||
|
const query = {
|
||||||
|
path: "/api",
|
||||||
|
queryString: "?test=1",
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json"
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
name: "test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const response = await config.integration.delete(query)
|
||||||
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,26 @@
|
||||||
|
const AWS = require("aws-sdk")
|
||||||
|
const S3Integration = require("../s3")
|
||||||
|
jest.mock("aws-sdk")
|
||||||
|
|
||||||
|
class TestConfiguration {
|
||||||
|
constructor(config = {}) {
|
||||||
|
this.integration = new S3Integration.integration(config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("S3 Integration", () => {
|
||||||
|
let config
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
config = new TestConfiguration()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the read method with the correct params", async () => {
|
||||||
|
const response = await config.integration.read({
|
||||||
|
bucket: "test"
|
||||||
|
})
|
||||||
|
expect(config.integration.client.listObjects).toHaveBeenCalledWith({
|
||||||
|
Bucket: "test"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue