Socket
Socket
Sign inDemoInstall

orma

Package Overview
Dependencies
Maintainers
2
Versions
233
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orma - npm Package Compare versions

Comparing version 1.0.249 to 1.0.250

30

build/integration_tests/integration_setup.test.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.test_query = exports.test_mutate = exports.register_integration_test = void 0;
const chai_1 = require("chai");
const mocha_1 = require("mocha");

@@ -18,3 +19,3 @@ const database_adapters_1 = require("../helpers/database_adapters");

let test_database = {
db: undefined,
db: undefined
};

@@ -27,3 +28,8 @@ const 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)));
(0, mocha_1.beforeEach)(async () => {
test_database.db = await (0, integration_test_helpers_1.reset_test_database)(test_database.db, test_database_directory);
await (0, database_adapters_1.sqlite3_adapter)(test_database.db)([
{ sql_string: 'PRAGMA foreign_keys = ON' }
]);
});
};

@@ -36,3 +42,3 @@ exports.register_integration_test = register_integration_test;

to_entity: 'users',
to_field: 'billing_address_id',
to_field: 'billing_address_id'
},

@@ -43,4 +49,4 @@ {

to_entity: 'users',
to_field: 'shipping_address_id',
},
to_field: 'shipping_address_id'
}
]);

@@ -52,3 +58,3 @@ const test_mutate = async (mutation, where_connecteds = []) => {

await (0, mutation_connected_1.get_mutation_connected_errors)(global_test_schema_1.global_test_schema, connection_edges, (0, database_adapters_1.sqlite3_adapter)(test_database.db), mutation_plan.guid_map, where_connecteds, mutation_plan.mutation_pieces),
await (0, verify_uniqueness_1.get_unique_verification_errors)(global_test_schema_1.global_test_schema, (0, database_adapters_1.sqlite3_adapter)(test_database.db), mutation_plan),
await (0, verify_uniqueness_1.get_unique_verification_errors)(global_test_schema_1.global_test_schema, (0, database_adapters_1.sqlite3_adapter)(test_database.db), mutation_plan)
]);

@@ -65,1 +71,13 @@ const res = await (0, mutate_1.orma_mutate_run)(global_test_schema_1.global_test_schema, (0, database_adapters_1.sqlite3_adapter)(test_database.db), mutation_plan);

exports.test_query = test_query;
(0, mocha_1.describe)('integration_setup', () => {
(0, exports.register_integration_test)();
(0, mocha_1.test)('uses sqlite foreign keys', async () => {
// not allowed since there there are posts that are children of users
const executed_query = await (0, database_adapters_1.sqlite3_adapter)(test_database.db)([
{ sql_string: 'DELETE FROM users WHERE id = 1' }
])
.then(() => true)
.catch(() => false);
(0, chai_1.expect)(executed_query).to.equal(false);
});
});

115

build/prepopulate/prepopulate.test.js

@@ -8,17 +8,7 @@ "use strict";

const prepopulate_1 = require("./prepopulate");
(0, mocha_1.describe)('Prepopulate', () => {
mocha_1.describe.only('Prepopulate', () => {
(0, integration_setup_test_1.register_integration_test)();
(0, mocha_1.test)('Prepopulate without supercede', async () => {
var _a, _b;
// Get users
const result = await (0, integration_setup_test_1.test_query)({
users: {
id: true,
},
});
// Delete users
await (0, integration_setup_test_1.test_mutate)({
$operation: 'delete',
users: (_a = result.users) === null || _a === void 0 ? void 0 : _a.map(el => ({ id: el.id })).slice(0, 1),
});
var _a;
await delete_users();
const schema = Object.assign(Object.assign({}, global_test_schema_1.global_test_schema), { $entities: Object.assign(Object.assign({}, global_test_schema_1.global_test_schema.$entities), { users: Object.assign(Object.assign({}, global_test_schema_1.global_test_schema.$entities.users), { $prepopulate: {

@@ -30,3 +20,3 @@ supercede: false,

first_name: 'John',
email: 'test',
email: 'test'
},

@@ -36,5 +26,5 @@ {

first_name: 'Jane',
email: 'test2',
},
],
email: 'test2'
}
]
} }) }) });

@@ -46,19 +36,10 @@ await (0, prepopulate_1.prepopulate)(integration_setup_test_1.test_query, integration_setup_test_1.test_mutate, schema);

id: true,
},
first_name: true
}
});
(0, chai_1.expect)((_b = result2.users) === null || _b === void 0 ? void 0 : _b.length).to.equal(3);
(0, chai_1.expect)((_a = result2.users) === null || _a === void 0 ? void 0 : _a.length).to.equal(3);
});
(0, mocha_1.test)('Prepopulate with supercede', async () => {
var _a, _b;
// Get users
const result = await (0, integration_setup_test_1.test_query)({
users: {
id: true,
},
});
// Delete users
await (0, integration_setup_test_1.test_mutate)({
$operation: 'delete',
users: (_a = result.users) === null || _a === void 0 ? void 0 : _a.map(el => ({ id: el.id })).slice(0, 1),
});
var _a;
await delete_users();
const schema = Object.assign(Object.assign({}, global_test_schema_1.global_test_schema), { $entities: Object.assign(Object.assign({}, global_test_schema_1.global_test_schema.$entities), { users: Object.assign(Object.assign({}, global_test_schema_1.global_test_schema.$entities.users), { $prepopulate: {

@@ -70,3 +51,3 @@ supercede: true,

first_name: 'John',
email: 'test',
email: 'test'
},

@@ -76,5 +57,5 @@ {

first_name: 'Jane',
email: 'test2',
},
],
email: 'test2'
}
]
} }) }) });

@@ -85,20 +66,9 @@ await (0, prepopulate_1.prepopulate)(integration_setup_test_1.test_query, integration_setup_test_1.test_mutate, schema);

users: {
id: true,
},
id: true
}
});
(0, chai_1.expect)((_b = result2.users) === null || _b === void 0 ? void 0 : _b.length).to.equal(2);
(0, chai_1.expect)((_a = result2.users) === null || _a === void 0 ? void 0 : _a.length).to.equal(2);
});
(0, mocha_1.test)('Can fail nicely', async () => {
var _a;
// Get users
const result = await (0, integration_setup_test_1.test_query)({
users: {
id: true,
},
});
// Delete users
await (0, integration_setup_test_1.test_mutate)({
$operation: 'delete',
users: (_a = result.users) === null || _a === void 0 ? void 0 : _a.map(el => ({ id: el.id })).slice(0, 1),
});
await delete_users();
const schema = Object.assign(Object.assign({}, global_test_schema_1.global_test_schema), { $entities: Object.assign(Object.assign({}, global_test_schema_1.global_test_schema.$entities), { users: Object.assign(Object.assign({}, global_test_schema_1.global_test_schema.$entities.users), { $prepopulate: {

@@ -110,3 +80,3 @@ supercede: true,

first_name: 'John',
email: 'test',
email: 'test'
},

@@ -116,5 +86,5 @@ {

first_name: 'Jane',
email: 'test',
},
],
email: 'test'
}
]
} }) }) });

@@ -130,14 +100,3 @@ try {

(0, mocha_1.test)('Can run multiple times', async () => {
var _a;
// Get users
const result = await (0, integration_setup_test_1.test_query)({
users: {
id: true,
},
});
// Delete users
await (0, integration_setup_test_1.test_mutate)({
$operation: 'delete',
users: (_a = result.users) === null || _a === void 0 ? void 0 : _a.map(el => ({ id: el.id })).slice(0, 1),
});
await delete_users();
const schema = Object.assign(Object.assign({}, global_test_schema_1.global_test_schema), { $entities: Object.assign(Object.assign({}, global_test_schema_1.global_test_schema.$entities), { users: Object.assign(Object.assign({}, global_test_schema_1.global_test_schema.$entities.users), { $prepopulate: {

@@ -149,3 +108,3 @@ supercede: true,

first_name: 'John',
email: 'test',
email: 'test'
},

@@ -155,5 +114,5 @@ {

first_name: 'Jane',
email: 'test3',
},
],
email: 'test3'
}
]
} }) }) });

@@ -169,1 +128,17 @@ try {

});
const delete_users = async () => {
// Get users
const result = await (0, integration_setup_test_1.test_query)({
users: {
id: true,
$where: { $eq: ['id', { $escape: 1 }] }
},
posts: {
id: true,
user_id: true,
comments: { id: true }
}
});
// Delete users id 1 and also all posts to avoid fk constraint fail
await (0, integration_setup_test_1.test_mutate)(Object.assign({ $operation: 'delete' }, result));
};
{
"name": "orma",
"version": "1.0.249",
"version": "1.0.250",
"description": "A declarative relational syncronous orm",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -1,2 +0,3 @@

import { before, beforeEach } from 'mocha'
import { expect } from 'chai'
import { before, beforeEach, describe, test } from 'mocha'
import * as sqlite3 from 'sqlite3'

@@ -11,3 +12,3 @@ import { sqlite3_adapter } from '../helpers/database_adapters'

add_connection_edges,
get_upwards_connection_edges,
get_upwards_connection_edges
} from '../query/macros/where_connected_macro'

@@ -18,6 +19,5 @@ import { orma_query } from '../query/query'

import {
GlobalTestAliases,
GlobalTestMutation,
GlobalTestSchema,
global_test_schema,
global_test_schema
} from '../test_data/global_test_schema'

@@ -29,7 +29,7 @@ import { OrmaQueryResult } from '../types/query/query_result_types'

set_up_test_database,
tear_down_test_database,
tear_down_test_database
} from './integration_test_helpers'
let test_database = {
db: undefined as sqlite3.Database | undefined,
db: undefined as sqlite3.Database | undefined
}

@@ -52,9 +52,11 @@

export const register_integration_test = () => {
beforeEach(
async () =>
(test_database.db = await reset_test_database(
test_database.db,
test_database_directory
))
)
beforeEach(async () => {
test_database.db = await reset_test_database(
test_database.db,
test_database_directory
)
await sqlite3_adapter(test_database.db)([
{ sql_string: 'PRAGMA foreign_keys = ON' }
])
})
}

@@ -69,3 +71,3 @@

to_entity: 'users',
to_field: 'billing_address_id',
to_field: 'billing_address_id'
},

@@ -76,4 +78,4 @@ {

to_entity: 'users',
to_field: 'shipping_address_id',
},
to_field: 'shipping_address_id'
}
]

@@ -101,3 +103,3 @@ )

mutation_plan
),
)
])

@@ -125,1 +127,15 @@

}
describe('integration_setup', () => {
register_integration_test()
test('uses sqlite foreign keys', async () => {
// not allowed since there there are posts that are children of users
const executed_query = await sqlite3_adapter(test_database.db!)([
{ sql_string: 'DELETE FROM users WHERE id = 1' }
])
.then(() => true)
.catch(() => false)
expect(executed_query).to.equal(false)
})
})

@@ -6,3 +6,3 @@ import { expect } from 'chai'

test_mutate,
test_query,
test_query
} from '../integration_tests/integration_setup.test'

@@ -12,3 +12,3 @@ import {

GlobalTestSchema,
global_test_schema,
global_test_schema
} from '../test_data/global_test_schema'

@@ -18,19 +18,8 @@ import { OrmaMutation } from '../types/mutation/mutation_types'

describe('Prepopulate', () => {
describe.only('Prepopulate', () => {
register_integration_test()
test('Prepopulate without supercede', async () => {
// Get users
const result = await test_query({
users: {
id: true,
},
} as const satisfies GlobalTestQuery)
await delete_users()
// Delete users
await test_mutate({
$operation: 'delete',
users: result.users?.map(el => ({ id: el.id })).slice(0, 1),
})
const schema = {

@@ -48,3 +37,3 @@ ...global_test_schema,

first_name: 'John',
email: 'test',
email: 'test'
},

@@ -54,10 +43,10 @@ {

first_name: 'Jane',
email: 'test2',
},
email: 'test2'
}
] as NonNullable<
OrmaMutation<GlobalTestSchema>['users']
>,
},
},
},
>
}
}
}
}

@@ -71,3 +60,4 @@

id: true,
},
first_name: true
}
} as const satisfies GlobalTestQuery)

@@ -78,15 +68,4 @@

test('Prepopulate with supercede', async () => {
// Get users
const result = await test_query({
users: {
id: true,
},
} as const satisfies GlobalTestQuery)
await delete_users()
// Delete users
await test_mutate({
$operation: 'delete',
users: result.users?.map(el => ({ id: el.id })).slice(0, 1),
})
const schema = {

@@ -104,3 +83,3 @@ ...global_test_schema,

first_name: 'John',
email: 'test',
email: 'test'
},

@@ -110,10 +89,10 @@ {

first_name: 'Jane',
email: 'test2',
},
email: 'test2'
}
] as NonNullable<
OrmaMutation<GlobalTestSchema>['users']
>,
},
},
},
>
}
}
}
}

@@ -126,4 +105,4 @@

users: {
id: true,
},
id: true
}
} as const satisfies GlobalTestQuery)

@@ -134,15 +113,4 @@

test('Can fail nicely', async () => {
// Get users
const result = await test_query({
users: {
id: true,
},
} as const satisfies GlobalTestQuery)
await delete_users()
// Delete users
await test_mutate({
$operation: 'delete',
users: result.users?.map(el => ({ id: el.id })).slice(0, 1),
})
const schema = {

@@ -160,3 +128,3 @@ ...global_test_schema,

first_name: 'John',
email: 'test',
email: 'test'
},

@@ -166,10 +134,10 @@ {

first_name: 'Jane',
email: 'test',
},
email: 'test'
}
] as NonNullable<
OrmaMutation<GlobalTestSchema>['users']
>,
},
},
},
>
}
}
}
}

@@ -185,15 +153,4 @@

test('Can run multiple times', async () => {
// Get users
const result = await test_query({
users: {
id: true,
},
} as const satisfies GlobalTestQuery)
await delete_users()
// Delete users
await test_mutate({
$operation: 'delete',
users: result.users?.map(el => ({ id: el.id })).slice(0, 1),
})
const schema = {

@@ -211,3 +168,3 @@ ...global_test_schema,

first_name: 'John',
email: 'test',
email: 'test'
},

@@ -217,10 +174,10 @@ {

first_name: 'Jane',
email: 'test3',
},
email: 'test3'
}
] as NonNullable<
OrmaMutation<GlobalTestSchema>['users']
>,
},
},
},
>
}
}
}
}

@@ -236,1 +193,22 @@

})
const delete_users = async () => {
// Get users
const result = await test_query({
users: {
id: true,
$where: { $eq: ['id', { $escape: 1 }] }
},
posts: {
id: true,
user_id: true,
comments: { id: true }
}
} as const satisfies GlobalTestQuery)
// Delete users id 1 and also all posts to avoid fk constraint fail
await test_mutate({
$operation: 'delete',
...result
})
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc