Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('datasource booter unit tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const DATASOURCES_PREFIX = 'datasources';
const DATASOURCES_TAG = 'datasource';
class AppWithRepo extends RepositoryMixin(Application) {}
let app: AppWithRepo;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let stub: sinon.SinonStub<[any?, ...any[]], void>;
beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(getApp);
beforeEach(createStub);
afterEach(restoreStub);
it('gives a warning if called on an app without RepositoryMixin', async () => {
describe('repository booter unit tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const REPOSITORIES_PREFIX = 'repositories';
const REPOSITORIES_TAG = 'repository';
class RepoApp extends RepositoryMixin(Application) {}
let app: RepoApp;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let stub: sinon.SinonStub<[any?, ...any[]], void>;
beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(getApp);
beforeEach(createStub);
afterEach(restoreStub);
it('gives a warning if called on an app without RepositoryMixin', async () => {
describe('repository booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
// Remnants from Refactor -- need to add these to core
const REPOSITORIES_PREFIX = 'repositories';
const REPOSITORIES_TAG = 'repository';
let app: BooterApp;
beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(getApp);
it('boots repositories when app.boot() is called', async () => {
const expectedBindings = [
`${REPOSITORIES_PREFIX}.ArtifactOne`,
`${REPOSITORIES_PREFIX}.ArtifactTwo`,
];
describe('lifecycle script booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const OBSERVER_PREFIX = CoreBindings.LIFE_CYCLE_OBSERVERS;
const OBSERVER_TAG = CoreTags.LIFE_CYCLE_OBSERVER;
let app: BooterApp;
beforeEach(function resetSandbox() {
return sandbox.reset();
});
beforeEach(getApp);
it('boots life cycle observers when app.boot() is called', async () => {
const expectedBinding = {
key: `${OBSERVER_PREFIX}.MyLifeCycleObserver`,
tags: [ContextTags.TYPE, OBSERVER_TAG],
scope: BindingScope.SINGLETON,
describe('interceptor script booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
let app: BooterApp;
beforeEach(function resetSandbox() {
return sandbox.reset();
});
beforeEach(buildAppWithInterceptors);
it('boots global interceptors when app.boot() is called', async () => {
const expectedBinding = {
key: `${GLOBAL_INTERCEPTOR_NAMESPACE}.myGlobalInterceptor`,
tags: [
ContextTags.PROVIDER,
ContextTags.TYPE,
ContextTags.GLOBAL_INTERCEPTOR,
ContextTags.NAMESPACE,
describe('booter-utils unit tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
beforeEach('reset sandbox', () => sandbox.reset());
describe('discoverFiles()', () => {
beforeEach(setupSandbox);
it('discovers files matching a nested glob pattern', async () => {
const expected = [
resolve(SANDBOX_PATH, 'empty.artifact.js'),
resolve(SANDBOX_PATH, 'nested/multiple.artifact.js'),
];
const glob = '/**/*.artifact.js';
const files = await discoverFiles(glob, SANDBOX_PATH);
expect(files.sort()).to.eql(expected.sort());
});
describe('controller booter unit tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const CONTROLLERS_PREFIX = 'controllers';
const CONTROLLERS_TAG = 'controller';
let app: Application;
beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(getApp);
it(`constructor uses ControllerDefaults for 'options' if none are given`, () => {
const booterInst = new ControllerBooter(app, SANDBOX_PATH);
expect(booterInst.options).to.deepEqual(ControllerDefaults);
});
it('overrides defaults with provided options and uses defaults for rest', () => {
const options = {
describe('datasource booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const DATASOURCES_PREFIX = 'datasources';
const DATASOURCES_TAG = 'datasource';
let app: BooterApp;
beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(getApp);
it('boots datasources when app.boot() is called', async () => {
const expectedBindings = [`${DATASOURCES_PREFIX}.db`];
await app.boot();
const bindings = app.findByTag(DATASOURCES_TAG).map(b => b.key);
expect(bindings.sort()).to.eql(expectedBindings.sort());
describe('service booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const SERVICES_PREFIX = 'services';
const SERVICES_TAG = 'service';
let app: BooterApp;
beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(getApp);
it('boots services when app.boot() is called', async () => {
const expectedBindings = [
'services.BindableGreetingService',
'services.CurrentDate',
'services.GeocoderService',
'services.NotBindableDate',
];
describe('application metadata booter acceptance tests', () => {
let app: BooterApp;
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(getApp);
it('binds content of package.json to application metadata', async () => {
await app.boot();
const metadata = await app.get(CoreBindings.APPLICATION_METADATA);
expect(metadata).containEql({
name: 'boot-test-app',
version: '1.0.0',
description: 'boot-test-app',
});
});
async function getApp() {
await sandbox.copyFile(resolve(__dirname, '../fixtures/package.json'));