When the soul created for a human has been placed, the angels were asked to then prostrate.
The heavens and even the mountains were asked to accept the agreement brought onto humans, and both refused to hold the responsibility as they were afraid of the consequences of actions.
Humans were unjust and ignorant then took on the covenant.
The Lord of the worlds is Most-Wise, it is fair to say that He knew of the disobedience of the shaitan and humans before it actually came.
When the devil committed the act of disobedience, he only tried justifying his disagreement that he was better of creations, whereas Adam (peace be upon him), the first form of man as soon as the mistake was made by him, he stated to the Lord of the worlds, that without forgiveness, indeed, that he would be lost and among the losers.
The Lord created the heavens and the earth in six days total and then established Himself above the throne, over all of creation.