Yes. First, the hypothesis implies that is injective for every scheme , even when is not an affine scheme. Indeed, suppose satisfy . Choose an affine open cover . On each , injectivity of gives . By gluing morphisms of schemes, .
Now choose an affine open cover , and denote its inclusion maps by . Surjectivity of gives morphisms of schemes with . On , the two restrictions have the same composite with . By the injectivity just established for arbitrary test schemes,
In particular, the overlaps need not be affine schemes. Gluing morphisms of schemes supplies with , and because this holds on every .
Finally,
Injectivity of , already proved without an affineness assumption, gives . Therefore
This proves the relevant instance of affine test schemes determine scheme morphisms: the restricted functor of points still retains the information needed to construct the inverse.