This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JS API: Convert rep payload to/from JS object
Fixes gh-28
- Loading branch information
Gabriel Schulhof
committed
Nov 5, 2015
1 parent
ee48cca
commit caf3369
Showing
5 changed files
with
281 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
var resource, | ||
_ = require( "lodash" ), | ||
async = require( "async" ), | ||
uuid = process.argv[ 2 ], | ||
device = require( "../../../index" )(), | ||
testUtils = require( "../../assert-to-console" ); | ||
|
||
console.log( JSON.stringify( { assertionCount: 1 } ) ); | ||
|
||
async.series( [ | ||
|
||
function initStack( callback ) { | ||
device.configure( { | ||
role: "client", | ||
connectionMode: "acked" | ||
} ).then( callback, callback ); | ||
}, | ||
|
||
function discoverResource( callback ) { | ||
Promise.all( [ | ||
new Promise( function( fulfill ) { | ||
var resourceFound = function( event ) { | ||
if ( event.resource.url === "/a/" + uuid ) { | ||
resource = event.resource; | ||
fulfill(); | ||
device.client.removeEventListener( "resourcefound", resourceFound ); | ||
} | ||
}; | ||
device.client.addEventListener( "resourcefound", resourceFound ); | ||
} ), | ||
device.client.findResources() | ||
] ).then( | ||
function() { | ||
callback(); | ||
}, callback ); | ||
}, | ||
|
||
function performRetrieve( callback ) { | ||
device.client.retrieveResource( resource.id ).then( | ||
function( resource ) { | ||
testUtils.assert( "deepEqual", resource.properties, { | ||
primitiveValue: 42, | ||
objectValue: { | ||
childValue: 91 | ||
}, | ||
arrayValue: [ 19, 23, 7 ] | ||
}, "Client: Retrieved properties are correct" ); | ||
callback(); | ||
}, | ||
callback ); | ||
}, | ||
|
||
function performUpdate( callback ) { | ||
device.client.updateResource( resource.id, _.extend( resource, { | ||
properties: { | ||
putValue: "A string", | ||
anotherPutValue: 23.7, | ||
childValues: { | ||
putChildValue: false, | ||
putChildArray: [ [ 2, 3, 5 ], [ 9, 11, 17 ] ] | ||
} | ||
} | ||
} ) ).then( callback, callback ); | ||
} | ||
], function( error ) { | ||
if ( error ) { | ||
testUtils.die( "Client: " + error.message + ", result: " + error.result ); | ||
} | ||
} ); |
Oops, something went wrong.