Comparing version 0.8.1 to 0.8.2
@@ -190,2 +190,3 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var procedure; | ||
if (options.hasOwnProperty('remote')) { | ||
@@ -202,6 +203,10 @@ if (!options.remote || typeof options.remote.type !== 'string') { | ||
var RemoteSyncProcedure = ModelObject._remoteProcedureTypesByName[remoteType]; | ||
lookup[procedureName] = new RemoteSyncProcedure(options); | ||
procedure = new RemoteSyncProcedure(options); | ||
} else { | ||
lookup[procedureName] = new SyncProcedure(options); | ||
procedure = new SyncProcedure(options); | ||
} | ||
lookup[procedureName] = procedure; | ||
return procedure; | ||
}; | ||
@@ -208,0 +213,0 @@ |
@@ -101,4 +101,2 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
throw new Error('Body is required to be passed by object'); | ||
} else if (!hasBody) { | ||
options.remote.body = null; | ||
} | ||
@@ -120,3 +118,3 @@ | ||
this.headers = _.extend(_.extend({}, CONST.DEFAULT_HEADERS), options.remote.headers); | ||
this.body = options.remote.body; | ||
this.body = options.remote.body || null; | ||
this.timeout = options.remote.timeout || CONST.DEFAULT_TIMEOUT_MS; | ||
@@ -195,2 +193,4 @@ this.httpClient = options.remote.httpClient || request; | ||
}.bind(this), callback); | ||
} else if (keyValues === null || keyValues === undefined) { | ||
return callback(null, null); | ||
} else if (typeof keyValues !== 'object') { | ||
@@ -243,6 +243,11 @@ return this._getBoundValues({value: keyValues}, scope, incoming, function(err, result) { | ||
headers: headers, | ||
json: body, | ||
timeout: this.timeout | ||
}; | ||
console.log('body', body); | ||
if (body !== undefined && body !== null) { | ||
options.json = body; | ||
} | ||
this.httpClient(options, function(err, response, body) { | ||
@@ -249,0 +254,0 @@ if (err || !response) { |
{ | ||
"name": "jetstream", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "Jetstream Sync server framework to sync local and remote models", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -51,2 +51,63 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
test(thing('should allow null body'), function t(assert) { | ||
var chatRoom = createTestChatRoom(); | ||
var syncFragments = [ | ||
new SyncFragment({ | ||
uuid: chatRoom.uuid, | ||
type: 'change', | ||
clsName: 'ChatRoom', | ||
properties: { | ||
name: 'New chat room name' | ||
} | ||
}) | ||
]; | ||
var accessToken = uuid.v4(); | ||
var scope = new Scope({name: 'TestScope', params: {accessToken: accessToken}}); | ||
var procedure = chatRoom.getProcedure('setName'); | ||
assert.ok(procedure); | ||
sandbox.stub(procedure, 'httpClient', mockHttpClient); | ||
function mockHttpClient(options, callback) { | ||
assert.equal(options.url, 'http://chatRoomAPI/room/' + chatRoom.uuid); | ||
assert.equal(options.method, 'POST'); | ||
assert.deepEqual(options.headers, { | ||
'Content-Type': 'application/json', | ||
'Authorization': scope.params.accessToken, | ||
'X-ChatRoom-SetName': 'New chat room name' | ||
}); | ||
assert.equal(options.json, undefined); | ||
callback(null, {statusCode: 200}, '{"updated": true}'); | ||
} | ||
async.waterfall([ | ||
function setRoot(nextCallback) { | ||
scope.setRoot(chatRoom, function(err) { | ||
assert.ifError(err); | ||
nextCallback(); | ||
}); | ||
}, | ||
function executeProcedure(nextCallback) { | ||
procedure.execute(scope, syncFragments, nextCallback); | ||
}, | ||
function verifyProcedureResult(result, nextCallback) { | ||
assert.ok(result instanceof SyncProcedureResult); | ||
assert.equal(result.additionalFragments.length, 0); | ||
nextCallback(); | ||
} | ||
], function(err) { | ||
assert.ifError(err); | ||
assert.end(); | ||
}); | ||
}); | ||
test(thing('should bind simple incoming and scope expression values'), function t(assert) { | ||
@@ -53,0 +114,0 @@ var chatRoom = createTestChatRoom(); |
@@ -77,2 +77,27 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
// Add procedures for procedure testing | ||
ChatRoom.defineProcedure('setName', { | ||
constraints: [ | ||
{ | ||
type: 'change', | ||
clsName: 'ChatRoom', | ||
properties: { | ||
name: hasNewValuePropertyConstraint() | ||
}, | ||
allowAdditionalProperties: false | ||
} | ||
], | ||
remote: { | ||
type: 'http', | ||
url: 'http://chatRoomAPI/room/:chatRoomUUID', | ||
params: { | ||
chatRoomUUID: expr('$incoming.ChatRoom.change.uuid') | ||
}, | ||
method: 'post', | ||
headers: { | ||
'Authorization': expr('$scope.params.accessToken'), | ||
'X-ChatRoom-SetName': expr('$incoming.ChatRoom.change.name') | ||
} | ||
} | ||
}); | ||
var caseStatusValue = {}; | ||
@@ -79,0 +104,0 @@ caseStatusValue[ChatRoomStatus.Open] = 'OPEN'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
500225
11149