added unit tests to write to db