()
| 617 | |
| 618 | // helpers |
| 619 | function setupAppAndRequest() { |
| 620 | app = loopback({localRegistry: true, loadBuiltinModels: true}); |
| 621 | app.use(loopback.rest()); |
| 622 | app.set('remoting', {errorHandler: {debug: true, log: true}}); |
| 623 | app.dataSource('db', {connector: 'memory'}); |
| 624 | request = supertest(app); |
| 625 | |
| 626 | app.enableAuth({dataSource: 'db'}); |
| 627 | models = app.models; |
| 628 | |
| 629 | // Speed up the password hashing algorithm for tests |
| 630 | models.User.settings.saltWorkFactor = 4; |
| 631 | |
| 632 | // creating a custom model |
| 633 | const MyTestModel = app.registry.createModel('MyTestModel'); |
| 634 | app.model(MyTestModel, {dataSource: 'db'}); |
| 635 | |
| 636 | // capturing the value of the last remoting context |
| 637 | models.MyTestModel.beforeRemote('find', function(ctx, unused, next) { |
| 638 | models.MyTestModel.lastRemotingContext = ctx; |
| 639 | next(); |
| 640 | }); |
| 641 | |
| 642 | // creating a user, a role and a rolemapping binding that user with that role |
| 643 | return Promise.all([ |
| 644 | models.User.create({username: 'myUser', email: 'myuser@example.com', password: 'pass'}), |
| 645 | models.Role.create({name: 'myRole'}), |
| 646 | ]) |
| 647 | .spread(function(myUser, myRole) { |
| 648 | return Promise.all([ |
| 649 | myRole.principals.create({principalType: 'USER', principalId: myUser.id}), |
| 650 | models.User.login({username: 'myUser', password: 'pass'}), |
| 651 | ]); |
| 652 | }) |
| 653 | .spread(function(role, token) { |
| 654 | accessToken = token; |
| 655 | }); |
| 656 | } |
| 657 | |
| 658 | function createACLs(model, acls) { |
| 659 | acls = acls.map(function(acl) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…