falcor icon indicating copy to clipboard operation
falcor copied to clipboard

Integration tests does not work with call

Open a9a4k opened this issue 10 years ago • 7 comments

I have the following setup in mocha:

describe('Falcor requests', function() {
  let server;
  before(function() {
    const app = express();
    app.use(routes);
    model = new falcor.Model({
      source: new HttpDataSource('http://localhost:1337/model.json')
    });
  });
  after(function() {
    server.close();
  });
  it('should retrieve deals', function() {                                             // model.get works
    return model.get(['dealsById', testDeal1.id, 'title']).
    then(res => {
      expect(
        res.json.dealsById[testDeal1.id].title
      ).to.equal(testDeal1.title);
    });
  });
it('should create a user with a call function and return its values', function() {         // model.call works
    const args = {
      ...
    };
    return model.call(
      ['users', 'create'],
      [args],
      ['email']
    ).
    then(res => {
      console.log(res, 'response');
    });
  });

All the gets are tested perfectly, however on call test throws Request not supported, pointing to the xmlhttprequest lib.

Could you please advise me on what to do?

a9a4k avatar Jan 02 '16 12:01 a9a4k

From what I can tell, this should be perfectly fine. I think I would need to see more of the program. Could you include routes and the call function you are attempting to call? That would be grand!

I know you are suppose to use a listen function at some point with an express server. I don't see that being executed. Make sure that the routes support post as well, as call uses post.

ThePrimeagen avatar Jan 02 '16 20:01 ThePrimeagen

@michaelbpaulson I have the following structure:

express-routes.js

...
router.all(
  '/model.json',
  authenticate,
  falcorExpress.dataSourceRoute(req => new ClientRouter(serverModel, req.user ? req.user.sub : null))
);
...
client-router.js

...
class ClientRouter extends Router.createClass([
  ...
  {
    route: 'users.create',
    call(...args) {
      // TODO for now it is ok, as call returns undeined,
      // but when refPaths will start working, will have to rewrite
      return this.serverModel.
        call(...args).
        map(json => toPathValues(json));
    }
  },
]) {
  constructor(serverModel, userId) {
    super();
    this.serverModel = serverModel;
    this.userId = userId;
  }
}
...

a9a4k avatar Jan 14 '16 10:01 a9a4k

@michaelbpaulson Call actuall works, when called from the webpage, it does not work when I call from tests...

a9a4k avatar Jan 14 '16 10:01 a9a4k

@michaelbpaulson I actually do call

return new Promise((resolve, reject) => {
            server = app.listen(1337, err => {
              if (err) {
                reject(err);
                return;
              }
              resolve();
            });
          })

at the end of the before function in mocha. I was just cutting code for it to be shorter and removed necessary stuff :)

a9a4k avatar Jan 14 '16 10:01 a9a4k

This I have no Idea. This is a problem that I would have to debug myself to figure out. All i know is Request not supported is not a falcor error. Have you made any progress on this? @gdi2290 do you have any idea? Could this have to do with falcor-http-datasource?

ThePrimeagen avatar Jan 20 '16 14:01 ThePrimeagen

@almasakchabayev Is this still a problem for you? Wanted to check in and see if there's anything we can do to help. See @michaelbpaulson's comment from 1/20.

ktrott avatar Mar 04 '16 17:03 ktrott

@ktrott For some reason I could not make it work with a call. I tried to dig into the source code and I guess that problem lies in xmlhttprequest lib

a9a4k avatar Mar 04 '16 17:03 a9a4k