Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server tests : Authentication in Mocha + Chai + Sinon #2168

Closed
JulienMalige opened this issue Aug 23, 2016 · 4 comments
Closed

Server tests : Authentication in Mocha + Chai + Sinon #2168

JulienMalige opened this issue Aug 23, 2016 · 4 comments

Comments

@JulienMalige
Copy link

JulienMalige commented Aug 23, 2016

I can't find a solution to run integration tests under authentication.

Is the Chai .auth('user', 'pass') working ?

    beforeEach(function(done) {
      request(app)
        .get('/api/searches')
        .auth('test@example.com', 'test')
        .expect(200)
        .expect('Content-Type', /json/)
        .end((err, res) => {
          if (err) {
            return done(err);
          }
          searchs = res.body;
          done();
        });
    });
Item Version
generator-angular-fullstack 3.7.6
Item Answer
Transpiler Babel
Markup HTML
CSS SCSS
Router ui-router
Client Tests Mocha
DB MongoDB
Auth Y
@JulienMalige JulienMalige changed the title Authentication in Mocha + Chai + Sinon Server tests : Authentication in Mocha + Chai + Sinon Aug 23, 2016
@Awk34
Copy link
Member

Awk34 commented Aug 23, 2016

If you look at the top of the file you should see import request from 'supertest';. request here is an instance of supertest. This isn't using Chai HTTP.

@JulienMalige
Copy link
Author

JulienMalige commented Aug 23, 2016

@Awk34 Excuse me for the confusion. In fact, I hesitated to ask the question here or on stackoverflow.

More globally, I try to find the cleanest way to "log an user" to make several authenticated sets of tests. Should we have to use the superset Agent ? (ladjs/supertest#46). I try it, but I'm also confused between cookies and token.

@Awk34
Copy link
Member

Awk34 commented Aug 23, 2016

This question has been asked a few times, which I can see with this search I think you'll find what you're looking for in those issues.

@JulienMalige
Copy link
Author

Thanks @Awk34. I found my solution in #494.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants