Skip to content

Commit

Permalink
test(repository-tests): add test for SQL DBs strict mode warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnes Lin authored and agnes512 committed Jan 23, 2020
1 parent a02b814 commit eb2cb23
Showing 1 changed file with 37 additions and 23 deletions.
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

0 comments on commit eb2cb23

Please sign in to comment.