loopback-connector-remote/test/helper.js

57 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2020-02-10 18:49:27 +00:00
// Copyright IBM Corp. 2016,2019. All Rights Reserved.
2016-05-06 19:02:21 +00:00
// Node module: loopback-connector-remote
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
2016-09-01 08:12:12 +00:00
'use strict';
const extend = require('util')._extend;
const loopback = require('loopback');
const remoteConnector = require('..');
2016-01-07 06:45:29 +00:00
exports.createMemoryDataSource = createMemoryDataSource;
exports.createRemoteDataSource = createRemoteDataSource;
exports.createRestAppAndListen = createRestAppAndListen;
exports.getUserProperties = getUserProperties;
2016-02-05 12:29:43 +00:00
function createRestAppAndListen() {
const app = loopback({localRegistry: true});
2016-01-07 06:45:29 +00:00
app.set('host', '127.0.0.1');
2016-02-05 12:29:43 +00:00
app.set('port', 0);
2016-01-07 06:45:29 +00:00
2016-09-01 08:24:56 +00:00
app.set('legacyExplorer', false);
app.set('remoting', {
errorHandler: {debug: true, log: false},
2016-09-01 08:24:56 +00:00
context: false,
});
2016-01-07 06:45:29 +00:00
app.use(loopback.rest());
app.locals.handler = app.listen();
return app;
}
function createMemoryDataSource(app) {
return app.dataSource('db', {connector: 'memory'});
2016-01-07 06:45:29 +00:00
}
function createRemoteDataSource(app, serverApp) {
return app.dataSource('remote', {
url: 'http://' + serverApp.get('host') + ':' + serverApp.get('port'),
connector: remoteConnector,
2016-01-07 06:45:29 +00:00
});
}
function getUserProperties() {
return {
'first': String,
'last': String,
'age': Number,
'password': String,
'gender': String,
'domain': String,
'email': String,
2016-01-07 06:45:29 +00:00
};
}