Fix HAL pagination links

Added test corresponding to the bug. Simplified the condition to get the previous link.