Comparing version 1.0.219 to 1.0.220
@@ -1,15 +0,6 @@ | ||
import * as sqlite3 from 'sqlite3'; | ||
import { GlobalTestMutation, GlobalTestSchema } from '../test_data/global_test_schema'; | ||
import { OrmaQueryResult } from '../types/query/query_result_types'; | ||
import { WhereConnected } from '../types/query/query_types'; | ||
import { OrmaQueryResult } from '../types/query/query_result_types'; | ||
type TestDatabase = { | ||
db: sqlite3.Database | undefined; | ||
file_name: string; | ||
}; | ||
export declare const remove_file: (file_name: string) => void; | ||
export declare const open_database: (test_database: TestDatabase) => Promise<void>; | ||
export declare const close_database: (test_database: TestDatabase) => Promise<void>; | ||
export declare const integration_test_setup: () => void; | ||
export declare const register_integration_test: () => void; | ||
export declare const test_mutate: (mutation: GlobalTestMutation, where_connecteds?: WhereConnected<GlobalTestSchema>) => Promise<void>; | ||
export declare const test_query: <T extends Record<string, any>>(query: T) => Promise<OrmaQueryResult<GlobalTestSchema, T, never>>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.test_query = exports.test_mutate = exports.integration_test_setup = exports.close_database = exports.open_database = exports.remove_file = void 0; | ||
const fs_1 = require("fs"); | ||
exports.test_query = exports.test_mutate = exports.register_integration_test = void 0; | ||
const mocha_1 = require("mocha"); | ||
const sqlite3 = require("sqlite3"); | ||
const database_adapters_1 = require("../helpers/database_adapters"); | ||
const helpers_1 = require("../helpers/helpers"); | ||
const global_test_schema_1 = require("../test_data/global_test_schema"); | ||
const mutate_1 = require("../mutate/mutate"); | ||
const mutate_validation_1 = require("../mutate/verifications/mutate_validation"); | ||
const mutation_connected_1 = require("../mutate/verifications/mutation_connected"); | ||
const json_sql_1 = require("../query/json_sql"); | ||
const verify_uniqueness_1 = require("../mutate/verifications/verify_uniqueness"); | ||
const where_connected_macro_1 = require("../query/macros/where_connected_macro"); | ||
const query_1 = require("../query/query"); | ||
const query_validation_1 = require("../query/validation/query_validation"); | ||
const schema_macro_1 = require("../schema/schema_macro"); | ||
const global_test_hydration_1 = require("../test_data/global_test_hydration"); | ||
const verify_uniqueness_1 = require("../mutate/verifications/verify_uniqueness"); | ||
const global_test_schema_1 = require("../test_data/global_test_schema"); | ||
const integration_test_helpers_1 = require("./integration_test_helpers"); | ||
let test_database = { | ||
db: undefined, | ||
file_name: 'test_database', | ||
}; | ||
const checkpoint_name = 'test_database_checkpoint'; | ||
const remove_file = (file_name) => { | ||
if ((0, fs_1.existsSync)(file_name)) { | ||
(0, fs_1.unlinkSync)(file_name); | ||
} | ||
const test_database_directory = './'; | ||
(0, mocha_1.before)(async () => { | ||
test_database.db = await (0, integration_test_helpers_1.set_up_test_database)(global_test_schema_1.global_test_schema, global_test_hydration_1.global_test_hydration, test_database_directory); | ||
}); | ||
after(async () => (0, integration_test_helpers_1.tear_down_test_database)(test_database.db, test_database_directory)); | ||
const register_integration_test = () => { | ||
(0, mocha_1.beforeEach)(async () => (test_database.db = await (0, integration_test_helpers_1.reset_test_database)(test_database.db, test_database_directory))); | ||
}; | ||
exports.remove_file = remove_file; | ||
const clear_database_files = () => { | ||
(0, exports.remove_file)(test_database.file_name); | ||
(0, exports.remove_file)(checkpoint_name); | ||
}; | ||
const open_database = async (test_database) => new Promise((accept, reject) => (test_database.db = new sqlite3.Database(test_database.file_name, e => (e ? reject() : accept())))); | ||
exports.open_database = open_database; | ||
const close_database = async (test_database) => new Promise((resolve, reject) => { var _a; return (_a = test_database.db) === null || _a === void 0 ? void 0 : _a.close(err => (err ? reject(err) : resolve())); }); | ||
exports.close_database = close_database; | ||
const integration_test_setup = () => { | ||
(0, mocha_1.before)(async () => { | ||
clear_database_files(); | ||
await (0, exports.open_database)(test_database); | ||
const schema_diff = (0, schema_macro_1.get_schema_diff)({ $entities: {} }, global_test_schema_1.global_test_schema); | ||
const statements = schema_diff.map(ast => ({ | ||
sql_string: (0, json_sql_1.json_to_sql)(ast, 'sqlite'), | ||
})); | ||
await (0, database_adapters_1.sqlite3_adapter)(test_database.db)(statements); | ||
await (0, exports.test_mutate)(global_test_hydration_1.global_test_hydration); | ||
(0, fs_1.copyFileSync)(test_database.file_name, checkpoint_name); | ||
}); | ||
(0, mocha_1.beforeEach)(async () => { | ||
await (0, exports.close_database)(test_database); | ||
(0, fs_1.copyFileSync)(checkpoint_name, test_database.file_name); | ||
await (0, exports.open_database)(test_database); | ||
}); | ||
after(async () => { | ||
await (0, exports.close_database)(test_database); | ||
clear_database_files(); | ||
}); | ||
}; | ||
exports.integration_test_setup = integration_test_setup; | ||
exports.register_integration_test = register_integration_test; | ||
const connection_edges = (0, where_connected_macro_1.add_connection_edges)((0, where_connected_macro_1.get_upwards_connection_edges)(global_test_schema_1.global_test_schema), [ | ||
@@ -63,0 +30,0 @@ { |
@@ -11,4 +11,6 @@ "use strict"; | ||
const integration_setup_test_1 = require("./integration_setup.test"); | ||
const file_helpers_1 = require("../helpers/file_helpers"); | ||
const integration_test_helpers_1 = require("./integration_test_helpers"); | ||
(0, mocha_1.describe)('full integration test', () => { | ||
(0, integration_setup_test_1.integration_test_setup)(); | ||
(0, integration_setup_test_1.register_integration_test)(); | ||
(0, mocha_1.test)('Handles orma schema with no nesting', async () => { | ||
@@ -49,6 +51,6 @@ const mutation = { | ||
const mutation_plan = (0, mutate_1.orma_mutate_prepare)(orma_schema, mutation); | ||
const database = { db: undefined, file_name: 'simple_test' }; | ||
await (0, integration_setup_test_1.remove_file)(database.file_name); | ||
await (0, integration_setup_test_1.open_database)(database); | ||
await (0, database_adapters_1.sqlite3_adapter)(database.db)([ | ||
const db_file_name = 'simple_test'; | ||
await (0, file_helpers_1.remove_file)(db_file_name); | ||
const db = await (0, integration_test_helpers_1.open_sqlite_database)(db_file_name); | ||
await (0, database_adapters_1.sqlite3_adapter)(db)([ | ||
{ | ||
@@ -58,5 +60,5 @@ sql_string: 'CREATE TABLE users (user_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL, age INTEGER)', | ||
]); | ||
await (0, mutate_1.orma_mutate_run)(orma_schema, (0, database_adapters_1.sqlite3_adapter)(database.db), mutation_plan); | ||
await (0, integration_setup_test_1.close_database)(database); | ||
await (0, integration_setup_test_1.remove_file)(database.file_name); | ||
await (0, mutate_1.orma_mutate_run)(orma_schema, (0, database_adapters_1.sqlite3_adapter)(db), mutation_plan); | ||
await (0, integration_test_helpers_1.close_sqlite_database)(db); | ||
(0, file_helpers_1.remove_file)(db_file_name); | ||
(0, chai_1.expect)(mutation.users[0].user_id).to.equal(1); | ||
@@ -63,0 +65,0 @@ }); |
{ | ||
"name": "orma", | ||
"version": "1.0.219", | ||
"version": "1.0.220", | ||
"description": "A declarative relational syncronous orm", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -1,15 +0,9 @@ | ||
import { copyFileSync, existsSync, unlinkSync } from 'fs' | ||
import { before, beforeEach, describe, test } from 'mocha' | ||
import { before, beforeEach } from 'mocha' | ||
import * as sqlite3 from 'sqlite3' | ||
import { sqlite3_adapter } from '../helpers/database_adapters' | ||
import { validate_errors } from '../helpers/helpers' | ||
import { | ||
GlobalTestMutation, | ||
GlobalTestSchema, | ||
global_test_schema, | ||
} from '../test_data/global_test_schema' | ||
import { orma_mutate_prepare, orma_mutate_run } from '../mutate/mutate' | ||
import { validate_mutation } from '../mutate/verifications/mutate_validation' | ||
import { get_mutation_connected_errors } from '../mutate/verifications/mutation_connected' | ||
import { json_to_sql } from '../query/json_sql' | ||
import { get_unique_verification_errors } from '../mutate/verifications/verify_uniqueness' | ||
import { | ||
@@ -21,71 +15,42 @@ add_connection_edges, | ||
import { validate_query } from '../query/validation/query_validation' | ||
import { get_schema_diff } from '../schema/schema_macro' | ||
import { WhereConnected } from '../types/query/query_types' | ||
import { global_test_hydration } from '../test_data/global_test_hydration' | ||
import { get_unique_verification_errors } from '../mutate/verifications/verify_uniqueness' | ||
import { | ||
GlobalTestMutation, | ||
GlobalTestSchema, | ||
global_test_schema, | ||
} from '../test_data/global_test_schema' | ||
import { OrmaQueryResult } from '../types/query/query_result_types' | ||
import { WhereConnected } from '../types/query/query_types' | ||
import { | ||
reset_test_database, | ||
set_up_test_database, | ||
tear_down_test_database, | ||
} from './integration_test_helpers' | ||
type TestDatabase = { | ||
db: sqlite3.Database | undefined | ||
file_name: string | ||
let test_database = { | ||
db: undefined as sqlite3.Database | undefined, | ||
} | ||
let test_database: TestDatabase = { | ||
db: undefined, | ||
file_name: 'test_database', | ||
} | ||
const checkpoint_name = 'test_database_checkpoint' | ||
const test_database_directory = './' | ||
export const remove_file = (file_name: string) => { | ||
if (existsSync(file_name)) { | ||
unlinkSync(file_name) | ||
} | ||
} | ||
before(async () => { | ||
test_database.db = await set_up_test_database( | ||
global_test_schema, | ||
global_test_hydration, | ||
test_database_directory | ||
) | ||
}) | ||
const clear_database_files = () => { | ||
remove_file(test_database.file_name) | ||
remove_file(checkpoint_name) | ||
} | ||
after(async () => | ||
tear_down_test_database(test_database.db, test_database_directory) | ||
) | ||
export const open_database = async (test_database: TestDatabase) => | ||
new Promise<void>( | ||
(accept, reject) => | ||
(test_database.db = new sqlite3.Database( | ||
test_database.file_name, | ||
e => (e ? reject() : accept()) | ||
export const register_integration_test = () => { | ||
beforeEach( | ||
async () => | ||
(test_database.db = await reset_test_database( | ||
test_database.db, | ||
test_database_directory | ||
)) | ||
) | ||
export const close_database = async (test_database: TestDatabase) => | ||
new Promise<void>((resolve, reject) => | ||
test_database.db?.close(err => (err ? reject(err) : resolve())) | ||
) | ||
export const integration_test_setup = () => { | ||
before(async () => { | ||
clear_database_files() | ||
await open_database(test_database) | ||
const schema_diff = get_schema_diff( | ||
{ $entities: {} }, | ||
global_test_schema | ||
) | ||
const statements = schema_diff.map(ast => ({ | ||
sql_string: json_to_sql(ast, 'sqlite'), | ||
})) | ||
await sqlite3_adapter(test_database.db!)(statements) | ||
await test_mutate(global_test_hydration) | ||
copyFileSync(test_database.file_name, checkpoint_name) | ||
}) | ||
beforeEach(async () => { | ||
await close_database(test_database) | ||
copyFileSync(checkpoint_name, test_database.file_name) | ||
await open_database(test_database) | ||
}) | ||
after(async () => { | ||
await close_database(test_database) | ||
clear_database_files() | ||
}) | ||
} | ||
@@ -92,0 +57,0 @@ |
@@ -11,12 +11,14 @@ import { expect } from 'chai' | ||
import { | ||
close_database, | ||
integration_test_setup, | ||
open_database, | ||
remove_file, | ||
register_integration_test, | ||
test_mutate, | ||
test_query, | ||
} from './integration_setup.test' | ||
import { remove_file } from '../helpers/file_helpers' | ||
import { | ||
close_sqlite_database, | ||
open_sqlite_database, | ||
} from './integration_test_helpers' | ||
describe('full integration test', () => { | ||
integration_test_setup() | ||
register_integration_test() | ||
@@ -67,8 +69,8 @@ test('Handles orma schema with no nesting', async () => { | ||
const mutation_plan = orma_mutate_prepare(orma_schema, mutation) | ||
const database = { db: undefined, file_name: 'simple_test' } | ||
await remove_file(database.file_name) | ||
await open_database(database) | ||
const db_file_name = 'simple_test' | ||
await remove_file(db_file_name) | ||
const db = await open_sqlite_database(db_file_name) | ||
await sqlite3_adapter(database.db!)([ | ||
await sqlite3_adapter(db)([ | ||
{ | ||
@@ -79,10 +81,6 @@ sql_string: | ||
]) | ||
await orma_mutate_run( | ||
orma_schema, | ||
sqlite3_adapter(database.db!), | ||
mutation_plan | ||
) | ||
await orma_mutate_run(orma_schema, sqlite3_adapter(db), mutation_plan) | ||
await close_database(database) | ||
await remove_file(database.file_name) | ||
await close_sqlite_database(db) | ||
remove_file(db_file_name) | ||
expect(mutation.users[0].user_id).to.equal(1) | ||
@@ -89,0 +87,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1583129
340
38612
6