All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
First of all, we say that if someone drinks alcohol in this company, then this by itself does not necessitate leaving it as long as the company's activity is lawful. The employee is not obliged to leave work in a company that practices lawful activities for the mere presence of someone who drinks alcohol in it. Rather, he should just avoid sitting with them at the same table where alcohol is drunk.
As for whether what happened to you is a test or punishment, then this is a matter of the Unseen that only Allah knows. It may be a test from Allah, and it may be a punishment for past sins, and it may be otherwise. There are so many people who cannot find work because of recession in the labor market.
In any case, you are required to be patient and rely on Allah and have trust in Him and have good expectations of Him.
The matter is easy, and there is no need for stress and worry. It is only a hardship that will pass soon, with the permission of Allah, and you will find a way out from it.
So, dear Brother, take it easy upon yourself and have trust in Allah rather than in what you have in your hands, as the livelihood is divided and the lifespans of people are fixed. You will not die until you consume your designated provision and reach your appointed time. You are required to be patient while endeavoring to find lawful means of earning.
For more benefit on the wisdom of tests and the virtue of patience with them, please refer to fatwa 83577.
Allah knows best.