Skip to content

Commit

Permalink
starting to add some workflow util tests
Browse files Browse the repository at this point in the history
  • Loading branch information
travjenkins committed Feb 13, 2024
1 parent d7a4a98 commit 4b26ebb
Showing 1 changed file with 73 additions and 37 deletions.
110 changes: 73 additions & 37 deletions src/utils/__tests__/workflow-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
ResourceConfigDictionary,
} from 'stores/ResourceConfig/types';
import { generateMockConnectorConfig } from 'test/test-utils';
import { EntityWithCreateWorkflow } from 'types';
import { generateTaskSpec, getBindingIndex } from 'utils/workflow-utils';
import { ConnectorConfig } from '../../../flow_deps/flow';

const defaultResponse = -1;
const foundName = 'acme/found';
Expand Down Expand Up @@ -87,70 +87,106 @@ describe('getBindingIndex', () => {
});
});

// entityType: EntityWithCreateWorkflow,
// connectorConfig: ConnectorConfig,
// resourceConfigs: ResourceConfigDictionary | null,
// existingTaskData: DraftSpecsExtQuery_ByCatalogName | null,
// sourceCapture: string | null,
// fullSource: FullSourceDictionary | null

describe('generateTaskSpec', () => {
let entityType: EntityWithCreateWorkflow,
let connectorConfig: ConnectorConfig,
resourceConfigs: ResourceConfigDictionary | null,
existingTaskData: DraftSpecsExtQuery_ByCatalogName | null,
sourceCapture: string | null,
fullSource: FullSourceDictionary | null;

const connectorConfig = generateMockConnectorConfig();
beforeEach(() => {
connectorConfig = generateMockConnectorConfig();
resourceConfigs = null;
existingTaskData = null;
sourceCapture = null;
fullSource = null;
});

describe('for captures', () => {
entityType = 'capture';
describe('when no resource configs are provided', () => {
resourceConfigs = {};
test('will return an empty array', () => {
const response = generateTaskSpec(
entityType,
connectorConfig,
resourceConfigs,
existingTaskData,
sourceCapture,
fullSource
);
expect(response.bindings).toBe([]);
});
describe('when no resource configs are provided', () => {
test('will return an empty array', () => {
const response = generateTaskSpec(
'capture',
connectorConfig,
{},
existingTaskData,
sourceCapture,
fullSource
);
expect(response.bindings).toStrictEqual([]);
});
});

describe('when resource configs are provided', () => {
const mockedResource = {
foo: 1,
bar: 2,
};
describe('when resource configs are provided', () => {
beforeEach(() => {
const mockedResourceConfig: ResourceConfig = {
errors: [],
data: mockedResource,
data: {
fiz: 'resource',
},
disable: false,
previouslyDisabled: false,
};

resourceConfigs = {
[foundName]: mockedResourceConfig,
first: mockedResourceConfig,
second: mockedResourceConfig,
};
});

test('will return an array with the names as targets', () => {
describe('for captures', () => {
test('will return an array with the names as `target`', () => {
const response = generateTaskSpec(
entityType,
'capture',
connectorConfig,
resourceConfigs,
existingTaskData,
sourceCapture,
fullSource
);
expect(response.bindings).toBe([

expect(response.bindings).toStrictEqual([
{
resource: mockedResource,
target: foundName,
resource: {
fiz: 'resource',
},
target: 'first',
},
{
resource: {
fiz: 'resource',
},
target: 'second',
},
]);
});

describe('for materializations', () => {
test('will return an array with the names as `source`', () => {
const response = generateTaskSpec(
'materialization',
connectorConfig,
resourceConfigs,
existingTaskData,
sourceCapture,
fullSource
);

expect(response.bindings).toStrictEqual([
{
resource: {
fiz: 'resource',
},
source: 'first',
},
{
resource: {
fiz: 'resource',
},
source: 'second',
},
]);
});
});
});
});
});

0 comments on commit 4b26ebb

Please sign in to comment.