Skip to content

Commit

Permalink
Cleaning up tests a bit
Browse files Browse the repository at this point in the history
Adding handling for source capture testing
  • Loading branch information
travjenkins committed Feb 13, 2024
1 parent 97092bb commit 74bafd8
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 42 deletions.
31 changes: 31 additions & 0 deletions src/utils/__tests__/__snapshots__/workflow-utils.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`generateTaskSpec > when existing data and new data > duplicates in existing bindings > will update all copies in the bindings 1`] = `
[
{
"resource": {
"bar": "updated",
},
"target": "mock/binding/one",
},
{
"backfill": 2,
"resource": {
"fiz": "resource",
},
"target": "mock/binding/two",
},
{
"resource": {
"bar": "updated",
},
"target": "mock/binding/one",
},
{
"resource": {
"bar": "updated",
},
"target": "mock/binding/one",
},
]
`;
122 changes: 80 additions & 42 deletions src/utils/__tests__/workflow-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('generateTaskSpec', () => {
});
});

describe('when existing data and binding data', () => {
describe('when existing data and new data', () => {
beforeEach(() => {
connectorConfig = generateMockConnectorConfig();
existingTaskData = {
Expand Down Expand Up @@ -245,62 +245,100 @@ describe('generateTaskSpec', () => {
},
]);
});

describe('duplicates in existing bindings', () => {
beforeEach(() => {
if (!existingTaskData) {
return console.log('missing data');
}

existingTaskData.spec.bindings.push(
existingTaskData.spec.bindings[0]
);
existingTaskData.spec.bindings.push(
existingTaskData.spec.bindings[0]
);
});

test('will update all copies in the bindings', () => {
const response = generateTaskSpec(
'capture',
connectorConfig,
{
'mock/binding/one': {
...mockedResourceConfig,
data: {
bar: 'updated',
},
},
'mock/binding/two': mockedResourceConfig,
},
existingTaskData,
sourceCapture,
fullSource
);

expect(response.bindings).toMatchSnapshot();
});
});
});

describe('the resource config key goes to different properties for each entity', () => {
describe('entity type can alter what is returned', () => {
beforeEach(() => {
resourceConfigs = {
first: mockedResourceConfig,
second: mockedResourceConfig,
};
});

test('captures use `target` as the binding name', () => {
const response = generateTaskSpec(
'capture',
connectorConfig,
resourceConfigs,
existingTaskData,
sourceCapture,
fullSource
);
test('captures use `target` and materializations use `source` as the binding name', () => {
expect(
generateTaskSpec(
'capture',
connectorConfig,
resourceConfigs,
existingTaskData,
sourceCapture,
fullSource
).bindings.map(({ target }: any) => target)
).toStrictEqual(['first', 'second']);

expect(
response.bindings.map(({ target }: any) => ({
target,
}))
).toStrictEqual([
{
target: 'first',
},
{
target: 'second',
},
]);
generateTaskSpec(
'materialization',
connectorConfig,
resourceConfigs,
existingTaskData,
sourceCapture,
fullSource
).bindings.map(({ source }: any) => source)
).toStrictEqual(['first', 'second']);
});

test('materializations use `source` as the binding name', () => {
const response = generateTaskSpec(
'materialization',
connectorConfig,
resourceConfigs,
existingTaskData,
sourceCapture,
fullSource
);
test('only materializations can return the `sourceCapture` property', () => {
sourceCapture = 'mock/source/capture';

expect(
response.bindings.map(({ source }: any) => ({
source,
}))
).toStrictEqual([
{
source: 'first',
},
{
source: 'second',
},
]);
generateTaskSpec(
'capture',
connectorConfig,
resourceConfigs,
existingTaskData,
sourceCapture,
fullSource
).sourceCapture
).toBeUndefined();

expect(
generateTaskSpec(
'materialization',
connectorConfig,
resourceConfigs,
existingTaskData,
sourceCapture,
fullSource
).sourceCapture
).toStrictEqual(sourceCapture);
});
});
});

0 comments on commit 74bafd8

Please sign in to comment.