God’s happiness is not associated with His children’s behavior. His happiness is that He provides all of his children with the ability to come back into His presence.
Each of us are tried for our own good that we may know our own selves. By knowing who we are, God may provide us with exaltation.
So why do bad things happen to good people? Research has shown that there are 13 reasons in scripture: only 1 of the reasons is because good people behave badly.
2 Nephi 9:48