Delimiter //
/**
 * test for LOADER_ENTRIES_MAP_CALCULATE_BALANCE()
 * 
 * @author Jean-François
 */
Drop Procedure If Exists TEST_LOADER_ENTRIES_MAP_CALCULATE_BALANCE//
Create Procedure TEST_LOADER_ENTRIES_MAP_CALCULATE_BALANCE()
Begin

    Call LOADER_TEST_MOCK_ENTRIES_CLEAN();
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(1, Concat('ENTRIES_ENT_CREDIT = 400, ENTRIES_ENT_DEBIT = 200'), 1, Null);
    Call LOADER_TEST_MOCK_ENTRIES_PUSH(2, Concat('ENTRIES_ENT_CREDIT = Null, ENTRIES_ENT_DEBIT = 500'), 2, Null);

    -- tested procedure
    Call LOADER_ENTRIES_MAP_CALCULATE_BALANCE(1);

    -- assertions
    Call utAssert_eq('Balance is correctly calculated with given Credit and Debit'
        , -200
        , (Select Cast(ENTRIES_ENT_BALANCE as Signed Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 1)
    );
    Call utAssert_eq('Balance is correctly calculated with a Null value'
        , 500
        , (Select Cast(ENTRIES_ENT_BALANCE as Signed Integer) From LOADER_ENTRIES Where ID_LOADER_ENTRIES = 2)
    );

    -- cleans
    Call LOADER_TEST_MOCK_ENTRIES_CLEAN();

End//
Delimiter ;