Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('gives a warning if called on an app without RepositoryMixin', async () => {
const normalApp = new Application();
await sandbox.copyFile(
resolve(__dirname, '../../fixtures/multiple.artifact.js'),
);
const booterInst = new RepositoryBooter(
normalApp as ApplicationWithRepositories,
SANDBOX_PATH,
);
// Load uses discovered property
booterInst.discovered = [resolve(SANDBOX_PATH, 'multiple.artifact.js')];
await booterInst.load();
sinon.assert.calledOnce(stub);
sinon.assert.calledWith(
stub,
'app.repository() function is needed for RepositoryBooter. You can add it ' +
'to your Application using RepositoryMixin from @loopback/repository.',
);
});
it('logs the error', async () => {
const logger = sinon.spy() as LogError & SinonSpy;
const reject = new RejectProvider(logger).value();
reject(contextStub, testError);
await contextStub.result;
sinon.assert.calledWith(logger, testError, 500, contextStub.request);
});
it('creates a todo on a todoList', async () => {
create.resolves(aTodoWithId);
expect(await controller.create(aTodoListWithId.id!, aTodo)).to.eql(
aTodoWithId,
);
sinon.assert.calledWith(todos, aTodoListWithId.id!);
sinon.assert.calledWith(create, aTodo);
});
});
it('returns an empty array when no instances have the foreign key values', async () => {
const find = productRepo.stubs.find;
find.resolves([]);
await productRepo.create({id: 1, name: 'product', categoryId: 1});
const products = await findByForeignKeys(productRepo, 'categoryId', [2, 3]);
expect(products).to.be.empty();
sinon.assert.calledWithMatch(find, {});
});
it('calls autoupdate on registered datasources', async () => {
app.dataSource(DataSourceStub);
await app.migrateSchema({existingSchema: 'alter'});
sinon.assert.called(updateStub);
sinon.assert.notCalled(migrateStub);
});
it('gives a warning if called on an app without RepositoryMixin', async () => {
const normalApp = new Application();
await sandbox.copyFile(
resolve(__dirname, '../../fixtures/datasource.artifact.js'),
);
const booterInst = new DataSourceBooter(
normalApp as ApplicationWithRepositories,
SANDBOX_PATH,
);
booterInst.discovered = [resolve(SANDBOX_PATH, 'datasource.artifact.js')];
await booterInst.load();
sinon.assert.calledOnce(stub);
sinon.assert.calledWith(
stub,
'app.dataSource() function is needed for DataSourceBooter. You can add ' +
'it to your Application using RepositoryMixin from @loopback/repository.',
);
});
it('gives a warning if called on an app without RepositoryMixin', async () => {
const normalApp = new Application();
await sandbox.copyFile(
resolve(__dirname, '../../fixtures/datasource.artifact.js'),
);
const booterInst = new DataSourceBooter(
normalApp as ApplicationWithRepositories,
SANDBOX_PATH,
);
booterInst.discovered = [resolve(SANDBOX_PATH, 'datasource.artifact.js')];
await booterInst.load();
sinon.assert.calledOnce(stub);
sinon.assert.calledWith(
stub,
'app.dataSource() function is needed for DataSourceBooter. You can add ' +
'it to your Application using RepositoryMixin from @loopback/repository.',
);
});
it('creates a TodoList', async () => {
const create = todoListRepo.stubs.create;
create.resolves(aTodoListWithId);
expect(await controller.create(aTodoList)).to.eql(aTodoListWithId);
sinon.assert.calledWith(create, aTodoList);
});
});
it('can find related model instance', async () => {
const constraint: Partial = {name: 'Jane'};
const hasManyCrudInstance = givenDefaultHasManyInstance(constraint);
await hasManyCrudInstance.find({where: {id: 3}});
sinon.assert.calledWithMatch(customerRepo.stubs.find, {
where: {id: 3, name: 'Jane'},
});
});
expect(spy.called).to.be.False();
await client.get('/off').expect(200, 'off called');
expect(spy.called).to.be.False();
await client.get('/debug').expect(200, 'debug called');
sinon.assert.calledWith(spy, debugMatch);
await client.get('/info').expect(200, 'info called');
sinon.assert.calledWith(spy, infoMatch);
await client.get('/warn').expect(200, 'warn called');
sinon.assert.calledWith(spy, warnMatch);
await client.get('/error').expect(200, 'error called');
sinon.assert.calledWith(spy, errorMatch);
await client.get('/?name=test').expect(200, 'hello test');
sinon.assert.calledWith(spy, nameMatch);
});