These are chat archives for canjs/canjs

28th
Feb 2018
Viktor Busko
@Lighttree
Feb 28 2018 14:06

Guys, we are working on JWT Authentication (actually any token auth):
And have some issue with modiying how url behavior makes call.

We would like to have something like this:

Entity.connection = connect(
    [url, JWTAuth, constructor, constructorStore, canMap, realTime, callbacksOnce], {
        url: '/secured/entity',
        Map: Entity,
        List: Entity.List,
        algebra
    }
);

The idea is that ajax call that makes url here:
https://github.com/canjs/can-connect/blob/master/data/url/url.js#L370

Should have tokens as request headers.

The problem is that there is no way how we can pre-configure ajax settings in URL behavior. In order to have beforeSend section with doing some Auth logic there.

The only option that we found is rewrite ajax function

Entity.connection = connect(
    [url, JWTAuth, constructor, constructorStore, canMap, realTime, callbacksOnce], {
        url: '/secured/entity',
        ajax: authenticatedAjax,
        Map: Entity,
        List: Entity.List,
        algebra
    }
);

But in this case we can move all logic to authenticatedAJAX and don't use JWTAuth.

How this best to organize ?

Eben
@eben-roux
Feb 28 2018 18:40
anyone around to give advice setting up tests that use canjs components?
Kevin Phillips
@phillipskevin
Feb 28 2018 18:41
sure
Eben
@eben-roux
Feb 28 2018 18:41
so I'm looking at mocha and I used that basic example test
I'm assuming that all the testing runs in node so the module format has to be node compliant
how would I go about testing a module that uses es6 import for instance?
e.g.: import DefineMap from 'can-define/map/';
Kevin Phillips
@phillipskevin
Feb 28 2018 18:43
well... you could use babel
Eben
@eben-roux
Feb 28 2018 18:44
I know this isn't exactly canjs specific so if you have a good resource I can take a look at that would also be fine... last serious JS testing I did was with JSTestDriver / QUnit about 2 years ago
Kevin Phillips
@phillipskevin
Feb 28 2018 18:44
and use mocha's --compilers option
what module loader are you using to load these things in your app?
Eben
@eben-roux
Feb 28 2018 18:44
was thinking that there would be some transpiling... is steal-mocha specific to testing in a browser using a page?
Kevin Phillips
@phillipskevin
Feb 28 2018 18:44
yeah
Eben
@eben-roux
Feb 28 2018 18:45
I use steal when developing the apps
Kevin Phillips
@phillipskevin
Feb 28 2018 18:45
ok
that's what we use most of the time
and just test in a browser
Eben
@eben-roux
Feb 28 2018 18:45
ah... was wondering what that is
I had a look at the canjs tests and did notice that
Kevin Phillips
@phillipskevin
Feb 28 2018 18:46
Eben
@eben-roux
Feb 28 2018 18:46
something you guys rolled yourself also?
Kevin Phillips
@phillipskevin
Feb 28 2018 18:46
yeah
Eben
@eben-roux
Feb 28 2018 18:47
does it handle async/promise testing also?
Kevin Phillips
@phillipskevin
Feb 28 2018 18:47
yeah
Eben
@eben-roux
Feb 28 2018 18:48
ok, excellent
Kevin Phillips
@phillipskevin
Feb 28 2018 18:48
if you don't want to test in a browser, you can use https://mochajs.org/#about-babel
Eben
@eben-roux
Feb 28 2018 18:48
I'm going to have a serious look, thanks
Kevin Phillips
@phillipskevin
Feb 28 2018 18:48
but testing in a browser when you're writing components usually makes sense
Eben
@eben-roux
Feb 28 2018 18:48
I'd prefer testing from node but not sure how feasible that is nowadays
Kevin Phillips
@phillipskevin
Feb 28 2018 18:49
you can use headless chrome
Eben
@eben-roux
Feb 28 2018 18:49
agreed, but I'm actually writing some infrastructure components that don't have any UI elements
I'm going to give it a shot... will ask when I get stuck, thanks :) --- should get cracking on this tomorrow
cheers
it's using qunit, but there's not much of a difference
and you can use https://github.com/donejs/donejs-mocha if you're using donejs
Eben
@eben-roux
Feb 28 2018 18:52
great stuff, thanks again --- haven't looked at the donejs site for ages
Kevin Phillips
@phillipskevin
Feb 28 2018 18:52
no problem
last plug, give canjs/canjs#3862 a :thumbsup: if you're interested in a testing-specific guide