Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
684e8ee
commit d42454a
Showing
23 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright IBM Corp. 2019. All Rights Reserved. | ||
// Node module: @loopback/repository-tests | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {juggler} from '@loopback/repository'; | ||
import * as debugFactory from 'debug'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import {withCrudCtx} from './helpers.repository-tests'; | ||
import { | ||
CrudFeatures, | ||
CrudRepositoryCtor, | ||
CrudTestContext, | ||
DataSourceOptions, | ||
} from './types.repository-tests'; | ||
|
||
const debug = debugFactory('loopback:repository-tests'); | ||
|
||
type SuiteFn = ( | ||
dataSourceOptions: DataSourceOptions, | ||
repositoryClass: CrudRepositoryCtor, | ||
features: CrudFeatures, | ||
) => void; | ||
|
||
export function relationsRepositoryTestSuite( | ||
dataSourceOptions: DataSourceOptions, | ||
repositoryClass: CrudRepositoryCtor, | ||
partialFeatures: Partial<CrudFeatures>, | ||
) { | ||
const features: CrudFeatures = { | ||
idType: 'string', | ||
freeFormProperties: true, | ||
emptyValue: undefined, | ||
supportsTransactions: true, | ||
...partialFeatures, | ||
}; | ||
|
||
describe('RELATIONS Repository operations', () => { | ||
before( | ||
withCrudCtx(function setupContext(ctx: CrudTestContext) { | ||
ctx.dataSourceOptions = dataSourceOptions; | ||
ctx.repositoryClass = repositoryClass; | ||
ctx.features = features; | ||
}), | ||
); | ||
before( | ||
withCrudCtx(function setupGlobalDataSource(ctx: CrudTestContext) { | ||
ctx.dataSource = new juggler.DataSource(ctx.dataSourceOptions); | ||
}), | ||
); | ||
|
||
const folders = ['acceptance', 'integration/repositories']; | ||
|
||
for (const folder of folders) { | ||
const testRoot = path.resolve(__dirname, `relations/${folder}`); | ||
let testFiles = fs.readdirSync(testRoot); | ||
testFiles = testFiles.filter(function(it) { | ||
return ( | ||
(!!require.extensions[path.extname(it).toLowerCase()] && | ||
/\.acceptance\.[^.]+$/.test(it)) || | ||
(!!require.extensions[path.extname(it).toLowerCase()] && | ||
/\.integration\.[^.]+$/.test(it)) | ||
); | ||
}); | ||
|
||
console.log(testFiles); | ||
|
||
for (const ix in testFiles) { | ||
const name = testFiles[ix]; | ||
const fullPath = path.resolve(testRoot, name); | ||
debug('Loading RELATIONS test suite %j', fullPath); | ||
const allExports = require(fullPath); | ||
for (const key in allExports) { | ||
const suite: SuiteFn = allExports[key]; | ||
if (typeof suite !== 'function') continue; | ||
debug( | ||
'Calling suite function %j with args', | ||
suite.name, | ||
dataSourceOptions, | ||
'class ' + repositoryClass.name, | ||
partialFeatures, | ||
); | ||
suite(dataSourceOptions, repositoryClass, features); | ||
} | ||
} | ||
} | ||
}); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.