Add tests and fix logic around affiliations retrieval

I thought we had refactored those jid/node splits to somewhere...