Expose promises so that API can be used with either style.

Also add mocks and much fuller testing.