Skip to content

Commit

Permalink
refactor(repository-tests): rename CrudConnectorFeatures to CrudFeatures
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Jul 8, 2019
1 parent 9695a52 commit 672698d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {
CrudConnectorFeatures,
DataSourceOptions,
} from '@loopback/repository-tests';
import {CrudFeatures, DataSourceOptions} from '@loopback/repository-tests';

const connector = require('loopback-connector-mongodb');

Expand All @@ -17,6 +14,6 @@ export const MONGODB_CONFIG: DataSourceOptions = {
database: process.env.MONGODB_DATABASE || 'repository-tests',
};

export const MONGODB_FEATURES: Partial<CrudConnectorFeatures> = {
export const MONGODB_FEATURES: Partial<CrudFeatures> = {
idType: 'string',
};
7 changes: 2 additions & 5 deletions acceptance/repository-mysql/src/__tests__/mysql.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {
CrudConnectorFeatures,
DataSourceOptions,
} from '@loopback/repository-tests';
import {CrudFeatures, DataSourceOptions} from '@loopback/repository-tests';

const connector = require('loopback-connector-mysql');

Expand All @@ -20,7 +17,7 @@ export const MYSQL_CONFIG: DataSourceOptions = {
createDatabase: true,
};

export const MYSQL_FEATURES: Partial<CrudConnectorFeatures> = {
export const MYSQL_FEATURES: Partial<CrudFeatures> = {
idType: 'number',
freeFormProperties: false,
};
15 changes: 8 additions & 7 deletions packages/repository-tests/src/crud-test-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as fs from 'fs';
import * as path from 'path';
import {withCrudCtx} from './helpers.repository-tests';
import {
CrudConnectorFeatures,
CrudFeatures,
CrudRepositoryCtor,
CrudTestContext,
DataSourceOptions,
Expand All @@ -20,26 +20,27 @@ const debug = debugFactory('loopback:repository-tests');
type SuiteFn = (
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
connectorFeatures: CrudConnectorFeatures,
features: CrudFeatures,
) => void;

export function crudRepositoryTestSuite(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
connectorFeatures: Partial<CrudConnectorFeatures>,
partialFeatures: Partial<CrudFeatures>,
) {
const features: CrudConnectorFeatures = {
const features: CrudFeatures = {
idType: 'string',
freeFormProperties: true,
...connectorFeatures,
inclusionResolvers: true,
...partialFeatures,
};

describe('CRUD Repository operations', () => {
before(
withCrudCtx(function setupContext(ctx: CrudTestContext) {
ctx.dataSourceOptions = dataSourceOptions;
ctx.repositoryClass = repositoryClass;
ctx.connectorFeatures = features;
ctx.features = features;
}),
);
before(
Expand Down Expand Up @@ -70,7 +71,7 @@ export function crudRepositoryTestSuite(
suite.name,
dataSourceOptions,
'class ' + repositoryClass.name,
connectorFeatures,
features,
);
suite(dataSourceOptions, repositoryClass, features);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/repository-tests/src/crud/create-retrieve.suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {EntityCrudRepository} from '@loopback/repository/src';
import {expect, toJSON} from '@loopback/testlab';
import {withCrudCtx} from '../helpers.repository-tests';
import {
CrudConnectorFeatures,
CrudFeatures,
CrudRepositoryCtor,
CrudTestContext,
DataSourceOptions,
Expand All @@ -19,12 +19,12 @@ import {
export function createRetrieveSuite(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
connectorFeatures: CrudConnectorFeatures,
features: CrudFeatures,
) {
@model()
class Product extends Entity {
@property({
type: connectorFeatures.idType,
type: features.idType,
id: true,
generated: true,
description: 'The unique identifier for a product',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {expect, skipIf, toJSON} from '@loopback/testlab';
import {Suite} from 'mocha';
import {withCrudCtx} from '../helpers.repository-tests';
import {
CrudConnectorFeatures,
CrudFeatures,
CrudRepositoryCtor,
CrudTestContext,
DataSourceOptions,
Expand All @@ -18,17 +18,17 @@ import {
export function freeformPropertiesSuite(
dataSourceOptions: DataSourceOptions,
repositoryClass: CrudRepositoryCtor,
connectorFeatures: CrudConnectorFeatures,
features: CrudFeatures,
) {
skipIf<[(this: Suite) => void], void>(
!connectorFeatures.freeFormProperties,
!features.freeFormProperties,
describe,
'free-form properties (strict: false)',
() => {
@model({settings: {strict: false}})
class Freeform extends Entity {
@property({
type: connectorFeatures.idType,
type: features.idType,
id: true,
description: 'The unique identifier for a product',
})
Expand Down
10 changes: 5 additions & 5 deletions packages/repository-tests/src/types.repository-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {
export type DataSourceOptions = Options;

/**
* List of flags describing connector-specific behavior. These flags
* are used by the test suite to tweak assertions and skip tests
* for scenarios not supported by some connectors.
* List of flags describing behavior specific to a connector and a repository
* class being tested. These flags are used by the test suite to tweak
* assertions and skip tests for scenarios not supported by some connectors.
*/
export interface CrudConnectorFeatures {
export interface CrudFeatures {
/**
* What type is used for auto-generated primary keys?
* - SQL databases typically use auto-incremented numbers,
Expand Down Expand Up @@ -60,6 +60,6 @@ export type CrudRepositoryCtor = new <
export interface CrudTestContext {
dataSourceOptions: DataSourceOptions;
repositoryClass: CrudRepositoryCtor;
connectorFeatures: CrudConnectorFeatures;
features: CrudFeatures;
dataSource: juggler.DataSource;
}

0 comments on commit 672698d

Please sign in to comment.