Add tests and fix logic around affiliations retrieval