Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cb => {
metaschema.fs
.load(
[
getPathFromCurrentDir('.', 'schemas'),
// TODO add other schemas here
],
{
...options,
context: {
api: {
argon2,
common,
console,
jstp,
provider,
},
},
metatests.test('Fully supports schemas/system', async test => {
let schema;
try {
schema = await metaschema.fs.load(
'test/fixtures/validate',
options,
config
);
} catch (error) {
console.error(error);
test.fail(error);
test.end();
return;
}
test.strictSame(
schema.validate('category', 'Person', {
Id: '12',
FullName: {
FirstName: 'Name',
metatests.test('Unsupported domain class', async test => {
const expectedErrorMessage =
"Unsupported domain class '__UNSUPPORTED_CLASS__' in domain 'Test'";
let schema;
try {
schema = await metaschema.fs.load(
'test/fixtures/unsupported-domain-class',
options,
config
);
} catch (error) {
console.error(error);
test.fail(error);
test.end();
return;
}
test.throws(() => generateDDL(schema), new Error(expectedErrorMessage));
test.end();
});
metatests.test('Fully supports schemas/system', async test => {
let schema;
try {
schema = await metaschema.fs.load(
'test/fixtures/resources',
options,
config
);
} catch (error) {
console.error(error);
test.fail(error);
test.end();
return;
}
test.strictSame(schema.resources.common.get('en'), '{"Id":"Identifier"}');
test.strictSame(schema.resources.domains.get('en'), '{"Id":"Identifier"}');
test.strictSame(
schema.actions.get('PublicAction').resources.get('en'),
'{"Login":"Login"}'
metatests.test('cursor schema', async test => {
const languages = [
{ Id: 1, Name: 'English', Locale: 'en' },
{ Id: 2, Name: 'Ukrainian', Locale: 'uk' },
{ Id: 3, Name: 'Russian', Locale: 'ru' },
];
let schema;
try {
schema = await metaschema.fs.load('schemas/system', options, config);
} catch (err) {
test.fail(err);
test.end();
return;
}
const schemaName = 'Language';
const category = schema.categories.get(schemaName).definition;
const mcLanguages = new MemoryCursor(languages).definition(
category,
schemaName
);
const data = await mcLanguages
.select({ Locale: '> en' })
.order('Name')
async test => {
let schema;
try {
schema = await metaschema.fs.load(
'test/fixtures/resources',
options,
config
);
} catch (error) {
console.error(error);
test.fail(error);
test.end();
return;
}
const provider = new StorageProvider({});
await provider.open({ schema });
test.endAfterSubtests();
metatests.test('pg.ddl.generateLinks unit test', async test => {
let schema;
try {
schema = await metaschema.fs.load(schemasDir, options, config);
} catch (err) {
test.fail(err);
test.end();
return;
}
test.strictSame(
ddl.generateLinks(
[
{
from: 'LocalCategory2',
to: 'LocalCategory1',
name: 'field',
link: schema.categories.get('LocalCategory2').definition.field,
destination: 'LocalCategory1',
},
metatests.test('pg.ddl.generateTable unit test', async test => {
let schema;
try {
schema = await metaschema.fs.load(schemasDir, options, config);
} catch (err) {
test.fail(err);
test.end();
return;
}
test.strictSame(
ddl.generateTable(
'LocalCategory2',
schema.categories.get('LocalCategory2').definition,
'Local',
new Map([['Nomen', 'text']]),
new Map(),
[],
schema.categories
),
async test => {
try {
const initSql = await util.promisify(fs.readFile)(
getPathFromCurrentDir('..', 'sql', 'id.sql'),
'utf8'
);
await pool.query(initSql);
const schema = await metaschema.fs.load(
[
getPathFromCurrentDir('..', 'schemas', 'system'),
getPathFromCurrentDir('fixtures', 'pg-test-schemas'),
],
options,
config
);
await provider.open({ schema, ...pgOptions });
await pool.query(generateDDL(provider.schema));
await provider[recreateIdTrigger](1000, 30);
await provider[uploadMetadata]();
} catch (err) {
if (process.env.CI) {
test.fail('PostgreSQL setup failed');
} else {
test.beforeEach(async (test, callback) => {
let schema;
try {
schema = await metaschema.fs.load(schemasDir, options, config);
} catch (err) {
test.fail(err);
test.end();
return;
}
const provider = new StorageProvider({});
await provider.open({ schema });
callback({ provider });
});