purest.js 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const fs = require('fs')
  2. class MockPurest {
  3. constructor (opts) {
  4. const methodsToMock = ['query', 'select', 'where', 'auth', 'get', 'put', 'post', 'options', 'json']
  5. methodsToMock.forEach((item) => {
  6. this[item] = () => this
  7. })
  8. this.opts = opts
  9. }
  10. request (done) {
  11. if (typeof done === 'function') {
  12. const responses = {
  13. dropbox: {
  14. hash: '0a9f95a989dd4b1851f0103c31e304ce',
  15. entries: [{ rev: 'f24234cd4' }]
  16. },
  17. drive: {
  18. kind: 'drive#fileList',
  19. etag: '"bcIyJ9A3gXa8oTYmz6nzAjQd-lY/eQc3WbZHkXpcItNyGKDuKXM_bNY"',
  20. items: [{ id: '0B2x-PmqQHSKdT013TE1VVjZ3TWs' }],
  21. size: 300
  22. }
  23. }
  24. const body = responses[this.opts.providerName]
  25. done(null, { body }, body)
  26. }
  27. return this
  28. }
  29. on (evt, cb) {
  30. if (evt === 'response') {
  31. cb(fs.createReadStream('./README.md'))
  32. }
  33. return this
  34. }
  35. }
  36. module.exports = () => {
  37. return (options) => new MockPurest(options)
  38. }