(userSettings)
| 155 | }); |
| 156 | |
| 157 | function givenAppWithUser(userSettings) { |
| 158 | app = loopback({localRegistry: true, loadBuiltinModels: true}); |
| 159 | app.set('remoting', {rest: {handleErrors: false}}); |
| 160 | app.dataSource('db', {connector: 'memory'}); |
| 161 | |
| 162 | userSettings = Object.assign({ |
| 163 | name: 'PwdUser', |
| 164 | base: 'User', |
| 165 | properties: { |
| 166 | name: 'string', |
| 167 | }, |
| 168 | |
| 169 | // Speed up the password hashing algorithm for tests |
| 170 | saltWorkFactor: 4, |
| 171 | |
| 172 | http: {path: '/users'}, |
| 173 | }, userSettings); |
| 174 | |
| 175 | User = app.registry.createModel(userSettings); |
| 176 | app.model(User, {dataSource: 'db'}); |
| 177 | |
| 178 | const AccessToken = app.registry.getModel('AccessToken'); |
| 179 | AccessToken.settings.relations.user.model = User.modelName; |
| 180 | |
| 181 | app.enableAuth({dataSource: 'db'}); |
| 182 | |
| 183 | app.use(loopback.token()); |
| 184 | app.use(loopback.rest()); |
| 185 | app.use(function logUnexpectedError(err, req, res, next) { |
| 186 | const statusCode = err.statusCode || err.status; |
| 187 | if (statusCode > 400 && statusCode !== 401) { |
| 188 | console.log('Unexpected error for %s %s: %s %s', |
| 189 | req.method, req.path, statusCode, err.stack || err); |
| 190 | } |
| 191 | next(err); |
| 192 | }); |
| 193 | app.use(errorHandler({debug: true, log: false})); |
| 194 | |
| 195 | return User.create(credentials) |
| 196 | .then(u => { |
| 197 | testUser = u; |
| 198 | return u.setAttribute('emailVerified', true); |
| 199 | }); |
| 200 | } |
| 201 | |
| 202 | function givenRegularAccessToken() { |
| 203 | return User.login(credentials).then(t => regularToken = t); |
no test coverage detected
searching dependent graphs…