Skip to content

Create behavior concern tests #152

Description

@kaievns

after the controllers and routers are uniformed and auto-generated, we can also start generating tests as well. something like this:

const { app, itBehavesLikeCRUDResource } = require('../helper');

describe("/users route", () {
  itBehavesLikeCRUDResource(app);
});

eventually we could split those into specific concerns like, itListsThingsProperly, itCreatesNewRecordsCorrectly, etc.

Activity

  1. davidbanham commented on Jul 1, 2016

    @davidbanham
    Contributor

    Definitely interesting. I think we should do a little exploratory hacking to validate the approach. My concern is that it becomes difficult to inject things required by the business logic. Things like injecting auth credentials, etc.

  2. kaievns commented on Jul 1, 2016

    @kaievns
    ContributorAuthor

    yup. absolutely, the point here is not to test custom business logic, but to test default standard behavior of REST api that was generated by redbeard.

    as for injecting the credentials, doubleagent has you covered:

    const { app, itBehavesLikeCRUDResource } = require('../helper');
    
    describe("/users route", () {
      beforeEach(function * () {
        const user = yield new User({... }).save();
        const token = yield generateToken(user);
    
        app.defaultHeaders = { Authorization: `Bearer: ${token}` };
      });
    
      itBehavesLikeCRUDResource(app);
    });
  3. davidbanham commented on Jul 1, 2016

    @davidbanham
    Contributor

    Ooooh, fancy. Yeah, looks like that'll work.

  4. self-assigned this
    on Sep 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions