Skip to content

Commit

Permalink
resolve in place test added
Browse files Browse the repository at this point in the history
  • Loading branch information
mwawrusch committed Jan 2, 2013
1 parent 93fd2b5 commit 8ff62c9
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 2 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -67,8 +67,7 @@ further details.

## Todo

* resolve test
* inline resolve tests
* embed test
* multiple depth test
* Invert name <> target
* Handle Url + Link case
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions test/t10-resolveinplace-test.coffee
@@ -0,0 +1,64 @@
should = require 'should'
_ = require 'underscore'

model = ->
createdBy:
actorId: "id001"


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:
createdBy:
name: 'createdBy'
type: 'User'
resolveInPlace: true
embed: false
idField: 'actorId'

apiFacade.addSchema "User",
mappings:
id : 'id'
username: 'username'
password: 'password'
email: 'email'

apiFacade.registerResolver new ResolverUsers


it 'IT should transform values', (done) ->
apiFacade.mapRoot 'TypeA', model(), {}, (err,jsonObj) ->
should.not.exist err
should.exist jsonObj
jsonObj.should.have.property 'createdBy'
jsonObj.createdBy.should.have.property 'id'
jsonObj.createdBy.should.have.property 'username'
jsonObj.createdBy.should.have.property 'password'
jsonObj.createdBy.should.have.property 'email'
done null


0 comments on commit 8ff62c9

Please sign in to comment.