Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const invocationCtx = givenInvocationContext();
const keys = invocationCtx.getGlobalInterceptorBindingKeys();
expect(keys).to.eql([
'globalInterceptors.authInterceptor',
'globalInterceptors.logInterceptor',
]);
});
// See https://v8.dev/blog/array-sort
function isSortStable() {
// v8 7.0 or above
return +process.versions.v8.split('.')[0] >= 7;
}
skipIf(
!isSortStable(),
it,
'sorts by binding order without group tags',
async () => {
ctx
.bind('globalInterceptors.authInterceptor')
.to(authInterceptor)
.apply(asGlobalInterceptor());
ctx
.bind('globalInterceptors.logInterceptor')
.to(logInterceptor)
.apply(asGlobalInterceptor());
const invocationCtx = givenInvocationContext();
...odin,
parentId: features.emptyValue,
orders: [
{
...odinPizza,
isShipped: features.emptyValue,
// eslint-disable-next-line @typescript-eslint/camelcase
shipment_id: features.emptyValue,
},
],
};
expect(toJSON(result)).to.containEql(toJSON(expected));
},
);
skipIf(
features.hasRevisionToken,
it,
'returns inclusions after running replaceById() operation',
async () => {
// this shows replaceById() works well with func ensurePersistable and ObjectId
// the test skips for Cloudant as it needs the _rev property for replacement.
// see replace-by-id.suite.ts
const thor = await customerRepo.create({name: 'Thor'});
const odin = await customerRepo.create({name: 'Odin'});
const thorOrder = await orderRepo.create({
customerId: thor.id,
description: 'Pizza',
});
const pizza = await orderRepo.findById(thorOrder.id.toString());
export function hasManyInclusionResolverAcceptance(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
features: CrudFeatures,
) {
skipIf<[(this: Suite) => void], void>(
!features.supportsInclusionResolvers,
describe,
'Multi relations inclusion resolvers - acceptance',
suite,
);
function suite() {
before(deleteAllModelsInDefaultDataSource);
let customerRepo: CustomerRepository;
let orderRepo: OrderRepository;
before(
withCrudCtx(async function setupRepository(ctx: CrudTestContext) {
// this helper should create the inclusion resolvers and also
// register inclusion resolvers for us
({customerRepo, orderRepo} = givenBoundCrudRepositories(
ctx.dataSource,
export function hasManyInclusionResolverAcceptance(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
features: CrudFeatures,
) {
skipIf<[(this: Suite) => void], void>(
!features.supportsInclusionResolvers,
describe,
'HasMany inclusion resolvers - acceptance',
suite,
);
function suite() {
before(deleteAllModelsInDefaultDataSource);
let customerRepo: CustomerRepository;
let orderRepo: OrderRepository;
before(
withCrudCtx(async function setupRepository(ctx: CrudTestContext) {
// this helper should create the inclusion resolvers and also
// register inclusion resolvers for us
({customerRepo, orderRepo} = givenBoundCrudRepositories(
ctx.dataSource,
const expected = {
...odin,
parentId: features.emptyValue,
orders: [
{
...odinOrder,
isShipped: features.emptyValue,
// eslint-disable-next-line @typescript-eslint/camelcase
shipment_id: features.emptyValue,
},
],
};
expect(toJSON(result)).to.deepEqual(toJSON(expected));
});
skipIf(
features.hasRevisionToken,
it,
'returns inclusions after running save() operation',
async () => {
// this shows save() works well with func ensurePersistable and ObjectId
// the test skips for Cloudant as it needs the _rev property for replacement.
// see replace-by-id.suite.ts
const thor = await customerRepo.create({name: 'Thor'});
const odin = await customerRepo.create({name: 'Odin'});
const thorOrder = await orderRepo.create({
customerId: thor.id,
description: 'Pizza',
});
const pizza = await orderRepo.findById(thorOrder.id);
export function hasOneInclusionResolverAcceptance(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
features: CrudFeatures,
) {
skipIf<[(this: Suite) => void], void>(
!features.supportsInclusionResolvers,
describe,
'HasOne inclusion resolvers - acceptance',
suite,
);
function suite() {
before(deleteAllModelsInDefaultDataSource);
let customerRepo: CustomerRepository;
let addressRepo: AddressRepository;
before(
withCrudCtx(async function setupRepository(ctx: CrudTestContext) {
// this helper should create the inclusion resolvers and also
// register inclusion resolvers for us
({customerRepo, addressRepo} = givenBoundCrudRepositories(
ctx.dataSource,
export function belongsToInclusionResolverAcceptance(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
features: CrudFeatures,
) {
skipIf<[(this: Suite) => void], void>(
!features.supportsInclusionResolvers,
describe,
'BelongsTo inclusion resolvers - acceptance',
suite,
);
function suite() {
before(deleteAllModelsInDefaultDataSource);
let customerRepo: CustomerRepository;
let orderRepo: OrderRepository;
before(
withCrudCtx(async function setupRepository(ctx: CrudTestContext) {
// this helper should create the inclusion resolvers and also
// register inclusion resolvers for us
({customerRepo, orderRepo} = givenBoundCrudRepositories(
ctx.dataSource,
export function transactionSuite(
dataSourceOptions: DataSourceOptions,
repositoryClass: TransactionalRepositoryCtor,
connectorFeatures: CrudFeatures,
) {
skipIf<[(this: Suite) => void], void>(
!connectorFeatures.supportsTransactions,
describe,
`transactions`,
() => {
@model()
class Product extends Entity {
@property({
type: connectorFeatures.idType,
id: true,
generated: true,
description: 'The unique identifier for a product',
})
id: MixedIdType;
@property({type: 'string', required: true})
name: string;
mongodb: {
dataType: 'ObjectID',
},
})
categoryId: number | string;
constructor(data?: Partial) {
super(data);
}
}
interface ItemRelations {
category?: Category;
}
skipIf<[(this: Suite) => void], void>(
!features.inclusionResolvers,
describe,
'retrieve models including relations',
() => {
let categoryRepo: EntityCrudRepository<
Category,
typeof Category.prototype.id,
CategoryRelations
>;
let itemRepo: EntityCrudRepository<
Item,
typeof Item.prototype.id,
ItemRelations
>;
before(
withCrudCtx(async function setupRepository(ctx: CrudTestContext) {