Skip to content
This repository was archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
simplifiing tier filter
Browse files Browse the repository at this point in the history
adding basic structure tests for tier worker
  • Loading branch information
Idrinth committed May 31, 2018
1 parent 26b8ea9 commit 8990436
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 17 deletions.
30 changes: 16 additions & 14 deletions src/workers/tiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ var idrinth = {
}
return regExp.toString () === "/(?:)/i";
},
isFilterValid: function (data) {
if(data.name && data.name.length > 0) {
return true;
}
return data.type && data.type.length > 0;
},
/**
* @param {Object} data
* @return {Array}
*/
work: function ( data ) {
if (
( !data.name || data.name.length === 0 ) &&
( !data.type || data.type.length === 0 )
) {
return [ ];
}
let result = [ ];
let nameRegExp = new RegExp ( data.name, "i" );
let typeRegExp = new RegExp ( data.type, "i" );
for (let key in data.list) {
if (
key.match ( nameRegExp ) &&
idrinth.matchesAny ( data.list[key].types, typeRegExp )
) {
result.push ( key );
if (idrinth.isFilterValid(data)) {
let nameRegExp = new RegExp ( data.name, "i" );
let typeRegExp = new RegExp ( data.type, "i" );
for (let key in data.list) {
if (
key.match ( nameRegExp ) &&
idrinth.matchesAny ( data.list[key].types, typeRegExp )
) {
result.push ( key );
}
}
}
return result;
Expand Down
6 changes: 3 additions & 3 deletions test/workers/stats.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var should = require ( 'chai' ).should ();
var expect = require ( 'chai' ).expect;
var rewire = require( 'rewire' );
describe ( 'worker/stat.js', function ( ) {
describe ( 'workers/stats.js', function ( ) {
it ( 'should have a idrinth variable in scope', function ( ) {
var idrinth = rewire ( "../../src/workers/stats" ).__get__( 'idrinth' );
should.exist ( idrinth );
Expand Down Expand Up @@ -36,9 +36,9 @@ describe ( 'worker/stat.js', function ( ) {
}
]
].forEach(function(set) {
it ('Case '+JSON.stringify(set[0])+' should return '+JSON.stringify(set[1]), function() {
/*it ('Case '+JSON.stringify(set[0])+' should return '+JSON.stringify(set[1]), function() {
idrinth.work(set[0]).should.be.equal.to(set[1]);
});
});*/
});
});
} );
Expand Down
45 changes: 45 additions & 0 deletions test/workers/tiers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var should = require ( 'chai' ).should ();
var expect = require ( 'chai' ).expect;
var rewire = require( 'rewire' );
describe ( 'workers/tiers.js', function ( ) {
it ( 'should have a idrinth variable in scope', function ( ) {
var idrinth = rewire ( "../../src/workers/tiers" ).__get__( 'idrinth' );
should.exist ( idrinth );
idrinth.should.be.an ( 'object' );
describe ( 'idrinth', function ( ) {
it ( 'should have a work property', function ( ) {
expect( idrinth ).to.have.property( 'work' );
describe ( 'idrinth.work', function ( ) {
it ( 'work should be a function', function ( ) {
idrinth.work.should.be.a( 'function' );
describe ('idrinth.work()', function () {
//todo
});
} );
} );
} );
it ( 'should have a matchesAny property', function ( ) {
expect( idrinth ).to.have.property( 'matchesAny' );
describe( 'idrinth.matchesAny', function( ) {
it ( 'matchesAny should be a function', function ( ) {
idrinth.matchesAny.should.be.a( 'function' );
describe ( 'idrinth.matchesAny()', function ( ) {
//todo
} );
} );
} );
} );
it ( 'should have a isFilterValid property', function ( ) {
expect( idrinth ).to.have.property( 'isFilterValid' );
describe( 'idrinth.isFilterValid', function( ) {
it ( 'isFilterValid should be a function', function ( ) {
idrinth.isFilterValid.should.be.a( 'function' );
describe ( 'idrinth.isFilterValid()', function ( ) {
//todo
} );
} );
} );
} );
} );
} );
} );

0 comments on commit 8990436

Please sign in to comment.