it's difficult to check the battery's condition unless you have the right equipment.
Batteries last on average about 4 years. Some longer, some shorter, there is a little bit of luck involved.
New batteries are not serviceable, so if a weld inside the cell pack detaches when you hit a pothole, you'll shortly need a new battery.
The simplest way is to factor in something like 50% of the cost of a new battery for one year old bike, 75% for 2 year old bike, 100% for 3 year old bike.
If you can, buy a seond hand bike with warranty so at least, you will be covered for a while.