client.js 799 B

12345678910111213141516171819202122232425262728
  1. module.exports = function () {
  2. // Mocks of public API methods
  3. function Client() {}
  4. Client.prototype.write = function mockWrite(notification, device) {
  5. return { device };
  6. };
  7. Client.prototype.setLogger = function mockSetLogger(newLogger, newErrorLogger = null) {
  8. // Validate arguments but don't store the logger
  9. if (typeof newLogger !== 'function') {
  10. throw new Error(`Expected newLogger to be a function, got ${typeof newLogger}`);
  11. }
  12. if (newErrorLogger && typeof newErrorLogger !== 'function') {
  13. throw new Error(
  14. `Expected newErrorLogger to be a function or null, got ${typeof newErrorLogger}`
  15. );
  16. }
  17. };
  18. Client.prototype.shutdown = function mockShutdown(callback) {
  19. if (callback) {
  20. callback();
  21. }
  22. };
  23. return Client;
  24. };