-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jean-PhilippeD
committed
Sep 25, 2016
1 parent
2e84047
commit 91ef1e4
Showing
4 changed files
with
66 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var queries = require('./deviceType.queries.js'); | ||
var Promise = require('bluebird'); | ||
|
||
module.exports = function(type){ | ||
|
||
// get all deviceTypes for a given tag | ||
return gladys.utils.sql(queries.getByType, [type]) | ||
.then(function(deviceTypes){ | ||
// if there is some deviceTypes for this tag | ||
if(deviceTypes.length){ | ||
// return deviceTypes | ||
return deviceTypes; | ||
} else { | ||
return null; | ||
} | ||
|
||
}); | ||
} |
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
23 changes: 23 additions & 0 deletions
23
test/unit/api/core/devicetype/deviceType.getByType.test.js
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,23 @@ | ||
var should = require('should'); | ||
var validateDeviceType = require('../../validator/deviceTypeValidator.js'); | ||
|
||
describe('DeviceType', function() { | ||
|
||
describe('getByType', function() { | ||
|
||
it('should return a deviceType', function (done) { | ||
|
||
var type = 'binary'; | ||
|
||
gladys.deviceType.getByType(type).then(function(type){ | ||
validateDeviceType(type); | ||
done(); | ||
}).catch(function(err){ | ||
done(err); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
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,22 @@ | ||
module.exports = validate; | ||
|
||
var should = require('should'); | ||
|
||
function validate(devicetype) { | ||
if(devicetype instanceof Array) { | ||
devicetype.forEach(validateDeviceType); | ||
} else { | ||
validateDeviceType(devicetype); | ||
} | ||
} | ||
|
||
function validateDeviceType(devicetype) { | ||
device.should.be.instanceOf(Object); | ||
device.should.have.property('id'); | ||
device.should.have.property('type'); | ||
device.should.have.property('tag'); | ||
device.should.have.property('sensor'); | ||
device.should.have.property('device'); | ||
device.should.have.property('min'); | ||
device.should.have.property('max'); | ||
} |