mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	#13 Sending in a patch request when updating enabled flag
This commit is contained in:
		
							parent
							
								
									50b56fd7a1
								
							
						
					
					
						commit
						8c643d4e8c
					
				| @ -27,7 +27,7 @@ module.exports = function (app) { | ||||
| 
 | ||||
|         db.getFeature(newFeature.name).then(function (feature) { | ||||
|             if (feature) { | ||||
|                 res.status(500).end(); | ||||
|                 res.status(403).end(); | ||||
|             } else { | ||||
|                 db.addFeature(newFeature).then(function () { | ||||
|                     res.status(201).end(); | ||||
| @ -36,20 +36,20 @@ module.exports = function (app) { | ||||
|         }); | ||||
|     }); | ||||
| 
 | ||||
|     app.patch('/features/:id', function (req, res) { | ||||
|         var body = req.body; | ||||
|         body.data.name = req.params.id; | ||||
|         var event = {}; | ||||
|         event.user = req.connection.remoteAddress; | ||||
|         event.comment = body.comment; | ||||
|         event.data = body.data; | ||||
| 
 | ||||
|         // console.log(event);
 | ||||
| 
 | ||||
|         // db.save(event).then(function () {
 | ||||
|         res.status(204).end(); | ||||
|         // });
 | ||||
| 
 | ||||
|     app.patch('/features/:featureName', function (req, res) { | ||||
|         var featureName = req.params.featureName; | ||||
|         db.getFeature(featureName).then(function (feature) { | ||||
|             if (feature) { | ||||
|                 var changeRequest = req.body; | ||||
|                 var event = {}; | ||||
|                 event.type = 'feature-update'; | ||||
|                 event.user = req.connection.remoteAddress; | ||||
|                 event.data = changeRequest; | ||||
|                 res.status(202).end(); | ||||
|             } else { | ||||
|                 res.status(404).end(); | ||||
|             } | ||||
|         }); | ||||
|     }); | ||||
| 
 | ||||
| }; | ||||
|  | ||||
| @ -29,19 +29,20 @@ var FeatureList = React.createClass({ | ||||
|         this.setState({features: data.features}); | ||||
|     }, | ||||
| 
 | ||||
|     updateFeature: function (feature) { | ||||
|     updateFeature: function (changeRequest) { | ||||
|         var newFeatures = this.state.features; | ||||
|         newFeatures.forEach(function(f){ | ||||
|             if(f.name === feature.name) { | ||||
|                 f = feature; | ||||
|             if(f.name === changeRequest.name) { | ||||
|                 f[changeRequest.field] = changeRequest.value; | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         console.log(changeRequest); | ||||
|         reqwest({ | ||||
|             url: 'features/' + feature.name, | ||||
|             method: 'post', | ||||
|             url: 'features/' + changeRequest.name, | ||||
|             method: 'patch', | ||||
|             type: 'json', | ||||
|             data: feature | ||||
|             contentType: 'application/json', | ||||
|             data: JSON.stringify(changeRequest) | ||||
|         }).then(function() { | ||||
|             this.setState({features: newFeatures}); | ||||
|         }.bind(this), function() { | ||||
| @ -78,9 +79,11 @@ var Feature = React.createClass({ | ||||
| */ | ||||
|     handleEnableChange: function(event) { | ||||
|         var feature = this.props.feature; | ||||
| 
 | ||||
|         feature.enabled = event.target.checked; | ||||
|         this.props.updateFeature(feature); | ||||
|         this.props.updateFeature({ | ||||
|             name: feature.name, | ||||
|             field: "enabled", | ||||
|             value: event.target.checked | ||||
|             }); | ||||
|     }, | ||||
| 
 | ||||
|     render: function () { | ||||
|  | ||||
| @ -22,22 +22,31 @@ describe('The api', function () { | ||||
|     it('creates new feature toggle', function (done) { | ||||
|         request | ||||
|             .post('/features') | ||||
|             .send({name: 'com.test.feature', 'status': 'off'}) | ||||
|             .send({name: 'com.test.feature', 'enabled': false}) | ||||
|             .set('Content-Type', 'application/json') | ||||
|             .expect(201, done); | ||||
|     }); | ||||
| 
 | ||||
|     it('change status of feature toggle', function (done) { | ||||
|     it('can not change status of feature toggle that dose not exsist', function (done) { | ||||
|         request | ||||
|             .patch('/features/com.test.feature') | ||||
|             .patch('/features/shouldNotExsist') | ||||
|             .send({ | ||||
|                 'comment': 'patch test of com.test.feature', | ||||
|                 data: { | ||||
|                     'status': 'on' | ||||
|                 } | ||||
|                 'field': 'enabled', | ||||
|                 'value': true | ||||
|             }) | ||||
|             .set('Content-Type', 'application/json') | ||||
|             .expect(204, done); | ||||
|             .expect(404, done); | ||||
|     }); | ||||
| 
 | ||||
|     it('can change status of feature toggle that dose exsist', function (done) { | ||||
|         request | ||||
|             .patch('/features/featureY') | ||||
|             .send({ | ||||
|                 'field': 'enabled', | ||||
|                 'value': true | ||||
|             }) | ||||
|             .set('Content-Type', 'application/json') | ||||
|             .expect(202, done); | ||||
|     }); | ||||
| 
 | ||||
| }); | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user