Some tidy-up and tests for #62
Turns out this had been fixed, but I did some tidy-up which hopefully should clarify the code, and I wrote an integration test for it
Merge branch 'master' of https://github.com/aodn/aodn-portal