Skip to content

Commit

Permalink
Merge pull request #193 from mean-expert-official/revert-192-master
Browse files Browse the repository at this point in the history
Revert "Added support for loopback http context checking"
  • Loading branch information
jonathan-casarrubias authored Nov 8, 2016
2 parents 3cb3f41 + e4c6957 commit 341475a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 71 deletions.
18 changes: 2 additions & 16 deletions lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ module.exports = function generate(ctx) {
buildMethodParams: buildMethodParams,
buildServiceImports: buildServiceImports,
normalizeMethodName: normalizeMethodName,
buildObservableType: buildObservableType,
paramIsContext: paramIsContext
buildObservableType: buildObservableType
}
}
]);
Expand Down Expand Up @@ -465,11 +464,6 @@ module.exports = function generate(ctx) {
let availableClasses = relations.map((relationName, index) =>
model.sharedClass.ctor.relations[relationName].targetClass
);

params = params.filter(param => {
return !paramIsContext(param)
});

relations.forEach(relationName => {
if (model.sharedClass.ctor.relations[relationName].modelThrough) {
let throughName = capitalize(
Expand Down Expand Up @@ -535,14 +529,6 @@ module.exports = function generate(ctx) {
function paramIsFunction(param) {
return typeof param.http === 'function'
}
/**
* @method paramIsContext
* @description
* Testing if the param is a http.context
*/
function paramIsContext(param) {
return (typeof param.http !== 'undefined' && typeof param.http.source !== 'undefined' && param.http.source === 'context');
}
/**
* @method buildPostBody
* @description
Expand Down Expand Up @@ -580,7 +566,7 @@ module.exports = function generate(ctx) {
// filter params that should not go over url query string
urlParams = urlParams.filter(param => {
// Filter out route params and function params
if (paramIsRoute(param) || paramIsFunction(param) || paramIsContext(param)) {
if (paramIsRoute(param) || paramIsFunction(param)) {
return false
}
// Filter out body params
Expand Down
7 changes: 2 additions & 5 deletions lib/angular2/shared/services/custom/service.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,14 @@ action.description = '<em>\n' +
} -%>
* <%-: action.description | replace:/\n/g, '\n * ' %>
<%
var params = action.accepts.filter(param => {
return !paramIsContext(param);
});
var params = action.accepts;
var postData;
if (httpVerb == 'POST' || httpVerb == 'PUT' || httpVerb == 'PATCH') {
params = params.filter(function(arg) {
return arg.http && (arg.http.source == 'query' || arg.http.source == 'path');
});
postData = action.accepts.filter(function(arg) {
return params.indexOf(arg) == -1 && !paramIsContext(arg);
return params.indexOf(arg) == -1;
});
}
-%>
Expand Down
35 changes: 3 additions & 32 deletions tests/angular2/common/models/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function (Room) {
Room.findByRoom = (room, next) => {
next(null, room);
};

Room.remoteMethod(
'findByRoom',
{
Expand All @@ -35,7 +35,7 @@ module.exports = function (Room) {
Room.greetPost = (b1, b2, b3, next) => {
next(null, `${b1.a}:${b2.b}:${b3.c}`);
};

Room.remoteMethod(
'greetPost',
{
Expand Down Expand Up @@ -80,35 +80,6 @@ module.exports = function (Room) {
http: { path: '/slimshady', verb: 'get' }
}
);

/**
* Mock endpoint thta checks to see if we can read the context and returns a valid result to test it.
* @param room
* @param context
* @param next
*/
Room.findByRoomContext = function(room, context, next){
var host = (typeof(context.req) !== 'undefined' && typeof(context.req.hostname) !== 'undefined' ? context.req.hostname : false);

if(host) {
room.name += host;
} else {
room = {id: -1, name: ""};
}
next(null, room);
};

Room.remoteMethod(
'findByRoomContext',
{
accepts: [
{ arg: 'room', type: 'object', http: { source: 'body' }},
{ arg: 'remoteCtx', description: '**Do not implement in clients**.', type: Object, injectCtx: true, http: { source: 'context' }}
],
returns: { arg: 'room', type: 'object', root: true },
http: { path: '/findByRoomContext', verb: 'post' }
}
);
};

function greet(a, b, c, next) { next(null, `${a}:${b}:${c}`); }
function greet(a, b, c, next) { next(null, `${a}:${b}:${c}`); }
2 changes: 1 addition & 1 deletion tests/angular2/loopback/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"port": 3000,
"remoting": {
"context": {
"enableHttpContext": true
"enableHttpContext": false
},
"rest": {
"normalizeHttpPath": false,
Expand Down
17 changes: 0 additions & 17 deletions tests/angular2/src/app/room-service.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,4 @@ describe('Service: Room Service', () => {
})))));
})
));

/**
* This test is to validate that contexts support is working
* i modify the name of the room appending the host to the name if it works
* if it doesn't work i set room.id = -1 and the name to blank
*/
it('should find by mock room to test custom remote method with context enabled',
async(inject([RoomApi], (roomApi: RoomApi) => {
let room = new Room({ id: 42, name: 'my awesome room' });
return roomApi.findByRoomContext(room)
.subscribe((instance: Room) => {
expect(room.id).toBe(instance.id);
// I append the host onto the instance name so it shouldn't match now
expect(room.name).not.toBe(instance.name);
});
})
));
});

0 comments on commit 341475a

Please sign in to comment.