Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question?] Cleanup after tests (Resource.destroy) causing TypeError #155

Open
Fishrock123 opened this issue Dec 19, 2014 · 3 comments
Open

Comments

@Fishrock123
Copy link

Getting this error

(Summary) Uncaught TypeError: Property 'tracks' of object { ... } is not a function

Uncaught TypeError: Property 'tracks' of object {"id":"72f17dbd-a826-4b6f-9b23-ffa71674e405","name":"user","permalink":"user","email":"user@zambah.com","following":[],"likes":[],"tracks":[],"followers":[],"password":"12345678","twitter":{},"facebook":{},"google":{},"profile_pic":"/img/default_avatar.png","cover":"/img/music.jpg","accountType":"artist","emailConfirmed":false,"track_ids":[],"resource":"User"} is not a function

At this line: https://github.com/flatiron/resourceful/blob/master/lib/resourceful/resource.js#L642

From the afterEach loop of my mocha tests here:

describe('api - profile', function () {
  var app
  var user
  var User

  function createApp(done, opts) {
    var config = opts || {}

    // UserAccount makes a User Resource
    //  providing an arg changes the `uri` of the memorystore
    User = UserAccount(randomstring.generate(25))
    app = express()

    app.use(bodyParser.json({
      limit: '100kb'
    }))

    User.create(user_create, function(err, _user) { // creates and sets `user`, etc
      user = _user

      app.use(function(req, res, next) {
        req.user = config.user || user
        next()
      })

      app.use('/api', api({ UserAccount: User }))

      if ('function' === typeof done) done()
    })
  }

  beforeEach(createApp)

  afterEach(function (done) {
    User.destroy(user.id, function () { // error caused here //
      done()
    })
  })

  // tests ...
})

(Running into this error for just one, but I really I need a way to clear all data from the associated memory store. ala #53)

@Fishrock123
Copy link
Author

UserAccount looks like this:

var resourceful = require('resourceful')

module.exports = function init(test_uri) {

  var User = resourceful.define('User', function(){
    if (test_uri) {
      this.use('memory', { uri: test_uri })
    }

    this.string('name')
    this.string('stage_name')
    this.string('permalink', { required: true })
    this.string('gender')
    this.string('email', { required: true })
    this.array('following')
    this.array('likes')
    this.array('tracks')
    this.array('followers')
    this.string('city')
    this.string('bio')
    this.string('password')
    this.number('lastFeedback')
    this.number('registered')
    this.object('twitter')
    this.object('facebook')
    this.object('google')
  });

  User.property('profile_pic', 'string', {
    // ...
  })

  User.property('cover', 'string', {
    // ...
  })

  User.property('accountType', 'string', {
    // ...
  })

  User.property('emailConfirmed', 'boolean', {
    // ...
  })

  return User
}

@jcrugzz
Copy link
Member

jcrugzz commented Dec 19, 2014

@Fishrock123 is this resource even using relationships here? Ill try and see whats happening.

@Fishrock123
Copy link
Author

@jcrugzz I don't think that it was. Now it is, and it works fine o_0 (User's no longer have a tracks array but rather have tracks as children).

(I have been implementing tests alongside a co-worker upgrading our database things, so it could be tricky to back up to, but I can if necessary.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants