Skip to content

Commit

Permalink
added array test
Browse files Browse the repository at this point in the history
  • Loading branch information
mwawrusch committed Jan 3, 2013
1 parent 31db420 commit 938972e
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions test/t16-embed-with-scope-and-array-test.coffee
@@ -0,0 +1,76 @@
should = require 'should'
_ = require 'underscore'

model = ->
targetId : ["id001","id002"]


module.exports = class ResolverUsers
constructor: () ->
# Ususally have a link to persistent store here.
@kinds = ['User'] # Supported types

resolve: (kind,userIdsToRetrieve = [],options = {},cb) =>
userIdsToRetrieve = _.uniq(userIdsToRetrieve)

result =
kind : kind
collectionName: 'users'
items : {}

if _.contains(userIdsToRetrieve,'id001')
result.items['id001'] =
id: "id001"
username: 'martin'
password: 'secret'
email: 'hello@world.com'
cb null,result


describe 'WHEN resolving stuff', ->
index = require '../lib/index'
apiFacade = index.client()
apiFacade.addSchema "TypeA",
mappings:
targetId:
name : 'targetId'
type: 'User'
collectionType: 'Array'
embed : true
resolve: false

apiFacade.addSchema "User",
mappings:
id : 'id'
username: 'username'
password: 'password'
email: 'email'
scopes:
inline:
fields: ['id','username']
scopea:
fields: ['id','username','email']

apiFacade.registerResolver new ResolverUsers


it 'IT should transform values', (done) ->
apiFacade.mapRoot 'TypeA', model(), scopes: ['scopea'], (err,jsonObj) ->
console.log "I GOT: #{JSON.stringify(jsonObj)}"
should.not.exist err
should.exist jsonObj
jsonObj.should.have.property 'targetId'
jsonObj.targetId.should.have.lengthOf 2
jsonObj.targetId[0].should.eql 'id001'
jsonObj.targetId[1].should.eql 'id002'

jsonObj.should.have.property '_embedded'
jsonObj._embedded.should.have.property 'users'
jsonObj._embedded.users.should.have.property 'id001'
jsonObj._embedded.users.id001.should.have.property 'id'
jsonObj._embedded.users.id001.should.have.property 'username'
jsonObj._embedded.users.id001.should.not.have.property 'password'
jsonObj._embedded.users.id001.should.have.property 'email'
done null


0 comments on commit 938972e

Please sign in to comment.