UNPKG

@buildable/pipelines

Version:

Buildable is a fully managed event bus lets you send and receive data across mission-critical cloud apps, databases and warehouses.

144 lines (118 loc) 3.37 kB
import { ValidAccessKey } from '@buildable/types'; import { createDestination, createSource, deleteDestination, deleteSource, createClient, setEvents, } from '@buildable/connections'; import { createPipeline } from '../logic/createPipeline'; import { deletePipeline, listPipelines, updatePipeline } from '../logic'; import { makeId } from '@buildable/utils'; import transformer from './transform'; require('dotenv').config(); jest.setTimeout(60000); describe('Connections APIs Specs', () => { it('Should create a Stripe to MongoDB pipeline', async () => { const client = createClient( process.env.BUILDABLE_SECRET_KEY as ValidAccessKey ); const source = await createSource(client, { type: 'stripe', group: `my-stripe-source-${makeId(4)}`, label: `my-stripe-source-${makeId(4)}`, config: { STRIPE_SECRET_KEY: process.env.CONNECTIONS_TEST_STRIPE_SECRET_KEY, }, }); expect(source).toHaveProperty('key'); const destination = await createDestination(client, { type: 'mongodb', group: `my-mongodb-destination-${makeId(4)}`, label: `my-mongodb-destination-${makeId(4)}`, config: { MONGODB_URI: process.env.CONNECTIONS_TEST_MONGODB_URI, }, }); expect(destination).toHaveProperty('key'); await new Promise((resolve) => setTimeout(resolve, 5000)); const subscribe = await setEvents(client, { type: 'stripe', key: source.key, events: ['customer.created'], }); expect(subscribe).toHaveProperty('success', true); await new Promise((resolve) => setTimeout(resolve, 5000)); const pipeline = await createPipeline(client, { label: `my-pipeline-${makeId(4)}`, source: { key: source.key, events: ['customer.created'], }, destination: { key: destination.key, action: 'insertOne', }, settings: { startToCloseTimeout: '30 minutes', retry: { maximumAttempts: 100, }, }, transformation: { type: 'javascript', func: transformer, }, extractors: [ { settings: { startToCloseTimeout: '30 minutes', retry: { maximumAttempts: 100, }, }, type: 'http', label: 'some_http_extractor', config: { url: 'abc.com', method: 'POST', headers: { 'Content-Type': 'application/json', }, data: { name: 'someName', age: 25, }, }, }, ], }); expect(pipeline).toHaveProperty('key'); await new Promise((resolve) => setTimeout(resolve, 10000)); const updatedPipeline = await updatePipeline(client, { key: pipeline.key, active: false, }); expect(updatedPipeline).toHaveProperty('key'); const deletePipelineResult = await deletePipeline(client, { key: pipeline.key, }); expect(deletePipelineResult).toHaveProperty('success', true); const deleteSourceResult = await deleteSource(client, { key: source.key, }); expect(deleteSourceResult).toHaveProperty('success', true); const deleteDestinationResult = await deleteDestination(client, { key: destination.key, }); expect(deleteDestinationResult).toHaveProperty('success', true); }); it('Should list all pipelines', async () => { const client = createClient( process.env.BUILDABLE_SECRET_KEY as ValidAccessKey ); const pipelineList = await listPipelines(client); expect(pipelineList).toHaveProperty('rows'); }); });