It came about after this that his master's wife cast her eyes on Joseph and said, "Lie with me." 8 But he refused and said to his master's wife, "Look, my master does not pay attention to what I do in the house, and he has put everything that he owns under my care. 9 No one is greater in this house than I am. He has not kept back anything from me but you, because you are his wife. How then can I do this great wickedness and sin against God?"
Joseph was tested by Yahweh through the pharoah’s wife to see if he would sin, and while Joseph stayed true to his beliefs, he was later on accused of advancing on her. Joseph was tested and put through suffering and almost faced exile and death but justice prevailed in the end. Joseph ended up rising up to a high position of power in Egypt, and saved many people from famine. From a theological perspective, Yahweh in the Old Testament is hard, but fair. This teaches that Yahweh isn't a cruel God, but one that allows tests of faith and if you're like Joseph, you will be redeemed for having that faith. Yahweh teaches a just world, where justice is always served, even if it’s delayed sometimes.