Skip to content

Commit

Permalink
Merge branch 'main' into docu
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-schwarz committed Dec 7, 2023
2 parents 937b40f + 2e5f611 commit 6b21215
Show file tree
Hide file tree
Showing 105 changed files with 2,785 additions and 46 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@
},
{
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
"plugins": ["jest"],
"env": {
"jest": true
},
"rules": {}
"rules": {
// you should turn the original rule off *only* for test files
"@typescript-eslint/unbound-method": "off",
"jest/unbound-method": "error"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

import { FileExtension, MimeType } from '@jvalue/jayvee-execution';
import { FileExtension, MimeType } from '../types';

import {
inferFileExtensionFromContentTypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

import { FileExtension, MimeType } from '@jvalue/jayvee-execution';
import * as mime from 'mime-types';

import { FileExtension, MimeType } from '../types';

export function inferMimeTypeFromFileExtensionString(
fileExtension: string | undefined,
): MimeType | undefined {
Expand Down
2 changes: 2 additions & 0 deletions libs/execution/src/lib/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
// SPDX-License-Identifier: AGPL-3.0-only

export * from './implements-static-decorator';
export * from './file-util';
export * from './string-util';
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ import {
FileExtension,
MimeType,
TextFile,
} from '@jvalue/jayvee-execution';

import {
inferFileExtensionFromFileExtensionString,
inferMimeTypeFromFileExtensionString,
} from '../src/file-util';
import { splitLines } from '../src/string-util';
splitLines,
} from '../../src';

export function createBinaryFileFromLocalFile(fileName: string): BinaryFile {
const extName = path.extname(fileName);
Expand Down
6 changes: 6 additions & 0 deletions libs/execution/test/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
//
// SPDX-License-Identifier: AGPL-3.0-only

export * from './test-infrastructure-util';
export * from './file-util';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TableColumn,
blockExecutorRegistry,
constraintExecutorRegistry,
} from '../src';
} from '../../src';

export function clearBlockExecutorRegistry() {
blockExecutorRegistry.clear();
Expand Down
174 changes: 174 additions & 0 deletions libs/extensions/rdbms/exec/src/lib/postgres-loader-executor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
//
// SPDX-License-Identifier: AGPL-3.0-only

import * as path from 'path';

import * as R from '@jvalue/jayvee-execution';
import {
constructTable,
getTestExecutionContext,
} from '@jvalue/jayvee-execution/test';
import {
BlockDefinition,
IOType,
PrimitiveValuetypes,
createJayveeServices,
} from '@jvalue/jayvee-language-server';
import {
ParseHelperOptions,
expectNoParserAndLexerErrors,
loadTestExtensions,
parseHelper,
readJvTestAssetHelper,
} from '@jvalue/jayvee-language-server/test';
import { AstNode, AstNodeLocator, LangiumDocument } from 'langium';
import { NodeFileSystem } from 'langium/node';

import { PostgresLoaderExecutor } from './postgres-loader-executor';

// eslint-disable-next-line no-var
var databaseConnectMock: jest.Mock;
// eslint-disable-next-line no-var
var databaseQueryMock: jest.Mock;
// eslint-disable-next-line no-var
var databaseEndMock: jest.Mock;
jest.mock('pg', () => {
databaseConnectMock = jest.fn();
databaseQueryMock = jest.fn();
databaseEndMock = jest.fn();
const mClient = {
connect: databaseConnectMock,
query: databaseQueryMock,
end: databaseEndMock,
};
return { Client: jest.fn(() => mClient) };
});

describe('Validation of PostgresLoaderExecutor', () => {
let parse: (
input: string,
options?: ParseHelperOptions,
) => Promise<LangiumDocument<AstNode>>;

let locator: AstNodeLocator;

const readJvTestAsset = readJvTestAssetHelper(
__dirname,
'../../test/assets/postgres-loader-executor/',
);

async function parseAndExecuteExecutor(
input: string,
IOInput: R.Table,
): Promise<R.Result<R.None>> {
const document = await parse(input, { validationChecks: 'all' });
expectNoParserAndLexerErrors(document);

const block = locator.getAstNode<BlockDefinition>(
document.parseResult.value,
'pipelines@0/blocks@1',
) as BlockDefinition;

return new PostgresLoaderExecutor().doExecute(
IOInput,
getTestExecutionContext(locator, document, [block]),
);
}

beforeAll(async () => {
// Create language services
const services = createJayveeServices(NodeFileSystem).Jayvee;
await loadTestExtensions(services, [
path.resolve(__dirname, '../../test/test-extension/TestBlockTypes.jv'),
]);
locator = services.workspace.AstNodeLocator;
// Parse function for Jayvee (without validation)
parse = parseHelper(services);
});
afterEach(() => {
jest.clearAllMocks();
});

it('should diagnose no error on valid loader config', async () => {
const text = readJvTestAsset('valid-postgres-loader.jv');

const inputTable = constructTable(
[
{
columnName: 'Column1',
column: {
values: ['value 1'],
valuetype: PrimitiveValuetypes.Text,
},
},
{
columnName: 'Column2',
column: {
values: [20.2],
valuetype: PrimitiveValuetypes.Decimal,
},
},
],
1,
);
const result = await parseAndExecuteExecutor(text, inputTable);

expect(R.isErr(result)).toEqual(false);
if (R.isOk(result)) {
expect(result.right.ioType).toEqual(IOType.NONE);
expect(databaseConnectMock).toBeCalledTimes(1);
expect(databaseQueryMock).nthCalledWith(
1,
'DROP TABLE IF EXISTS "Test";',
);
expect(databaseQueryMock).nthCalledWith(
2,
`CREATE TABLE IF NOT EXISTS "Test" ("Column1" text,"Column2" real);`,
);
expect(databaseQueryMock).nthCalledWith(
3,
`INSERT INTO "Test" ("Column1","Column2") VALUES ('value 1',20.2)`,
);
expect(databaseEndMock).toBeCalledTimes(1);
}
});

it('should diagnose error on pg client connect error', async () => {
const text = readJvTestAsset('valid-postgres-loader.jv');

const inputTable = constructTable(
[
{
columnName: 'Column1',
column: {
values: ['value 1'],
valuetype: PrimitiveValuetypes.Text,
},
},
{
columnName: 'Column2',
column: {
values: [20.2],
valuetype: PrimitiveValuetypes.Decimal,
},
},
],
1,
);
databaseConnectMock.mockImplementation(() => {
throw new Error('Connection error');
});
const result = await parseAndExecuteExecutor(text, inputTable);

expect(R.isOk(result)).toEqual(false);
if (R.isErr(result)) {
expect(result.left.message).toEqual(
'Could not write to postgres database: Connection error',
);
expect(databaseConnectMock).toBeCalledTimes(1);
expect(databaseQueryMock).toBeCalledTimes(0);
expect(databaseEndMock).toBeCalledTimes(1);
}
});
});
Loading

0 comments on commit 6b21215

Please sign in to comment.