totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

Enhance Unit-Testing with subdomain route #750

Closed fgnm closed 4 years ago

fgnm commented 4 years ago

Hi, I would like to suggest an improvement of TEST method with subdomains using internal Total.js syntax. This is the route method:

ROUTE('POST [api]/v1/auth/sms                     *phone_auth --> @send_sms');

This is the TEST method I would use:

TEST('Test action', '[api]/v1/auth/sms', function(builder) {
    builder.json({ phone: '+340000000000' });
    builder.exec(function(err, data, response) {
        FAIL(response.success !== true);
        // or
        // OK(respons.success);
    });
});

The app is running in localhost so I could use http://api.localhost:8000/v1/auth/sms, but it would be nice to use [api]/v1/auth/sms as url

petersirka commented 4 years ago

I have extended it. Try it $ npm install total.js@beta.

fgnm commented 4 years ago

Wow many thanks to be so fast! It works, and METHOD inside url is cool too, just a little advice: to get it working options.ip have to be changed to localhost, since IPs does not have subdomains (of course :smile: )

petersirka commented 4 years ago

Thank you. And yes options.ip must be set to localhost or some local domain. I wondered to disable it for IP addresses, but error is better than silent behaviour.