refactor api unit tests and confirm no upsert bug