Skip to content

Commit

Permalink
Test(style): Better readable code
Browse files Browse the repository at this point in the history
  • Loading branch information
fvdm committed Mar 29, 2024
1 parent 70f676b commit 2e4b2f9
Showing 1 changed file with 33 additions and 35 deletions.
68 changes: 33 additions & 35 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ License: Unlicense (public domain, see LICENSE file)
Source & docs: https://github.com/fvdm/nodejs-geolocation
*/

const dotest = require ('dotest');
const app = require ('./');
const dotest = require( 'dotest' );
const app = require( './' );

const config = {
key: process.env.KEY,
timeout: process.env.TIMEOUT || 5000,
};


dotest.add ('exports', async test => {
test ()
.isFunction ('fail', 'exports', app)
.done ()
dotest.add( 'exports', async test => {
test()
.isFunction( 'fail', 'exports', app )
.done()
;
});
} );


dotest.add ('Function', async test => {
dotest.add( 'Function', async test => {
let error;
let data;

try {
data = await app ({
data = await app( {
key: config.key,
timeout: config.timeout,
wifiAccessPoints: [
Expand All @@ -38,50 +38,48 @@ dotest.add ('Function', async test => {
signalToNoiseRatio: 40,
},
],
});
} );
}
catch (err) {
catch ( err ) {
error = err;
}

const location = data && data.location;

test (error)
.isObject ('fail', 'data', data)
.isNotEmpty ('fail', 'data', data)
.isObject ('fail', 'data.location', location)
.isNumber ('fail', 'data.location.lat', location && location.lat)
.isNumber ('fail', 'data.location.lng', location && location.lng)
.isNumber ('fail', 'data.accuracy', data && data.accuracy)
.done ()
test( error )
.isObject( 'fail', 'data', data )
.isNotEmpty( 'fail', 'data', data )
.isObject( 'fail', 'data.location', data?.location )
.isNumber( 'fail', 'data.location.lat', data?.location?.lat )
.isNumber( 'fail', 'data.location.lng', data?.location?.lng )
.isNumber( 'fail', 'data.accuracy', data?.accuracy )
.done()
;
});
} );


dotest.add ('API error', async test => {
dotest.add( 'API error', async test => {
let error;
let data;

try {
data = await app ({
data = await app( {
key: 'invalid',
considerIp: false,
carrier: 0,
});
} );
}
catch (err) {
catch ( err ) {
error = err;
}

test ()
.isError ('fail', 'error', error)
.isNotEmpty ('fail', 'error.message', error && error.message)
.isNumber ('fail', 'error.code', error && error.code)
.isArray ('fail', 'error.errors', error && error.errors)
.isUndefined ('fail', 'data', data)
.done ()
test()
.isError( 'fail', 'error', error )
.isNotEmpty( 'fail', 'error.message', error?.message )
.isNumber( 'fail', 'error.code', error?.code )
.isArray( 'fail', 'error.errors', error?.errors )
.isUndefined( 'fail', 'data', data )
.done()
;
});
} );


dotest.run ();
dotest.run();

0 comments on commit 2e4b2f9

Please sign in to comment.