Skip to content

Commit

Permalink
Merge pull request #209 from PradnyaBaviskar/lb-issue-1327
Browse files Browse the repository at this point in the history
add test to verify target type array
  • Loading branch information
bajtos committed Jun 2, 2015
2 parents 4c7c952 + b246b79 commit ebe0614
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/shared-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function coerceAccepts(uarg, desc) {
// ignore all other root settings like "required"
return coerceAccepts(arg, {
name: name + '[' + ix + ']',
type: desc.type[0]
type: targetType[0]
});
});
}
Expand Down Expand Up @@ -335,6 +335,7 @@ function convertToBasicRemotingType(type) {
}

type = String(type).toLowerCase();

switch (type) {
case 'string':
case 'number':
Expand All @@ -344,6 +345,8 @@ function convertToBasicRemotingType(type) {
case 'object':
case 'any':
return type;
case 'array':
return ['any'].map(convertToBasicRemotingType);
default:
// custom types like MyModel
return 'object';
Expand Down
60 changes: 60 additions & 0 deletions test/rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,66 @@ describe('strong-remoting-rest', function() {
.end(done);
});

it('should support taget type [any]', function(done) {
var method = givenSharedStaticMethod(
function(arg, cb) { cb(null, { value: arg }); },
{
accepts: { arg: 'arg', type: ['any'] },
returns: { arg: 'data', type: ['any'], root: true },
http: { method: 'POST' }
});

request(app).post(method.url)
.send({ arg: ['single'] })
.expect(200, { value: ['single'] })
.end(done);
});

it('should support taget type `array` - of string', function(done) {
var method = givenSharedStaticMethod(
function(arg, cb) { cb(null, { value: arg }); },
{
accepts: { arg: 'arg', type: 'array' },
returns: { arg: 'data', type: 'array', root: true },
http: { method: 'POST' }
});

request(app).post(method.url)
.send({ arg: ['single'] })
.expect(200, { value: ['single'] })
.end(done);
});

it('should support taget type `array` - of number', function(done) {
var method = givenSharedStaticMethod(
function(arg, cb) { cb(null, { value: arg }); },
{
accepts: { arg: 'arg', type: 'array' },
returns: { arg: 'data', type: 'array', root: true },
http: { method: 'POST' }
});

request(app).post(method.url)
.send({ arg: [1] })
.expect(200, { value: [1] })
.end(done);
});

it('should support taget type `array` - of object', function(done) {
var method = givenSharedStaticMethod(
function(arg, cb) { cb(null, { value: arg }); },
{
accepts: { arg: 'arg', type: 'array' },
returns: { arg: 'data', type: 'array', root: true },
http: { method: 'POST' }
});

request(app).post(method.url)
.send({ arg: [{foo: 'bar'}] })
.expect(200, { value: [{foo: 'bar'}] })
.end(done);
});

it('should allow empty body for json request', function(done) {
remotes.foo = {
bar: function(a, b, fn) {
Expand Down

0 comments on commit ebe0614

Please sign in to comment.