-
-
Notifications
You must be signed in to change notification settings - Fork 288
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
1 parent
cf7b9d2
commit 23bbda2
Showing
9 changed files
with
170 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Gladys Project | ||
* http://gladysproject.com | ||
* Software under licence Creative Commons 3.0 France | ||
* http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ | ||
* You may not use this software for commercial purposes. | ||
* @author :: Pierre-Gilles Leymarie | ||
*/ | ||
|
||
/** | ||
* LockController | ||
* | ||
* @description :: Server-side logic for managing locks | ||
* @help :: See http://links.sailsjs.org/docs/controllers | ||
*/ | ||
|
||
module.exports = { | ||
|
||
create: function(req, res, next){ | ||
gladys.machine.create(req.body) | ||
.then((machine) => res.json(machine)) | ||
.catch(next); | ||
}, | ||
|
||
get: function(req, res, next){ | ||
gladys.machine.get() | ||
.then((machines) => res.json(machines)) | ||
.catch(next); | ||
}, | ||
|
||
update: function(req, res, next){ | ||
req.body.id = req.params.id; | ||
gladys.machine.update(req.body) | ||
.then((machine) => res.json(machine)) | ||
.catch(next); | ||
}, | ||
|
||
delete: function(req, res, next){ | ||
gladys.machine.delete({id: req.params.id}) | ||
.then(() => res.json({success: true})) | ||
.catch(next); | ||
} | ||
|
||
}; |
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,32 @@ | ||
var request = require('supertest'); | ||
var validateMachine = require('../../validator/machineValidator.js'); | ||
|
||
describe('MachineController', function() { | ||
|
||
describe('create', function() { | ||
|
||
it('should create a machine', function (done) { | ||
|
||
var machine = { | ||
name: 'trest', | ||
host: 'http://192.168.1.100', | ||
house: 1 | ||
}; | ||
|
||
request(sails.hooks.http.app) | ||
.post('/machine?token=test') | ||
.send(machine) | ||
.expect(200) | ||
.end(function(err, res) { | ||
if(err) return done(err); | ||
|
||
validateMachine(res.body); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
|
||
}); |
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,24 @@ | ||
var request = require('supertest'); | ||
var validateMachine = require('../../validator/machineValidator.js'); | ||
|
||
describe('MachineController', function() { | ||
|
||
describe('delete', function() { | ||
|
||
it('should delete a machine', function (done) { | ||
|
||
request(sails.hooks.http.app) | ||
.delete('/machine/1?token=test') | ||
.expect(200) | ||
.end(function(err, res) { | ||
if(err) return done(err); | ||
|
||
done(); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
|
||
}); |
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,25 @@ | ||
var request = require('supertest'); | ||
var validateMachine = require('../../validator/machineValidator.js'); | ||
|
||
describe('MachineController', function() { | ||
|
||
describe('get', function() { | ||
|
||
it('should get all machines', function (done) { | ||
|
||
request(sails.hooks.http.app) | ||
.get('/machine?token=test') | ||
.expect(200) | ||
.end(function(err, res) { | ||
if(err) return done(err); | ||
|
||
validateMachine(res.body); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
|
||
}); |
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,31 @@ | ||
var request = require('supertest'); | ||
var validateMachine = require('../../validator/machineValidator.js'); | ||
|
||
describe('MachineController', function() { | ||
|
||
describe('update', function() { | ||
|
||
it('should update a machine', function (done) { | ||
|
||
var machine = { | ||
name: 'newName' | ||
}; | ||
|
||
request(sails.hooks.http.app) | ||
.patch('/machine/1?token=test') | ||
.send(machine) | ||
.expect(200) | ||
.end(function(err, res) { | ||
if(err) return done(err); | ||
|
||
validateMachine(res.body); | ||
res.body.name.should.equal(machine.name); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
|
||
}); |
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