Add tests and fix logic around affiliations retrieval

woulnd't a ternary conditional be less verbose in here?