Merge pull request #681 from strongloop/feature/fix-issue-679
Make sure GET /:id/exists returns 200 {exists: true|false}
This commit is contained in:
commit
94033312e6
|
@ -509,6 +509,10 @@ PersistedModel.setupRemoting = function() {
|
|||
rest: {
|
||||
// After hook to map exists to 200/404 for HEAD
|
||||
after: function(ctx, cb) {
|
||||
if (ctx.req.method === 'GET') {
|
||||
// For GET, return {exists: true|false} as is
|
||||
return cb();
|
||||
}
|
||||
if(!ctx.result.exists) {
|
||||
var modelName = ctx.method.sharedClass.name;
|
||||
var id = ctx.getArgByName('id');
|
||||
|
|
|
@ -29,6 +29,18 @@ describe('loopback.rest', function() {
|
|||
.end(done);
|
||||
});
|
||||
|
||||
it('should report 200 for GET /:id/exists not found', function(done) {
|
||||
app.model(MyModel);
|
||||
app.use(loopback.rest());
|
||||
request(app).get('/mymodels/1/exists')
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if (err) return done(err);
|
||||
expect(res.body).to.eql({exists: false});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report 200 for GET /:id found', function(done) {
|
||||
app.model(MyModel);
|
||||
app.use(loopback.rest());
|
||||
|
@ -49,6 +61,20 @@ describe('loopback.rest', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should report 200 for GET /:id/exists found', function(done) {
|
||||
app.model(MyModel);
|
||||
app.use(loopback.rest());
|
||||
MyModel.create({name: 'm2'}, function(err, inst) {
|
||||
request(app).get('/mymodels/' + inst.id + '/exists')
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if (err) return done(err);
|
||||
expect(res.body).to.eql({exists: true});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('includes loopback.token when necessary', function(done) {
|
||||
givenUserModelWithAuth();
|
||||
app.enableAuth();
|
||||
|
|
Loading…
Reference in New Issue