The tests that are carried out on medical staff, for example, look for the presence of antibodies to the virus in their blood. If those antibodies are present, then it's an indicator that they've recovered from the virus and that (because of the presence of those antibodies) they're now immune to it.
However the research has shown that they antibodies are actually only 'low level' ones, so there's not a total guarantee that the person couldn't possibly get a second dose of the disease (although, the the best of my knowledge, there's been no recorded incidence of anyone contracting the disease for a second time yet).
Further, all viruses mutate over time. That's why last year's flu jab won't protect you against this year's flu. So it's possible that Covid-19 could mutate into a slightly different form, to which any existing antibodies in a person's body would then be ineffective.