Gravity123
Gravity123

Reputation: 1130

Xolvio/meteor-cucumber: returning result of this.server.call

I am using the package Xolvio/meteor-cucumber and I'm trying to call a fixture method and use its returned value in a step definition:

Step:

And I fill in the sms code "#smsCodeVerification"

Step definition:

this.Then(/^I fill in the sms code "([^"]*)"$/, function (verificationField, callback) {
      var code = this.server.call('getSmsCodeForUser', "+467*******");
      console.log("step code: " + code);

      this.client
        .waitForExist(verificationField, 4000)
        .waitForVisible(verificationField, 2000)
        .setValue(verificationField, code)
        .call(callback);
    });

The above code prints:

step code: [object Promise]

The server method looks like this:

'getSmsCodeForUser': function (tel) {
      var user = User.findOne({ phone: tel }),
        password = Password.findOne({ user: user._id }),
        code = parseInt(password.code);

      return code;
    }

The console log in the step definition will run before the server method is finished, and using the meteors normal way of getting a callback from server methods will not work, it will only return undefined.

Upvotes: 0

Views: 93

Answers (1)

Xolv.io
Xolv.io

Reputation: 2533

this.server.call('getSmsCodeForUser', "+467*******").then(function(resopnse) {

    // you can use the response here

});

Upvotes: 1

Related Questions