Is there any way to test an app on all devices without purchasing all devices?
In order to do that, you can purchase a cloud based service like SauceLabs, BrowserStack or even try Amazon's Device Farm, which would give you the capability of testing your apps, across different platforms, on different devices.
There are other services too that offer this capability , and so you can search for this in and whatever suites your budget and needs , you should go for it.
Google's firebase test lab is another option that I don't see listed in the other answers so far. https://firebase.google.com/docs/test-lab ;
pcloudy, that was listed in one of the other answers, also supports testing automation through integration with appium.
BitBar = lots of devices, lots of supported test frameworks
This is a common requirement in mobile testing services and for the same we can test an app on different online platforms without purchasing the real devices and below are some of them:
1. Browser Stack
2. Sauce Labs
3. Device Farm
But these platforms are paid one and require a subscription to get the benefits.
IMP: App build should also be made compatible to run these in Online Platforms.