tests and upsert logic