Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 37 additions & 23 deletions packages/repository-tests/src/crud/freeform-properties.suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import {Entity, model, property} from '@loopback/repository';
import {EntityCrudRepository} from '@loopback/repository';
import {expect, skipIf, toJSON} from '@loopback/testlab';
import {Suite} from 'mocha';
import {MixedIdType} from '../helpers.repository-tests';
import {
withCrudCtx,
Expand All @@ -18,38 +17,53 @@ import {
CrudTestContext,
DataSourceOptions,
} from '../types.repository-tests';
import {assert} from 'console';

export function freeformPropertiesSuite(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
features: CrudFeatures,
) {
skipIf<[(this: Suite) => void], void>(
!features.freeFormProperties,
describe,
'free-form properties (strict: false)',
() => {
before(deleteAllModelsInDefaultDataSource);
@model({settings: {strict: false}})
class Freeform extends Entity {
@property({
type: features.idType,
id: true,
description: 'The unique identifier for a product',
})
id: MixedIdType;

@model({settings: {strict: false}})
class Freeform extends Entity {
@property({
type: features.idType,
id: true,
description: 'The unique identifier for a product',
})
id: MixedIdType;
@property({type: 'string', required: true})
name: string;

@property({type: 'string', required: true})
name: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[propName: string]: any;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
[propName: string]: any;
constructor(data?: Partial<Freeform>) {
super(data);
}
}
/* istanbul ignore next */
it('should warn that {strict: false} mode is not supported for SQL DBs ', async () => {
withCrudCtx(async (ctx: CrudTestContext) => {
new repositoryClass(Freeform, ctx.dataSource);
});
if (!features.freeFormProperties) {
assert(
"WARNING: relational database doesn't support {strict: false} mode. {strict: true} " +
'mode will be set for model Freeform instead.',
);
}
});

constructor(data?: Partial<Freeform>) {
super(data);
}
}
// test DBs that support freeform props
/* istanbul ignore next */
skipIf(
!features.freeFormProperties,
it,
'free-form properties {strict: false}',
async () => {
before(deleteAllModelsInDefaultDataSource);

let repo: EntityCrudRepository<Freeform, typeof Freeform.prototype.id>;

Expand Down