2018-02-02 15:24:22 +00:00
const app = require ( '../../../../../client/server/server' ) ;
2018-01-31 11:02:35 +00:00
const catchErrors = require ( '../../../../../../services/utils/jasmineHelpers' ) . catchErrors ;
const restoreFixtures = require ( '../../../../../../services/db/testing_fixtures' ) ;
2018-01-23 14:59:21 +00:00
describe ( 'Client addressesPropagateRe' , ( ) => {
let fixturesToApply = { tables : [ '`account`.`user`' , '`vn2008`.`Clientes`' , '`vn2008`.`Consignatarios`' ] , inserts : [
` INSERT INTO account.user(id,name,password,role,active,email)
VALUES
( 1 , 'BruceWayne' , 'ac754a330530832ba1bf7687f577da91' , 2 , 1 , 'BruceWayne@verdnatura.es' ) ,
( 2 , 'PetterParker' , 'ac754a330530832ba1bf7687f577da91' , 2 , 1 , 'PetterParker@verdnatura.es' ) ,
( 3 , 'ClarkKent' , 'ac754a330530832ba1bf7687f577da91' , 2 , 1 , 'ClarkKent@verdnatura.es' ) ,
( 4 , 'TonyStark' , 'ac754a330530832ba1bf7687f577da91' , 2 , 1 , 'TonyStark@verdnatura.es' ) ,
( 5 , 'MaxEisenhardt' , 'ac754a330530832ba1bf7687f577da91' , 2 , 1 , 'MaxEisenhardt@verdnatura.es' ) ,
( 6 , 'DavidCharlesHaller' , 'ac754a330530832ba1bf7687f577da91' , 18 , 1 , 'DavidCharlesHaller@verdnatura.es' ) ,
( 7 , 'HankPym' , 'ac754a330530832ba1bf7687f577da91' , 1 , 1 , 'HankPym@verdnatura.es' ) ,
( 8 , 'CharlesXavier' , 'ac754a330530832ba1bf7687f577da91' , 18 , 1 , 'CharlesXavier@verdnatura.es' ) ,
( 9 , 'BruceBanner' , 'ac754a330530832ba1bf7687f577da91' , 18 , 1 , 'BruceBanner@verdnatura.es' ) ,
( 10 , 'JessicaJones' , 'ac754a330530832ba1bf7687f577da91' , 9 , 1 , 'JessicaJones@verdnatura.es' ) ,
( 11 , 'Cyborg' , 'ac754a330530832ba1bf7687f577da91' , 1 , 1 , 'cyborg@verdnatura.es' ) ;
INSERT INTO salix . Address ( id , consignee , street , city , postcode , provinceFk , phone , mobile , isEnabled , isDefaultAddress , clientFk , defaultAgencyFk , longitude , latitude , isEqualizated )
VALUES
( 1 , 'Bruce Wayne' , 'The Bat cave' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 1 , 2 , NULL , NULL , 0 ) ,
( 2 , 'Petter Parker' , 'NY roofs' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 2 , 2 , NULL , NULL , 0 ) ,
( 3 , 'Clark Kenn' , 'The phone box' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 3 , 2 , NULL , NULL , 0 ) ,
( 4 , 'Tony Stark' , 'Stark tower' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 4 , 2 , NULL , NULL , 0 ) ,
( 5 , 'Max Eisenhardt' , 'The plastic cell' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 5 , 2 , NULL , NULL , 0 ) ,
( 6 , 'David Charles Haller' , 'Many places' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 6 , 2 , NULL , NULL , 0 ) ,
( 7 , 'Hank Pym' , 'Your pocket' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 7 , 2 , NULL , NULL , 0 ) ,
( 8 , 'Charles Xavier' , 'Cerebro' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 8 , 2 , NULL , NULL , 0 ) ,
( 9 , 'Bruce Banner' , 'Somewhere in Thailand' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 9 , 2 , NULL , NULL , 0 ) ,
( 10 , 'Jessica Jones' , 'Luke Cages Bar' , 'Silla' , 46460 , 1 , NULL , NULL , 1 , 1 , 10 , 2 , NULL , NULL , 0 ) ;
INSERT INTO vn . client ( id , name , fi , socialName , contact , street , city , postcode , phone , mobile , fax , isRelevant , email , iban , dueDay , accountingAccount , isEqualizated , provinceFk , hasToInvoice , credit , countryFk , isActive , gestdocFk , quality , payMethodFk , created , isToBeMailed , contactChannelFk , hasSepaVnl , hasCoreVnl , hasCoreVnh , riskCalculated , clientTypeFk , mailAddress , cplusTerIdNifFk , hasToInvoiceByAddress , isTaxDataChecked , isFreezed , creditInsurance , isCreatedAsServed , hasInvoiceSimplified , salesPersonFk , isVies , eypbc )
VALUES
( 1 , 'Bruce Wayne' , '74451390E' , 'Batman' , 'Alfred' , '1007 Mountain Drive, Gotham' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'BruceWayne@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 1 , 0 , 1 ) ,
( 2 , 'Petter Parker' , '87945234L' , 'Spider-Man' , 'Aunt May' , '20 Ingram Street' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'PetterParker@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 1 , 0 , 1 ) ,
( 3 , 'Clark Kent' , '06815934E' , 'Super-Man' , 'lois lane' , '344 Clinton Street' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'ClarkKent@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 1 , 0 , 1 ) ,
( 4 , 'Tony Stark' , '06089160W' , 'Iron-Man' , 'Pepper Potts' , '10880 Malibu Point' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'TonyStark@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 1 , 0 , 1 ) ,
( 5 , 'Max Eisenhardt' , '39182496H' , 'Magneto' , 'Rogue' , 'Unknown Whereabouts' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'MaxEisenhardt@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 3 , 0 , 1 ) ,
( 6 , 'DavidCharlesHaller' , '53136686Q' , 'Legion' , 'Charles Xavier' , 'Evil hideout' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'DavidCharlesHaller@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 3 , 0 , 1 ) ,
( 7 , 'Hank Pym' , '09854837G' , 'Ant-Man' , 'Hawk' , 'Anthill' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'HankPym@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 3 , 0 , 1 ) ,
( 8 , 'Charles Xavier' , '22641921P' , 'Professor X' , 'Beast' , '3800 Victory Pkwy, Cincinnati, OH 45207, USA' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'CharlesXavier@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 4 , 0 , 1 ) ,
( 9 , 'Bruce Banner' , '16104829E' , 'Hulk' , 'Black widow' , 'Somewhere in New York' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'BruceBanner@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 4 , 0 , 1 ) ,
( 10 , 'Jessica Jones' , '58282869H' , 'Jessica Jones' , 'Luke Cage' , 'NYCC 2015 Poster' , 'Silla' , 46460 , 1111111111 , 222222222 , 333333333 , 1 , 'JessicaJones@verdnatura.es' , NULL , 0 , 1234567890 , 0 , 1 , 1 , 300 , 1 , 1 , NULL , 10 , 5 , CURDATE ( ) , 1 , 5 , 1 , 1 , 1 , '0000-00-00' , 1 , NULL , 1 , 1 , 1 , 1 , NULL , 0 , 0 , 4 , 0 , 1 ) ; `
] } ;
beforeEach ( done => {
restoreFixtures ( fixturesToApply , done ) ;
} ) ;
2018-01-24 07:09:39 +00:00
afterAll ( done => {
restoreFixtures ( fixturesToApply , done ) ;
} ) ;
2018-01-23 14:59:21 +00:00
it ( 'should propagate the isEqualizated on both addresses of Mr Wayne' , done => {
let id = 1 ;
let data = {
isEqualizated : true
} ;
let callback = ( error , result ) => {
if ( error ) return catchErrors ( done ) ( error ) ;
expect ( result ) . toBe ( true ) ;
app . models . Address . find ( { where : { clientFk : id } } )
2018-02-02 15:24:22 +00:00
. then ( result => {
expect ( result [ 0 ] . isEqualizated ) . toBeTruthy ( ) ;
expect ( result [ 1 ] . isEqualizated ) . toBeTruthy ( ) ;
done ( ) ;
} ) ;
2018-01-23 14:59:21 +00:00
} ;
2018-01-24 12:45:32 +00:00
app . models . Address . find ( { where : { clientFk : id } } )
2018-02-02 15:24:22 +00:00
. then ( result => {
expect ( result [ 0 ] . isEqualizated ) . toBeFalsy ( ) ;
expect ( result [ 1 ] . isEqualizated ) . toBeFalsy ( ) ;
} )
. then ( ( ) => {
app . models . Client . addressesPropagateRe ( id , data , callback ) ;
} )
. catch ( catchErrors ( done ) ) ;
2018-01-23 14:59:21 +00:00
} ) ;
} ) ;