Meteor / Jasmine / Velocity : how to test a server method requiring logged in user?

Petrov

Using velocity/jasmine, I'm a bit stuck on how I should test a server-side method requiring that there be a currently logged-in user. Is there a way to make Meteor think a user is logged in via stub/fake ?

myServerSideModel.doThisServerSideThing = function(){
    var user = Meteor.user();
    if(!user) throw new Meteor.Error('403', 'not-autorized');
}

Jasmine.onTest(function () {
    describe("doThisServerSideThing", function(){
        it('should only work if user is logged in', function(){
            // this only works on the client :(
            Meteor.loginWithPassword('user','pwd', function(err){
                expect(err).toBeUndefined();

            });
        });
    });
});
Thomas Goorden

What you could do is add users just to your test suite. You could do this by populating these users in a the server-side test script:

Something like:

Jasmine.onTest(function () {
  Meteor.startup(function() {
    if (!Meteor.users.findOne({username:'test-user'})) {
       Accounts.createUser
          username: 'test-user'
  ... etc

Then, a good strategy could be to use the beforeAll in your test to login (this is client side):

Jasmine.onTest(function() {
  beforeAll(function(done) {
    Meteor.loginWithPassword('test-user','pwd', done);
  }
}

This is assuming your test isn't logged in yet. You can make this more fancy by checking for Meteor.user() and properly logging out in an afterAll, etc. Note how you can handily pass the done callback to many of the Accounts functions.

Essentially, you don't have to mock a user. Just make sure you have the right users, with the correct roles, available in the Velocity/Jasmine DB.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Requiring timeouts when testing Meteor with Velocity and Jasmine

From Dev

shared test fixture for meteor velocity cucumber and jasmine

From Dev

Client integration test with velocity and jasmine on Meteor

From Dev

velocity + jasmin unit test on meteor server side

From Dev

How to check logged user in liferay velocity?

From Dev

How to wait for the user to be logged in, in Velocity integration tests

From Dev

How to generate test coverage report in Meteor / Velocity?

From Dev

Simple Meteor Method Jasmine Test not working

From Dev

In Meteor, how can i identify connection / a user of a site on the server, regardless of whether or not they're logged in?

From Dev

Meteor 'forgets' the logged in user

From Dev

Meteor - Set the logged in user

From Dev

Meteor Velocity with Jasmine not returning expecting result?

From Dev

How can I integrate casperJS to Meteor's Velocity Test Runner?

From Dev

Automating Matlab without requiring the user to be logged in

From Dev

Allow to run Meteor server-methods only when user is logged in

From Dev

Meteor minimongo shows user logged in on client before server

From Dev

Django: How to test if a user is currently logged in

From Dev

Meteor client integration async testing with Velocity / Jasmine; How to get return value?

From Dev

How to display payment method to logged in user only?

From Dev

How to unit test a chained method using Jasmine

From Dev

Jasmine: How to test method containing a declared variable

From Dev

How to write Jasmine test cases for jQuery on() method

From Dev

Meteor integration testing, rest api endpoint in velocity's mirror with jasmine

From Java

TestCafe: How to test logout if user logged in from another machine

From Dev

How can I test methods which needs user to be logged

From Dev

How to get `Test` objects created by actually logged user?

From Dev

test check user logged in laravel

From Dev

How to test a code requiring user input within lambda function in JAVA 8?

From Dev

How to test with Jasmine an AngularJS controller that calls service method that returns promise

Related Related

  1. 1

    Requiring timeouts when testing Meteor with Velocity and Jasmine

  2. 2

    shared test fixture for meteor velocity cucumber and jasmine

  3. 3

    Client integration test with velocity and jasmine on Meteor

  4. 4

    velocity + jasmin unit test on meteor server side

  5. 5

    How to check logged user in liferay velocity?

  6. 6

    How to wait for the user to be logged in, in Velocity integration tests

  7. 7

    How to generate test coverage report in Meteor / Velocity?

  8. 8

    Simple Meteor Method Jasmine Test not working

  9. 9

    In Meteor, how can i identify connection / a user of a site on the server, regardless of whether or not they're logged in?

  10. 10

    Meteor 'forgets' the logged in user

  11. 11

    Meteor - Set the logged in user

  12. 12

    Meteor Velocity with Jasmine not returning expecting result?

  13. 13

    How can I integrate casperJS to Meteor's Velocity Test Runner?

  14. 14

    Automating Matlab without requiring the user to be logged in

  15. 15

    Allow to run Meteor server-methods only when user is logged in

  16. 16

    Meteor minimongo shows user logged in on client before server

  17. 17

    Django: How to test if a user is currently logged in

  18. 18

    Meteor client integration async testing with Velocity / Jasmine; How to get return value?

  19. 19

    How to display payment method to logged in user only?

  20. 20

    How to unit test a chained method using Jasmine

  21. 21

    Jasmine: How to test method containing a declared variable

  22. 22

    How to write Jasmine test cases for jQuery on() method

  23. 23

    Meteor integration testing, rest api endpoint in velocity's mirror with jasmine

  24. 24

    TestCafe: How to test logout if user logged in from another machine

  25. 25

    How can I test methods which needs user to be logged

  26. 26

    How to get `Test` objects created by actually logged user?

  27. 27

    test check user logged in laravel

  28. 28

    How to test a code requiring user input within lambda function in JAVA 8?

  29. 29

    How to test with Jasmine an AngularJS controller that calls service method that returns promise

HotTag

Archive