出于测试目的在服务器上登录用户

Sign in user on server for testing purposes

我使用 velocity + mocha 做了一些集成测试。对于某些服务器测试,用户必须登录(Meteor.userId 等必须具有有效 ID)。如何在服务器上登录用户(那里没有 loginWithPassword)。

您可以在 Meteor 方法中使用 this.setUserId (docs) 并在进行任何测试之前调用它。

例如

//在服务器端的测试代码中

Meteor.methods({
    signMeIn:function() {
        this.setUserId("<_id of a user>");
    }
});

然后 运行 在您希望用户登录之前在服务器或客户端上执行此操作。

Meteor.call("signMeIn");

您没有指定任何有关您在哪里使用 userId 的信息,但既然您说 Meteor.userId() 我假设它是一种方法。您也可以在现有的测试方法中更早地 运行 这段代码 (this.setUserId)。